|
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.core.urlresolvers import reverse |
|
22
|
|
|
from django.core.files.uploadedfile import SimpleUploadedFile |
|
23
|
|
|
|
|
24
|
|
|
from rest_framework import status |
|
25
|
|
|
from rest_framework.test import APITestCase |
|
26
|
|
|
|
|
27
|
|
|
from omaha.factories import ApplicationFactory, ChannelFactory |
|
28
|
|
|
|
|
29
|
|
|
from sparkle.serializers import SparkleVersionSerializer |
|
30
|
|
|
from sparkle.factories import SparkleVersionFactory |
|
31
|
|
|
from sparkle.models import SparkleVersion |
|
32
|
|
|
|
|
33
|
|
|
from omaha.tests.utils import temporary_media_root |
|
34
|
|
|
from omaha.tests.test_api import BaseTest |
|
35
|
|
|
from omaha_server.utils import is_private |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
class VersionTest(BaseTest, APITestCase): |
|
39
|
|
|
url = 'sparkleversion-list' |
|
40
|
|
|
url_detail = 'sparkleversion-detail' |
|
41
|
|
|
factory = SparkleVersionFactory |
|
42
|
|
|
serializer = SparkleVersionSerializer |
|
43
|
|
|
|
|
44
|
|
|
@is_private() |
|
45
|
|
|
@temporary_media_root(MEDIA_URL='http://cache.pack.google.com/edgedl/chrome/install/782.112/') |
|
46
|
|
|
def test_detail(self): |
|
47
|
|
|
super(VersionTest, self).test_detail() |
|
48
|
|
|
|
|
49
|
|
|
@is_private() |
|
50
|
|
|
@temporary_media_root(MEDIA_URL='http://cache.pack.google.com/edgedl/chrome/install/782.112/') |
|
51
|
|
|
def test_list(self): |
|
52
|
|
|
super(VersionTest, self).test_list() |
|
53
|
|
|
|
|
54
|
|
View Code Duplication |
@is_private() |
|
|
|
|
|
|
55
|
|
|
@temporary_media_root(MEDIA_URL='http://cache.pack.google.com/edgedl/chrome/install/782.112/') |
|
56
|
|
|
def test_create(self): |
|
57
|
|
|
data = dict( |
|
58
|
|
|
app=ApplicationFactory.create().id, |
|
59
|
|
|
channel=ChannelFactory.create().id, |
|
60
|
|
|
version='1.2.3.4', |
|
61
|
|
|
file=SimpleUploadedFile("chrome.exe", b'content'), |
|
62
|
|
|
) |
|
63
|
|
|
response = self.client.post(reverse(self.url), data) |
|
64
|
|
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED) |
|
65
|
|
|
version = SparkleVersion.objects.get(id=response.data['id']) |
|
66
|
|
|
self.assertEqual(response.data, self.serializer(version).data) |
|
67
|
|
|
self.assertEqual(version.file_size, len(b'content')) |
|
68
|
|
|
self.assertTrue(version.is_enabled) |
|
69
|
|
|
|
|
70
|
|
|
@is_private() |
|
71
|
|
|
@temporary_media_root(MEDIA_URL='http://cache.pack.google.com/edgedl/chrome/install/782.112/') |
|
72
|
|
|
def test_update(self): |
|
73
|
|
|
data = dict( |
|
74
|
|
|
app=ApplicationFactory.create().id, |
|
75
|
|
|
channel=ChannelFactory.create().id, |
|
76
|
|
|
version='1.2.3.4', |
|
77
|
|
|
file=SimpleUploadedFile("chrome.exe", b'content'), |
|
78
|
|
|
) |
|
79
|
|
|
response = self.client.post(reverse(self.url), data) |
|
80
|
|
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED) |
|
81
|
|
|
obj_id = response.data['id'] |
|
82
|
|
|
version = SparkleVersion.objects.get(id=obj_id) |
|
83
|
|
|
self.assertEqual(version.version, '1.2.3.4') |
|
84
|
|
|
url = reverse(self.url_detail, kwargs=dict(pk=obj_id)) |
|
85
|
|
|
response = self.client.patch(url, dict(version='1.2.3.5')) |
|
86
|
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK) |
|
87
|
|
|
version = SparkleVersion.objects.get(id=obj_id) |
|
88
|
|
|
self.assertEqual(version.version, '1.2.3.5') |
|
89
|
|
|
|