Test   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A test_StatisticsDetailView() 0 6 1
A test_UpdateView() 0 2 1
A test_RequestListView() 0 6 1
A test_StatisticsView() 0 3 1
A test_AppRequestDetailView() 0 6 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.core.urlresolvers import resolve, reverse
22
from django.test import TestCase
23
24
from omaha_server.utils import is_private
25
from omaha.views import UpdateView
26
from omaha.views_admin import StatisticsView, StatisticsDetailView, RequestListView, AppRequestDetailView
27
28
29
class URLTestMixin(object):
30
    def assert_url_matches_view(self, view, expected_url, url_name,
31
                                url_args=None, url_kwargs=None, urlconf=None):
32
        """
33
        Assert a view's url is correctly configured
34
        Check the url_name reverses to give a correctly formated expected_url.
35
        Check the expected_url resolves to the expected view.
36
        """
37
38
        reversed_url = reverse(
39
            url_name,
40
            urlconf=urlconf,
41
            args=url_args,
42
            kwargs=url_kwargs,
43
        )
44
        self.assertEqual(reversed_url, expected_url)
45
46
        resolved_view = resolve(expected_url, urlconf=urlconf).func
47
48
        if hasattr(resolved_view, 'cls'):
49
            self.assertEqual(resolved_view.cls, view)
50
        else:
51
            self.assertEqual(resolved_view.__name__, view.__name__)
52
53
54
class Test(URLTestMixin, TestCase):
55
    def test_UpdateView(self):
56
        self.assert_url_matches_view(UpdateView, '/service/update2', 'update')
57
58
    @is_private()
59
    def test_StatisticsView(self):
60
        self.assert_url_matches_view(StatisticsView, '/admin/statistics/', 'omaha_statistics')
61
62
    @is_private()
63
    def test_StatisticsDetailView(self):
64
        self.assert_url_matches_view(StatisticsDetailView,
65
                                     '/admin/statistics/appName/',
66
                                     'omaha_statistics_detail',
67
                                     url_args=('appName',))
68
69
    @is_private()
70
    def test_RequestListView(self):
71
        self.assert_url_matches_view(RequestListView,
72
                                     '/admin/statistics/appName/requests/',
73
                                     'omaha_request_list',
74
                                     url_args=('appName',))
75
76
    @is_private()
77
    def test_AppRequestDetailView(self):
78
        self.assert_url_matches_view(AppRequestDetailView,
79
                                     '/admin/statistics/requests/123/',
80
                                     'omaha_request_detail',
81
                                     url_args=(123,))
82