-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_event.py
More file actions
74 lines (60 loc) · 2.45 KB
/
test_event.py
File metadata and controls
74 lines (60 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# -*- coding: utf-8 -*-
"""
Unit tests for the Drycc api app.
Run the tests with "./manage.py test api"
"""
from django.contrib.auth import get_user_model
from django.core.cache import cache
from api.models.app import App
from api.tests import adapter, DryccTransactionTestCase
import requests_mock
User = get_user_model()
@requests_mock.Mocker(real_http=True, adapter=adapter)
class EventTest(DryccTransactionTestCase):
"""Tests setting and updating config values"""
fixtures = ['tests.json']
def setUp(self):
self.user = User.objects.get(username='autotest')
self.token = self.get_or_create_token(self.user)
self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.token)
url = '/v2/apps'
response = self.client.post(url, HTTP_AUTHORIZATION='token {}'.format(self.token))
self.assertEqual(response.status_code, 201, response.data)
self.app = App.objects.all()[0]
def tearDown(self):
# make sure every test has a clean slate for k8s mocking
cache.clear()
def build_deploy(self, app_id):
# post a new build with procfile
url = "/v2/apps/{app_id}/build".format(app_id=app_id)
body = {
'image': 'autotest/example',
'sha': 'a'*40,
'stack': 'heroku-18',
'procfile': {
'web': 'node server.js',
'worker': 'node worker.js'
}
}
response = self.client.post(url, body)
self.assertEqual(response.status_code, 201, response.data)
def test_events(self, mock_requests):
"""
Test that config is auto-created for a new app and that
config can be updated using a PATCH
"""
app_id = self.create_app()
self.build_deploy(app_id)
# list events of pod
url = f"/v2/apps/{app_id}/pods"
response = self.client.get(url)
self.assertEqual(response.status_code, 200, response.data)
pod_name = response.data['results'][0]["name"]
response = self.client.get(f"/v2/apps/{app_id}/pods/{pod_name}/describe/")
url = f"/v2/apps/{app_id}/events"
response = self.client.get(url, {"pod_name": pod_name})
self.assertEqual(response.status_code, 200, response.data)
# list events of deployment
url = f"/v2/apps/{app_id}/events"
response = self.client.get(url, {"ptype": f"{app_id}-web"})
self.assertEqual(response.status_code, 200, response.data)