[ee46bc]: / Allura / allura / tests / functional / test_nav.py  Maximize  Restore  History

Download this file

128 lines (113 with data), 5.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import mock
import json
from tg import config
from tg import app_globals as g
from allura.tests import TestController
from allura.lib import helpers as h
class TestNavigation(TestController):
"""
Test div-logo and nav-left:
- Test of global_nav links.
- Test of logo.
"""
def setup_method(self, method):
super().setup_method(method)
self.logo_pattern = ('div', {'class': 'nav-logo'})
self.global_nav_pattern = ('nav', {'class': 'nav-left'})
self.nav_data = {
"title": "Link Test", "url": "http://example.com"}
self.logo_data = {
"link": "/", "path": "test_image.png"}
self.width = 'width: %spx;'
self.height = 'height: %spx;'
g._Globals__shared_state.pop('global_nav', None)
g._Globals__shared_state.pop('nav_logo', None)
def _set_config(self):
return {
"global_nav": json.dumps([self.nav_data]),
"logo.link": self.logo_data['link'],
"logo.path": self.logo_data['path'],
"logo.width": self.logo_data.get('width', ''),
"logo.height": self.logo_data.get('height', '')
}
def test_global_nav_links_present(self):
with h.push_config(config, **self._set_config()):
response = self.app.get('/').follow()
nav_left = response.html.find(*self.global_nav_pattern)
assert len(nav_left.findAll('a')) == 1
assert nav_left.a.get('href') == self.nav_data['url']
assert nav_left.a.text == self.nav_data['title']
@mock.patch.object(g, 'global_nav', return_value=[])
def test_global_nav_links_absent(self, global_nav):
with h.push_config(config, **self._set_config()):
response = self.app.get('/').follow()
nav_left = response.html.find(*self.global_nav_pattern)
assert len(nav_left.findAll('a')) == 0
def test_logo_absent_if_not_image_path(self):
with h.push_config(config, **self._set_config()):
response = self.app.get('/').follow()
nav_logo = response.html.find(*self.logo_pattern)
assert len(nav_logo.findAll('a')) == 0
def test_logo_present(self):
self.logo_data = {
"link": "/", "path": "user.png"}
with h.push_config(config, **self._set_config()):
response = self.app.get('/').follow()
nav_logo = response.html.find(*self.logo_pattern)
assert len(nav_logo.findAll('a')) == 1
assert self.logo_data['path'] in nav_logo.a.img.get('src')
def test_logo_no_redirect_url_set_default(self):
self.logo_data = {
"link": "", "path": "user.png"}
with h.push_config(config, **self._set_config()):
response = self.app.get('/').follow()
nav_logo = response.html.find(*self.logo_pattern)
assert len(nav_logo.findAll('a')) == 1
assert nav_logo.a.get('href') == '/'
def test_logo_image_width_and_height(self):
self.logo_data = {
"link": "", "path": "user.png",
"width": 20, "height": 20}
with h.push_config(config, **self._set_config()):
response = self.app.get('/').follow()
nav_logo = response.html.find(*self.logo_pattern)
width = self.width % self.logo_data["width"]
height = self.height % self.logo_data["height"]
assert nav_logo.find(
'img', style=f'{width} {height}') is not None
def test_missing_logo_width(self):
self.logo_data = {
"link": "", "path": "user.png",
"height": 20}
with h.push_config(config, **self._set_config()):
response = self.app.get('/').follow()
nav_logo = response.html.find(*self.logo_pattern)
height = self.height % self.logo_data["height"]
assert nav_logo.find(
'img', style=' %s' % height) is not None
def test_missing_logo_height(self):
self.logo_data = {
"link": "/", "path": "user.png",
"width": 20}
with h.push_config(config, **self._set_config()):
response = self.app.get('/').follow()
nav_logo = response.html.find(*self.logo_pattern)
width = self.width % self.logo_data["width"]
assert nav_logo.find(
'img', style='%s ' % width) is not None