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 import override_settings |
23
|
|
|
from mock import Mock |
24
|
|
|
|
25
|
|
|
from omaha_server.utils import show_toolbar, add_extra_to_log_message, get_splunk_url |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
class UtilsTest(TestCase): |
29
|
|
|
def setUp(self): |
30
|
|
|
self.request = Mock() |
31
|
|
|
|
32
|
|
|
def test_show_toolbar_ajax(self): |
33
|
|
|
self.request.is_ajax = lambda: True |
34
|
|
|
self.assertFalse(show_toolbar(self.request)) |
35
|
|
|
|
36
|
|
|
@override_settings(DEBUG=True) |
37
|
|
|
def test_show_toolbar_debug_true(self): |
38
|
|
|
self.request.is_ajax = lambda: False |
39
|
|
|
self.assertTrue(show_toolbar(self.request)) |
40
|
|
|
|
41
|
|
|
@override_settings(DEBUG=False) |
42
|
|
|
def test_show_toolbar_debug_false(self): |
43
|
|
|
self.request.is_ajax = lambda: False |
44
|
|
|
self.assertFalse(show_toolbar(self.request)) |
45
|
|
|
|
46
|
|
|
def test_add_extra_to_log_message(self): |
47
|
|
|
msg = 'test' |
48
|
|
|
extra = dict(a=1, c=3, b=2, d=4) |
49
|
|
|
expected_msg = 'test, a=1 , b=2 , c=3 , d=4' |
50
|
|
|
actual_msg = add_extra_to_log_message(msg, extra) |
51
|
|
|
self.assertEqual(actual_msg, expected_msg) |
52
|
|
|
|
53
|
|
|
@override_settings(FILEBEAT_HOST='splunk.example.com') |
54
|
|
|
def test_add_extra_to_log_message(self): |
55
|
|
|
params = dict(a=1, c=3, b=2, d=4) |
56
|
|
|
actual_msg = get_splunk_url(params) |
57
|
|
|
expected_msg = 'http://splunk.example.com/en-US/app/search/search?q=search a=1 b=2 c=3 d=4' |
58
|
|
|
self.assertEqual(actual_msg, expected_msg) |
59
|
|
|
|