Completed
Pull Request — master (#260)
by Kirill
01:25
created

SparkleViewTest.test_sparkle_critical()   A

Complexity

Conditions 1

Size

Total Lines 60

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 60
rs 9.5555

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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.test.client import Client
23
from django.core.urlresolvers import reverse
24
from django.core.files.uploadedfile import SimpleUploadedFile
25
26
from xmlunittest import XmlTestMixin
27
from freezegun import freeze_time
28
29
from omaha.tests.utils import temporary_media_root
30
from omaha.factories import ApplicationFactory, ChannelFactory
31
32
from sparkle.tests import fixtures
33
from sparkle.factories import SparkleVersionFactory
34
35
36
37
class SparkleViewTest(TestCase, XmlTestMixin):
38
    def setUp(self):
39
        self.client = Client()
40
41 View Code Duplication
    @freeze_time('2014-10-14 08:28:05')
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
42
    @temporary_media_root(MEDIA_URL='http://cache.pack.google.com/edgedl/chrome/install/782.112/')
43
    def test_sparkle(self):
44
        app = ApplicationFactory.create(id='{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}', name='chrome')
45
        channel = ChannelFactory.create(name='stable')
46
        obj = SparkleVersionFactory.create(
47
            app=app,
48
            channel=channel,
49
            version='782.112',
50
            short_version='13.0.782.112',
51
            file=SimpleUploadedFile('./chrome.dmg', b'_' * 23963192),
52
            file_size=23963192)
53
        obj.save()
54
55
        response = self.client.get(reverse('sparkle_appcast', args=(app.name, channel.name)),
56
                                   HTTP_HOST='example.com')
57
58
        self.assertEqual(response.status_code, 200)
59
60
        self.assertXmlDocument(response.content)
61
        self.assertXmlEquivalentOutputs(response.content,
62
                                        fixtures.response_sparkle)
63
64 View Code Duplication
    @freeze_time('2014-10-14 08:28:05')
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
65
    @temporary_media_root(MEDIA_URL='http://cache.pack.google.com/edgedl/chrome/install/782.112/')
66
    def test_sparkle_with_dsa_signature(self):
67
        app = ApplicationFactory.create(id='{D0AB2EBC-931B-4013-9FEB-C9C4C2225C9C}', name='chrome_dsa')
68
        channel = ChannelFactory.create(name='stable')
69
        obj = SparkleVersionFactory.create(
70
            app=app,
71
            channel=channel,
72
            version='782.112',
73
            short_version='13.0.782.112',
74
            dsa_signature='MCwCFCdoW13VBGJWIfIklKxQVyetgxE7AhQTVuY9uQT0KOV1UEk21epBsGZMPg==',
75
            file=SimpleUploadedFile('./chrome.dmg', b'_' * 23963192),
76
            file_size=23963192)
77
        obj.save()
78
79
        response = self.client.get(reverse('sparkle_appcast', args=(app.name, channel.name)),
80
                                   HTTP_HOST='example.com')
81
82
        self.assertEqual(response.status_code, 200)
83
84
        self.assertXmlDocument(response.content)
85
        self.assertXmlEquivalentOutputs(fixtures.response_sparkle_with_dsa,
86
                                        response.content)
87
88
    @freeze_time('2014-10-14 08:28:05')
89
    @temporary_media_root(MEDIA_URL='http://cache.pack.google.com/edgedl/chrome/install/782.112/')
90
    def test_sparkle_critical(self):
91
        app = ApplicationFactory.create(id='{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}', name='chrome')
92
        channel = ChannelFactory.create(name='stable')
93
        first_version = SparkleVersionFactory.create(
94
            app=app,
95
            channel=channel,
96
            version='782.110',
97
            short_version='13.0.782.110',
98
            file=SimpleUploadedFile('./chrome1.dmg', b'_' * 23963192),
99
            file_size=23963192)
100
        first_version.save()
101
102
        first_crit_version = SparkleVersionFactory.create(
103
            app=app,
104
            channel=channel,
105
            version='782.111',
106
            short_version='13.0.782.111',
107
            is_critical=True,
108
            file=SimpleUploadedFile('./chrome2.dmg', b'_' * 23963192),
109
            file_size=23963192)
110
        first_crit_version.save()
111
112
        last_version = SparkleVersionFactory.create(
113
            app=app,
114
            channel=channel,
115
            version='782.112',
116
            short_version='13.0.782.112',
117
            file=SimpleUploadedFile('./chrome3.dmg', b'_' * 23963192),
118
            file_size=23963192)
119
        last_version.save()
120
121
        last_version = SparkleVersionFactory.create(
122
            app=app,
123
            channel=channel,
124
            version='782.113',
125
            short_version='13.0.782.113',
126
            is_critical=True,
127
            file=SimpleUploadedFile('./chrome4.dmg', b'_' * 23963192),
128
            file_size=23963192)
129
        first_version.save()
130
131
        response = self.client.get("%s?appVersionShort=13.0.782.110" % reverse('sparkle_appcast', args=(app.name, channel.name)),
132
                                   HTTP_HOST='example.com')
133
134
        self.assertEqual(response.status_code, 200)
135
136
        self.assertXmlDocument(response.content)
137
        self.assertXmlEquivalentOutputs(response.content,
138
                                        fixtures.first_crit_response_sparkle)
139
140
        response = self.client.get("%s?appVersionShort=13.0.782.111" % reverse('sparkle_appcast', args=(app.name, channel.name)),
141
                                   HTTP_HOST='example.com')
142
143
        self.assertEqual(response.status_code, 200)
144
145
        self.assertXmlDocument(response.content)
146
        self.assertXmlEquivalentOutputs(response.content,
147
                                        fixtures.second_crit_response_sparkle)
148