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.test import TestCase |
22
|
|
|
from django.core.files.uploadedfile import SimpleUploadedFile |
23
|
|
|
|
24
|
|
|
from omaha.models import Version |
25
|
|
|
from omaha.factories import VersionFactory |
26
|
|
|
from omaha.tests.utils import temporary_media_root |
27
|
|
|
|
28
|
|
|
|
29
|
|
View Code Duplication |
class VersionManagerTest(TestCase): |
|
|
|
|
30
|
|
|
@temporary_media_root() |
31
|
|
|
def test_filter_by_enabled(self): |
32
|
|
|
version = VersionFactory.create( |
33
|
|
|
version='37.0.2062.125', |
34
|
|
|
file=SimpleUploadedFile('./chrome_installer.exe', False)) |
35
|
|
|
version_disabled = VersionFactory.create( |
36
|
|
|
app=version.app, |
37
|
|
|
platform=version.platform, |
38
|
|
|
channel=version.channel, |
39
|
|
|
is_enabled=False, |
40
|
|
|
version='38.0.2062.125', |
41
|
|
|
file=SimpleUploadedFile('./chrome_installer2.exe', False)) |
42
|
|
|
|
43
|
|
|
self.assertEqual(Version.objects.all().count(), 2) |
44
|
|
|
self.assertEqual(Version.objects.filter_by_enabled().count(), 1) |
45
|
|
|
self.assertIn(version, Version.objects.filter_by_enabled()) |
46
|
|
|
self.assertNotIn(version_disabled, Version.objects.filter_by_enabled()) |
47
|
|
|
|
48
|
|
|
def test_get_size(self): |
49
|
|
|
file_size = 42 |
50
|
|
|
VersionFactory.create_batch(10, file_size=file_size) |
51
|
|
|
size = Version.objects.get_size() |
52
|
|
|
self.assertEqual(size, file_size*10) |
53
|
|
|
|