-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_procfile.py
More file actions
70 lines (63 loc) · 2.83 KB
/
test_procfile.py
File metadata and controls
70 lines (63 loc) · 2.83 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
from rest_framework.test import APITestCase
from rest_framework import serializers
from api.serializers import validate_ptype, BuildSerializer, ServiceSerializer
class ProcfileTypeTest(APITestCase):
def assertException(self, method, exception=Exception, *args, **kwargs):
try:
method(*args, **kwargs)
except BaseException as e:
if not isinstance(e, exception):
raise AssertionError(
"Did not throw the expected exception, "
f"actual: {type(e)}, expect: {exception}"
)
else:
raise AssertionError(
f"Did not throw the expected exception, args: {args}, kwargs: {kwargs}")
def test_ptype_error(self):
for ptype in ["w", "we", "-a", "we-new-", "w" * 64]:
self.assertException(
validate_ptype, serializers.ValidationError, ptype)
def test_ptype_ok(self):
self.assertEqual(validate_ptype("web"), "web")
self.assertEqual(validate_ptype("w" * 63), "w" * 63)
self.assertEqual(validate_ptype("web-new-be"), "web-new-be")
def test_dryccfile_ptype(self):
dryccfile_1 = {
"build": {
"docker": {
"web": "Dockerfile",
"task": "Dockerfile.task"
},
},
"deploy": {
"web": {
"args": ["python", "-m", "http.server", "5000"]
},
"task": {
"command": ["sleep"],
"args": ["infinity"]
},
}
}
validate_dryccfile = BuildSerializer().validate_dryccfile
self.assertEqual(validate_dryccfile(dryccfile_1), dryccfile_1)
dryccfile_1["build"]["docker"]["w"] = "Dockerfile.w"
self.assertException(
validate_dryccfile, serializers.ValidationError, dryccfile_1)
del dryccfile_1["build"]["docker"]["w"]
dryccfile_1["deploy"]["w"] = {"args": ["python", "-m", "http.server", "5000"]}
self.assertException(
validate_dryccfile, serializers.ValidationError, dryccfile_1)
del dryccfile_1["deploy"]["w"]
dryccfile_1["deploy"]["w-new-"] = {"args": ["python", "-m", "http.server", "5000"]}
self.assertException(
validate_dryccfile, serializers.ValidationError, dryccfile_1)
def test_staticmethod_ptype(self):
s_validate_ptype = ServiceSerializer().validate_ptype
for ptype in ["w", "we", "-a", "we-new-", "w" * 64]:
self.assertException(
s_validate_ptype, serializers.ValidationError, ptype)
self.assertEqual(s_validate_ptype("web"), "web")
self.assertEqual(s_validate_ptype("w" * 63), "w" * 63)
self.assertEqual(s_validate_ptype("web-new-be"), "web-new-be")