# -*- coding: utf-8 -*- """ (c) 2015-2018 - Copyright Red Hat Inc Authors: Pierre-Yves Chibon """ from __future__ import unicode_literals __requires__ = ['SQLAlchemy >= 0.8'] import pkg_resources import datetime import unittest import shutil import sys import tempfile import os import six import json import pygit2 from mock import patch, MagicMock sys.path.insert(0, os.path.join(os.path.dirname( os.path.abspath(__file__)), '..')) import pagure.lib import tests class PagureFlaskApptests(tests.Modeltests): """ Tests for flask app controller of pagure """ def test_watch_list(self): ''' Test for watch list of a user ''' user = tests.FakeUser(username='pingou') with tests.user_set(self.app.application, user): output = self.app.get('/', follow_redirects=True) output_text = output.get_data(as_text=True) self.assertIn( '
You have no Projects
', output_text) tests.create_projects(self.session) output = self.app.get('/', follow_redirects=True) output_text = output.get_data(as_text=True) self.assertIn( '

My Projects

', output_text) def test_view_users(self): """ Test the view_users endpoint. """ output = self.app.get('/users/?page=abc') self.assertEqual(output.status_code, 200) output_text = output.get_data(as_text=True) self.assertIn( '

\n Users ' '2', output_text) self.assertIn( '\n ' '
pingou', output_text) self.assertIn( '\n ' '
foo', output_text) @patch.dict('pagure.config.config', {'ITEM_PER_PAGE': 2}) def test_view_user_repo_cnt(self): """ Test the repo counts on the view_user endpoint. """ tests.create_projects(self.session) self.gitrepos = tests.create_projects_git( pagure.config.config['GIT_FOLDER']) output = self.app.get('/user/pingou') self.assertEqual(output.status_code, 200) output_text = output.get_data(as_text=True) self.assertIn( """ Projects 
3
""", output_text) self.assertIn( """ Forks 
0
""", output_text) def test_view_user(self): """ Test the view_user endpoint. """ output = self.app.get('/user/pingou?repopage=abc&forkpage=def') self.assertEqual(output.status_code, 200) output_text = output.get_data(as_text=True) self.assertIn( """ Projects 
0
""", output_text) self.assertIn( """ Forks 
0
""", output_text) tests.create_projects(self.session) self.gitrepos = tests.create_projects_git( pagure.config.config['GIT_FOLDER']) output = self.app.get('/user/pingou?repopage=abc&forkpage=def') self.assertEqual(output.status_code, 200) output_text = output.get_data(as_text=True) self.assertIn( """ Projects 
3
""", output_text) self.assertIn( """ Forks 
0
""", output_text) self.assertNotIn( '
page 1 of 2', output_text) @patch.dict('pagure.config.config', {'ENABLE_UI_NEW_PROJECTS': False}) def test_new_project_when_turned_off_in_the_ui(self): """ Test the new_project endpoint when new project creation is not allowed in the UI of this pagure instance. """ user = tests.FakeUser(username='foo') with tests.user_set(self.app.application, user): output = self.app.get('/new/') self.assertEqual(output.status_code, 404) data = { 'description': 'Project #1', 'name': 'project-1', } output = self.app.post('/new/', data=data, follow_redirects=True) self.assertEqual(output.status_code, 404) @patch.dict('pagure.config.config', {'ENABLE_UI_NEW_PROJECTS': False}) def test_new_project_button_when_turned_off_in_the_ui_no_project(self): """ Test the index endpoint when new project creation is not allowed in the UI of this pagure instance. """ user = tests.FakeUser(username='foo') with tests.user_set(self.app.application, user): output = self.app.get('/', follow_redirects=True) self.assertEqual(output.status_code, 200) output_text = output.get_data(as_text=True) self.assertIn( '

My Projects

', output_text) # master template self.assertNotIn( '