1
|
|
|
import json |
2
|
|
|
|
3
|
|
|
from rest_framework.test import APITestCase |
4
|
|
|
from django.db import connections |
5
|
|
|
|
6
|
|
|
from omaha.factories import VersionFactory, ApplicationFactory, ChannelFactory, PlatformFactory |
7
|
|
|
from sparkle.factories import SparkleVersionFactory |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
class DownloadsTest(APITestCase): |
11
|
|
|
maxDiff = None |
12
|
|
|
|
13
|
|
|
def setUp(self): |
14
|
|
|
self.app = ApplicationFactory(name='TestApp') |
15
|
|
|
self.platform = PlatformFactory(name='win') |
16
|
|
|
self.channel = ChannelFactory(name='alpha') |
17
|
|
|
self.stable_channel = ChannelFactory(name='stable') |
18
|
|
|
self.win_v1 = VersionFactory(version='10.0.0.0', app=self.app, channel=self.channel, platform=self.platform) |
19
|
|
|
self.win_v2 = VersionFactory(version='42.0.1.0', app=self.app, channel=self.channel, platform=self.platform) |
20
|
|
|
self.win_stable_v = VersionFactory(version='23.0.0.0', app=self.app, |
21
|
|
|
channel=self.stable_channel, platform=self.platform) |
22
|
|
|
self.win_disabled_v = VersionFactory(version='55.0.2.0', app=self.app, channel=self.channel, |
23
|
|
|
platform=self.platform, is_enabled=False) |
24
|
|
|
|
25
|
|
|
self.mac_v1 = SparkleVersionFactory(short_version='10.0.0.0', version='0.0', |
26
|
|
|
app=self.app, channel=self.channel) |
27
|
|
|
self.mac_v2 = SparkleVersionFactory(short_version='42.0.1.0', version='1.0', |
28
|
|
|
app=self.app, channel=self.channel) |
29
|
|
|
self.mac_stable_v = SparkleVersionFactory(short_version='23.0.0.0', version='0.0', |
30
|
|
|
app=self.app, channel=self.stable_channel) |
31
|
|
|
self.mac_disabled_v = SparkleVersionFactory(short_version='55.0.2.0', version='2.0', |
32
|
|
|
app=self.app, channel=self.channel, is_enabled=False) |
33
|
|
|
self.exp_res = { |
34
|
|
|
self.app.name: { |
35
|
|
|
"win": { |
36
|
|
|
self.channel.name: { |
37
|
|
|
"url": self.win_v2.file_absolute_url, |
38
|
|
|
"version": self.win_v2.version |
39
|
|
|
}, |
40
|
|
|
self.stable_channel.name: { |
41
|
|
|
"url": self.win_stable_v.file_absolute_url, |
42
|
|
|
"version": self.win_stable_v.version |
43
|
|
|
} |
44
|
|
|
}, |
45
|
|
|
"mac": { |
46
|
|
|
self.channel.name: { |
47
|
|
|
"url": self.mac_v2.file_absolute_url, |
48
|
|
|
"version": self.mac_v2.short_version |
49
|
|
|
}, |
50
|
|
|
self.stable_channel.name: { |
51
|
|
|
"url": self.mac_stable_v.file_absolute_url, |
52
|
|
|
"version": self.mac_stable_v.short_version |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
def test(self): |
59
|
|
|
if connections['default'].settings_dict['ENGINE'] != 'django.db.backends.postgresql_psycopg2': |
60
|
|
|
self.skipTest('Database should be postgreSQL') |
61
|
|
|
response = self.client.get('/api/downloads', format='json') |
62
|
|
|
|
63
|
|
|
self.assertEqual(json.loads(json.dumps(response.data)), self.exp_res) |
64
|
|
|
|
65
|
|
|
def test_latest_mac_version(self): |
66
|
|
|
if connections['default'].settings_dict['ENGINE'] != 'django.db.backends.postgresql_psycopg2': |
67
|
|
|
self.skipTest('Database should be postgreSQL') |
68
|
|
|
response = self.client.get('/downloads/latest/sparkle/TestApp/alpha/') |
69
|
|
|
|
70
|
|
|
self.assertRedirects(response, self.mac_v2.file.url, fetch_redirect_response=False) |
71
|
|
|
|
72
|
|
|
def test_latest_win_version(self): |
73
|
|
|
if connections['default'].settings_dict['ENGINE'] != 'django.db.backends.postgresql_psycopg2': |
74
|
|
|
self.skipTest('Database should be postgreSQL') |
75
|
|
|
response = self.client.get('/downloads/latest/omaha/TestApp/win/alpha/') |
76
|
|
|
|
77
|
|
|
self.assertRedirects(response, self.win_v2.file.url, fetch_redirect_response=False) |
78
|
|
|
|