-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathupdater.py
98 lines (79 loc) · 3.85 KB
/
updater.py
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from api.utils import variant_check
from api.views import V1UpdaterLOS
from django.contrib.auth.models import AnonymousUser
from rest_framework.test import APIRequestFactory, APITestCase
from core.tests.base import mock_setup
class UpdaterTestCase(APITestCase):
def setUp(self):
mock_setup()
self.factory = APIRequestFactory()
V1UpdaterLOS.throttle_classes = ()
def test_variant_check(self):
response = variant_check("unknown")
self.assertEqual(response.status_code, 400)
self.assertIsNone(variant_check("gapps"))
self.assertIsNone(variant_check("vanilla"))
self.assertIsNone(variant_check("foss"))
self.assertIsNone(variant_check("goapps"))
def test_v1_updater_los_bullhead_gapps(self):
request = self.factory.get("/api/v1/updater/los/", secure=True)
request.user = AnonymousUser()
response = V1UpdaterLOS.as_view()(request, "bullhead", "gapps")
self.assertEqual(response.status_code, 200)
self.assertIn("response", response.data)
self.assertIn("datetime", response.data["response"][0])
self.assertIn("filename", response.data["response"][0])
self.assertIn("id", response.data["response"][0])
self.assertIn("size", response.data["response"][0])
self.assertIn("version", response.data["response"][0])
self.assertIn("variant", response.data["response"][0])
self.assertIn("url", response.data["response"][0])
self.assertEqual(1591574400, response.data["response"][0]["datetime"])
self.assertEqual(
"Bliss-v14-bullhead-OFFICIAL-gapps-20200608.zip",
response.data["response"][0]["filename"],
)
self.assertEqual(
"b9566ebc192a4c27c72df19eae8a6eed6ea063226792e680fa0b2ede284e19f2",
response.data["response"][0]["id"],
)
self.assertEqual(857483855, response.data["response"][0]["size"])
self.assertEqual("v14", response.data["response"][0]["version"])
self.assertEqual("gapps", response.data["response"][0]["variant"])
self.assertEqual(
"https://testserver/download_check/bullhead/"
"Bliss-v14-bullhead-OFFICIAL-gapps-20200608/",
response.data["response"][0]["url"],
)
def test_v1_updater_los_bullhead_vanilla(self):
request = self.factory.get("/api/v1/updater/los/")
request.user = AnonymousUser
response = V1UpdaterLOS.as_view()(request, "bullhead", "vanilla")
self.assertEqual(response.status_code, 404)
def test_v1_updater_los_bullhead_foss(self):
request = self.factory.get("/api/v1/updater/los/")
request.user = AnonymousUser
response = V1UpdaterLOS.as_view()(request, "bullhead", "foss")
self.assertEqual(response.status_code, 404)
def test_v1_updater_los_bullhead_goapps(self):
request = self.factory.get("/api/v1/updater/los/")
request.user = AnonymousUser
response = V1UpdaterLOS.as_view()(request, "bullhead", "goapps")
self.assertEqual(response.status_code, 404)
def test_v1_updater_los_nonexistent_device(self):
request = self.factory.get("/api/v1/updater/los/")
request.user = AnonymousUser
response = V1UpdaterLOS.as_view()(request, "nonexistent", "gapps")
self.assertEqual(response.status_code, 404)
self.assertEqual(
response.data["message"], "The specified device does not exist!"
)
def test_v1_updater_los_nonexistent_variant(self):
request = self.factory.get("/api/v1/updater/los/")
request.user = AnonymousUser
response = V1UpdaterLOS.as_view()(request, "bullhead", "milkshake")
self.assertEqual(response.status_code, 400)
self.assertEqual(
response.data["message"],
"Wrong parameter. Try with the correct parameters.",
)