Completed
Push — master ( e271b6...fc740f )
by Egor
01:21
created

SparkleViewTest.test_sparkle()   A

Complexity

Conditions 1

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 22
rs 9.2
cc 1
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
    @freeze_time('2014-10-14 08:28:05')
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
    @freeze_time('2014-10-14 08:28:05')
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