|
Pierre-Yves Chibon |
5cdb69 |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
5cdb69 |
|
|
Pierre-Yves Chibon |
5cdb69 |
"""
|
|
Pierre-Yves Chibon |
5cdb69 |
(c) 2017 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
5cdb69 |
|
|
Pierre-Yves Chibon |
5cdb69 |
Authors:
|
|
Pierre-Yves Chibon |
5cdb69 |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
5cdb69 |
|
|
Pierre-Yves Chibon |
5cdb69 |
"""
|
|
Pierre-Yves Chibon |
5cdb69 |
|
|
Pierre-Yves Chibon |
67d1cc |
from __future__ import unicode_literals, absolute_import
|
|
Aurélien Bompard |
dcf6f6 |
|
|
Pierre-Yves Chibon |
5cdb69 |
import datetime
|
|
Pierre-Yves Chibon |
5cdb69 |
import unittest
|
|
Pierre-Yves Chibon |
5cdb69 |
import shutil
|
|
Pierre-Yves Chibon |
5cdb69 |
import sys
|
|
Pierre-Yves Chibon |
5cdb69 |
import os
|
|
Pierre-Yves Chibon |
5cdb69 |
|
|
Pierre-Yves Chibon |
5cdb69 |
import six
|
|
Pierre-Yves Chibon |
5cdb69 |
import json
|
|
Pierre-Yves Chibon |
5cdb69 |
import pygit2
|
|
Pierre-Yves Chibon |
5cdb69 |
from mock import patch, MagicMock
|
|
Pierre-Yves Chibon |
5cdb69 |
|
|
Pierre-Yves Chibon |
5cdb69 |
sys.path.insert(0, os.path.join(os.path.dirname(
|
|
Pierre-Yves Chibon |
5cdb69 |
os.path.abspath(__file__)), '..'))
|
|
Pierre-Yves Chibon |
5cdb69 |
|
|
Pierre-Yves Chibon |
930073 |
import pagure.lib.query
|
|
Pierre-Yves Chibon |
5cdb69 |
import tests
|
|
Pierre-Yves Chibon |
5cdb69 |
|
|
Pierre-Yves Chibon |
5cdb69 |
|
|
Pierre-Yves Chibon |
5cdb69 |
class PagureFlaskAppIndextests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
5cdb69 |
""" Tests for the index page of flask app controller of pagure """
|
|
Pierre-Yves Chibon |
5cdb69 |
|
|
Pierre-Yves Chibon |
5cdb69 |
def test_index_logged_out(self):
|
|
Pierre-Yves Chibon |
5cdb69 |
""" Test the index endpoint when logged out. """
|
|
Pierre-Yves Chibon |
5cdb69 |
|
|
Pierre-Yves Chibon |
5cdb69 |
output = self.app.get('/')
|
|
Pierre-Yves Chibon |
5cdb69 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Aurélien Bompard |
626417 |
self.assertIn('<title>Home - Pagure</title>', output_text)
|
|
Pierre-Yves Chibon |
5cdb69 |
self.assertIn(
|
|
Pierre-Yves Chibon |
b1ec6e |
'All Projects '
|
|
Pierre-Yves Chibon |
b1ec6e |
'0',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
5cdb69 |
|
|
Pierre-Yves Chibon |
5cdb69 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
5cdb69 |
|
|
Pierre-Yves Chibon |
5cdb69 |
output = self.app.get('/?page=abc')
|
|
Pierre-Yves Chibon |
5cdb69 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
5cdb69 |
self.assertIn(
|
|
Pierre-Yves Chibon |
b1ec6e |
'All Projects '
|
|
Pierre-Yves Chibon |
b1ec6e |
'3',
|
|
Aurélien Bompard |
626417 |
output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
5cdb69 |
|
|
Pierre-Yves Chibon |
5cdb69 |
def test_index_logged_in(self):
|
|
Ryan Lerch |
336cd6 |
"""
|
|
Ryan Lerch |
336cd6 |
Test the index endpoint when logged in.
|
|
Ryan Lerch |
336cd6 |
It should redirect to the userdash.
|
|
Ryan Lerch |
336cd6 |
"""
|
|
Pierre-Yves Chibon |
5cdb69 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
5cdb69 |
|
|
Pierre-Yves Chibon |
5cdb69 |
# Add a 3rd project with a long description
|
|
Pierre-Yves Chibon |
5cdb69 |
item = pagure.lib.model.Project(
|
|
Pierre-Yves Chibon |
5cdb69 |
user_id=2, # foo
|
|
Pierre-Yves Chibon |
5cdb69 |
name='test3',
|
|
Pierre-Yves Chibon |
5cdb69 |
description='test project #3 with a very long description',
|
|
Pierre-Yves Chibon |
5cdb69 |
hook_token='aaabbbeeefff',
|
|
Pierre-Yves Chibon |
5cdb69 |
)
|
|
Pierre-Yves Chibon |
5cdb69 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
5cdb69 |
self.session.commit()
|
|
Pierre-Yves Chibon |
5cdb69 |
|
|
Pierre-Yves Chibon |
5cdb69 |
user = tests.FakeUser(username='foo')
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Ryan Lerch |
336cd6 |
output = self.app.get('/', follow_redirects=True)
|
|
Pierre-Yves Chibon |
5cdb69 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
5cdb69 |
self.assertIn(
|
|
Ryan Lerch |
336cd6 |
'
|
|
Ryan Lerch |
336cd6 |
'opacity-100 border-0 ml-auto font-weight-bold">'
|
|
Pierre-Yves Chibon |
837e8c |
'1 Projects\n',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Ryan Lerch |
336cd6 |
self.assertNotIn(
|
|
Ryan Lerch |
336cd6 |
'All Projects '
|
|
Ryan Lerch |
336cd6 |
'3',
|
|
Pierre-Yves Chibon |
5872c5 |
output_text)
|
|
Pierre-Yves Chibon |
5872c5 |
|
|
Pierre-Yves Chibon |
5cdb69 |
|
|
Pierre-Yves Chibon |
5cdb69 |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
5cdb69 |
unittest.main(verbosity=2)
|