Completed
Push — master ( 646ecf...07a97f )
by
unknown
48s
created

VersionTest.setUp()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
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 import OverloadTestStorageMixin
35
from omaha.tests.test_api import BaseTest
36
from omaha_server.utils import is_private
37
38
39
class VersionTest(OverloadTestStorageMixin, BaseTest, APITestCase):
40
    url = 'sparkleversion-list'
41
    url_detail = 'sparkleversion-detail'
42
    factory = SparkleVersionFactory
43
    serializer = SparkleVersionSerializer
44
    model = SparkleVersion
45
46
    @temporary_media_root(MEDIA_URL='http://cache.pack.google.com/edgedl/chrome/install/782.112/')
47
    def setUp(self):
48
        super(VersionTest, self).setUp()
49
50
    @is_private()
51
    @temporary_media_root(MEDIA_URL='http://cache.pack.google.com/edgedl/chrome/install/782.112/')
52
    def test_detail(self):
53
        super(VersionTest, self).test_detail()
54 View Code Duplication
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
55
    @is_private()
56
    @temporary_media_root(MEDIA_URL='http://cache.pack.google.com/edgedl/chrome/install/782.112/')
57
    def test_list(self):
58
        super(VersionTest, self).test_list()
59
60
    @is_private()
61
    @temporary_media_root(MEDIA_URL='http://cache.pack.google.com/edgedl/chrome/install/782.112/')
62
    def test_create(self):
63
        data = dict(
64
            app=ApplicationFactory.create().id,
65
            channel=ChannelFactory.create().id,
66
            version='3.4',
67
            file=SimpleUploadedFile("chrome.exe", b'content'),
68
        )
69
        response = self.client.post(reverse(self.url), data)
70
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
71
        version = SparkleVersion.objects.get(id=response.data['id'])
72
        self.assertEqual(response.data, self.serializer(version).data)
73
        self.assertEqual(version.file_size, len(b'content'))
74
        self.assertTrue(version.is_enabled)
75
76
    @is_private()
77
    @temporary_media_root(MEDIA_URL='http://cache.pack.google.com/edgedl/chrome/install/782.112/')
78
    def test_update(self):
79
        data = dict(
80
            app=ApplicationFactory.create().id,
81
            channel=ChannelFactory.create().id,
82
            version='3.4',
83
            file=SimpleUploadedFile("chrome.exe", b'content'),
84
        )
85
        response = self.client.post(reverse(self.url), data)
86
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
87
        obj_id = response.data['id']
88
        version = SparkleVersion.objects.get(id=obj_id)
89
        self.assertEqual(version.version, '3.4')
90
        url = reverse(self.url_detail, kwargs=dict(pk=obj_id))
91
        response = self.client.patch(url, dict(version='3.5'))
92
        self.assertEqual(response.status_code, status.HTTP_200_OK)
93
        version = SparkleVersion.objects.get(id=obj_id)
94
        self.assertEqual(version.version, '3.5')
95