1
|
|
|
# coding: utf8 |
2
|
|
|
|
3
|
|
|
""" |
4
|
|
|
This software is licensed under the Apache 2 license, quoted below. |
5
|
|
|
|
6
|
|
|
Copyright 2014 Crystalnix Limited |
7
|
|
|
|
8
|
|
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not |
9
|
|
|
use this file except in compliance with the License. You may obtain a copy of |
10
|
|
|
the License at |
11
|
|
|
|
12
|
|
|
http://www.apache.org/licenses/LICENSE-2.0 |
13
|
|
|
|
14
|
|
|
Unless required by applicable law or agreed to in writing, software |
15
|
|
|
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
16
|
|
|
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
17
|
|
|
License for the specific language governing permissions and limitations under |
18
|
|
|
the License. |
19
|
|
|
""" |
20
|
|
|
|
21
|
|
|
from django import test |
22
|
|
|
from django.core.files.uploadedfile import SimpleUploadedFile |
23
|
|
|
|
24
|
|
|
from mock import patch |
25
|
|
|
|
26
|
|
|
from omaha.models import Application, Channel, Platform, Version, Action, EVENT_DICT_CHOICES |
27
|
|
|
from omaha.models import version_upload_to |
28
|
|
|
from omaha.factories import ApplicationFactory, ChannelFactory, PlatformFactory, VersionFactory |
29
|
|
|
from omaha.tests.utils import temporary_media_root |
30
|
|
|
from omaha.tests import OverloadTestStorageMixin |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
class ApplicationModelTest(test.SimpleTestCase): |
34
|
|
|
allow_database_queries = True |
35
|
|
|
|
36
|
|
|
def test_factory(self): |
37
|
|
|
app = ApplicationFactory.create() |
38
|
|
|
self.assertTrue(Application.objects.get(id=app.id)) |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
class ChannelModelTest(test.TestCase): |
42
|
|
|
def test_factory(self): |
43
|
|
|
channel = ChannelFactory.create() |
44
|
|
|
self.assertTrue(Channel.objects.get(id=channel.id)) |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
class PlatformModelTest(test.TestCase): |
48
|
|
|
def test_factory(self): |
49
|
|
|
platform = PlatformFactory.create() |
50
|
|
|
self.assertTrue(Platform.objects.get(id=platform.id)) |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
class VersionModelTest(OverloadTestStorageMixin, test.TestCase): |
54
|
|
|
model = Version |
55
|
|
|
|
56
|
|
|
@temporary_media_root() |
57
|
|
|
def test_version_upload_to(self): |
58
|
|
|
version = VersionFactory.create(file=SimpleUploadedFile('./chrome_installer.exe', False)) |
59
|
|
|
self.assertEqual(version_upload_to(version, 'chrome_installer.exe'), |
60
|
|
|
'build/{}/{}/{}/{}/chrome_installer.exe'.format( |
61
|
|
|
version.app.name, |
62
|
|
|
version.channel.name, |
63
|
|
|
version.platform.name, |
64
|
|
|
version.version, |
65
|
|
|
version.file.name, |
66
|
|
|
)) |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
@temporary_media_root() |
70
|
|
|
def test_factory(self): |
71
|
|
|
version = VersionFactory.create(file=SimpleUploadedFile('./chrome_installer.exe', False)) |
72
|
|
|
self.assertTrue(Version.objects.get(id=version.id)) |
73
|
|
|
|
74
|
|
|
@temporary_media_root(MEDIA_URL='http://cache.pack.google.com/edgedl/chrome/install/782.112/') |
75
|
|
|
@patch('omaha.models.version_upload_to', lambda o, f: f) |
76
|
|
|
def test_property(self): |
77
|
|
|
version = VersionFactory.create(file=SimpleUploadedFile('./chrome_installer.exe', '')) |
78
|
|
|
self.assertEqual(version.file_absolute_url, |
79
|
|
|
'http://cache.pack.google.com/edgedl/chrome/install/782.112/chrome_installer.exe') |
80
|
|
|
self.assertEqual(version.file_package_name, 'chrome_installer.exe') |
81
|
|
|
self.assertEqual(version.file_url, |
82
|
|
|
u'http://cache.pack.google.com/edgedl/chrome/install/782.112/') |
83
|
|
|
|
84
|
|
|
@temporary_media_root() |
85
|
|
|
@test.override_settings(OMAHA_URL_PREFIX='http://example.com') |
86
|
|
|
def test_property_default_storage(self): |
87
|
|
|
version = VersionFactory.create(file=SimpleUploadedFile('./chrome_installer.exe', '')) |
88
|
|
|
_url = 'http://example.com/static/media/build/%s/%s/%s/37.0.2062.124/chrome_installer.exe' \ |
89
|
|
|
% (version.app.name, version.channel.name, version.platform.name) |
90
|
|
|
self.assertEqual(version.file_absolute_url, _url) |
91
|
|
|
self.assertEqual(version.file_package_name, 'chrome_installer.exe') |
92
|
|
|
_url = u'http://example.com/static/media/build/%s/%s/%s/37.0.2062.124/' \ |
93
|
|
|
% (version.app.name, version.channel.name, version.platform.name) |
94
|
|
|
self.assertEqual(version.file_url, _url) |
95
|
|
|
|
96
|
|
|
@temporary_media_root(MEDIA_URL='http://cache.pack.google.com/edgedl/chrome/install/782.112/') |
97
|
|
|
@patch('omaha.models.version_upload_to', lambda o, f: f) |
98
|
|
|
def test_property_s3_meta_data(self): |
99
|
|
|
version = VersionFactory.create(file=SimpleUploadedFile('./chrome_installer.exe', '')) |
100
|
|
|
self.assertEqual(version.file_package_name, 'chrome_installer.exe') |
101
|
|
|
self.assertEqual(version.file_url, |
102
|
|
|
'http://cache.pack.google.com/edgedl/chrome/install/782.112/') |
103
|
|
|
self.assertEqual(version.size, 123) |
104
|
|
|
|
105
|
|
|
@temporary_media_root() |
106
|
|
|
def test_pre_save_callback(self): |
107
|
|
|
version = VersionFactory.create(file=SimpleUploadedFile('./chrome_installer.exe', b'')) |
108
|
|
|
self.assertEqual(version.file.size, 0) |
109
|
|
|
self.assertEqual(version.file_hash, '2jmj7l5rSw0yVb/vlWAYkK/YBwk=') |
110
|
|
|
|
111
|
|
|
|
112
|
|
|
class ActionModelTest(test.TestCase): |
113
|
|
|
@temporary_media_root() |
114
|
|
|
def test_get_attributes(self): |
115
|
|
|
ver = VersionFactory.create(file=SimpleUploadedFile('./chrome_installer.exe', False)) |
116
|
|
|
action = Action( |
117
|
|
|
version=ver, |
118
|
|
|
arguments='--do-not-launch-chrome', |
119
|
|
|
event=EVENT_DICT_CHOICES['install'], |
120
|
|
|
run='chrome_installer.exe' |
121
|
|
|
) |
122
|
|
|
|
123
|
|
|
self.assertDictEqual( |
124
|
|
|
action.get_attributes(), |
125
|
|
|
dict( |
126
|
|
|
arguments='--do-not-launch-chrome', |
127
|
|
|
run='chrome_installer.exe', |
128
|
|
|
)) |
129
|
|
|
|
130
|
|
|
action = Action( |
131
|
|
|
version=ver, |
132
|
|
|
terminateallbrowsers=True, |
133
|
|
|
event=EVENT_DICT_CHOICES['postinstall'], |
134
|
|
|
other=dict( |
135
|
|
|
version='13.0.782.112', |
136
|
|
|
onsuccess='exitsilentlyonlaunchcmd') |
137
|
|
|
) |
138
|
|
|
|
139
|
|
|
self.assertDictEqual( |
140
|
|
|
action.get_attributes(), |
141
|
|
|
dict( |
142
|
|
|
terminateallbrowsers='true', |
143
|
|
|
version='13.0.782.112', |
144
|
|
|
onsuccess='exitsilentlyonlaunchcmd', |
145
|
|
|
) |
146
|
|
|
) |
147
|
|
|
|