# -*- coding: utf-8 -*- # Copyright (C) 2010-2017 RhodeCode GmbH # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License, version 3 # (only), as published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # # This program is dual-licensed. If you wish to learn more about the # RhodeCode Enterprise Edition, including its added features, Support services, # and proprietary license terms, please see https://rhodecode.com/licenses/ import pytest from pylons import tmpl_context as c import rhodecode from rhodecode.model.db import Repository, User from rhodecode.model.meta import Session from rhodecode.model.repo import RepoModel from rhodecode.model.repo_group import RepoGroupModel from rhodecode.model.settings import SettingsModel from rhodecode.tests import TestController from rhodecode.tests.fixture import Fixture fixture = Fixture() def route_path(name, **kwargs): return { 'home': '/', 'repo_group_home': '/{repo_group_name}' }[name].format(**kwargs) class TestHomeController(TestController): def test_index(self): self.log_user() response = self.app.get(route_path('home')) # if global permission is set response.mustcontain('Add Repository') # search for objects inside the JavaScript JSON for repo in Repository.getAll(): response.mustcontain('"name_raw": "%s"' % repo.repo_name) def test_index_contains_statics_with_ver(self): self.log_user() response = self.app.get(route_path('home')) rhodecode_version_hash = c.rhodecode_version_hash response.mustcontain('style.css?ver={0}'.format(rhodecode_version_hash)) response.mustcontain('rhodecode-components.js?ver={0}'.format(rhodecode_version_hash)) def test_index_contains_backend_specific_details(self, backend): self.log_user() response = self.app.get(route_path('home')) tip = backend.repo.get_commit().raw_id # html in javascript variable: response.mustcontain(r'' user.lastname = ( '') Session().add(user) Session().commit() user_util.create_repo(owner=username) response = self.app.get(route_path('home')) response.mustcontain( '<img src="/image1" onload="' 'alert('Hello, World!');">') response.mustcontain( '<img src="/image2" onload="' 'alert('Hello, World!');">') @pytest.mark.parametrize("name, state", [ ('Disabled', False), ('Enabled', True), ]) def test_index_show_version(self, autologin_user, name, state): version_string = 'RhodeCode Enterprise %s' % rhodecode.__version__ sett = SettingsModel().create_or_update_setting( 'show_version', state, 'bool') Session().add(sett) Session().commit() SettingsModel().invalidate_settings_cache() response = self.app.get(route_path('home')) if state is True: response.mustcontain(version_string) if state is False: response.mustcontain(no=[version_string])