Blame tests/test_progit_flask_ui_app.py

Pierre-Yves Chibon cfad13
# -*- coding: utf-8 -*-
Pierre-Yves Chibon cfad13
Pierre-Yves Chibon cfad13
"""
Pierre-Yves Chibon cfad13
 (c) 2015 - Copyright Red Hat Inc
Pierre-Yves Chibon cfad13
Pierre-Yves Chibon cfad13
 Authors:
Pierre-Yves Chibon cfad13
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon cfad13
Pierre-Yves Chibon cfad13
"""
Pierre-Yves Chibon cfad13
Pierre-Yves Chibon cfad13
__requires__ = ['SQLAlchemy >= 0.8']
Pierre-Yves Chibon cfad13
import pkg_resources
Pierre-Yves Chibon cfad13
Pierre-Yves Chibon cfad13
import unittest
Pierre-Yves Chibon cfad13
import shutil
Pierre-Yves Chibon cfad13
import sys
Pierre-Yves Chibon cfad13
import os
Pierre-Yves Chibon cfad13
Pierre-Yves Chibon cfad13
import json
Pierre-Yves Chibon cfad13
from mock import patch
Pierre-Yves Chibon cfad13
Pierre-Yves Chibon cfad13
sys.path.insert(0, os.path.join(os.path.dirname(
Pierre-Yves Chibon cfad13
    os.path.abspath(__file__)), '..'))
Pierre-Yves Chibon cfad13
Pierre-Yves Chibon cfad13
import progit.lib
Pierre-Yves Chibon cfad13
import tests
Pierre-Yves Chibon cfad13
Pierre-Yves Chibon cfad13
Pierre-Yves Chibon cfad13
class ProgitFlaskApptests(tests.Modeltests):
Pierre-Yves Chibon cfad13
    """ Tests for flask app of progit """
Pierre-Yves Chibon cfad13
Pierre-Yves Chibon cfad13
    def setUp(self):
Pierre-Yves Chibon cfad13
        """ Set up the environnment, ran before every tests. """
Pierre-Yves Chibon cfad13
        super(ProgitFlaskApptests, self).setUp()
Pierre-Yves Chibon cfad13
Pierre-Yves Chibon cfad13
        progit.APP.config['TESTING'] = True
Pierre-Yves Chibon cfad13
        progit.SESSION = self.session
Pierre-Yves Chibon cfad13
        progit.ui.SESSION = self.session
Pierre-Yves Chibon 720115
        progit.ui.app.SESSION = self.session
Pierre-Yves Chibon cfad13
        self.app = progit.APP.test_client()
Pierre-Yves Chibon 6e1ebb
        progit.APP.config['GIT_FOLDER'] = tests.HERE
Pierre-Yves Chibon 6e1ebb
        progit.APP.config['FORK_FOLDER'] = tests.HERE
Pierre-Yves Chibon 6e1ebb
        progit.APP.config['TICKET_FOLDER'] = tests.HERE
Pierre-Yves Chibon 6e1ebb
        progit.APP.config['DOC_FOLDER'] = tests.HERE
Pierre-Yves Chibon cfad13
Pierre-Yves Chibon cfad13
    def test_index(self):
Pierre-Yves Chibon 7827f1
        """ Test the index endpoint. """
Pierre-Yves Chibon cfad13
Pierre-Yves Chibon cfad13
        output = self.app.get('/')
Pierre-Yves Chibon cfad13
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon daa3de
        self.assertTrue('

All Projects (0)

' in output.data)
Pierre-Yves Chibon daa3de
Pierre-Yves Chibon daa3de
        tests.create_projects(self.session)
Pierre-Yves Chibon cfad13
Pierre-Yves Chibon 0ebfa3
        output = self.app.get('/?page=abc')
Pierre-Yves Chibon 0ebfa3
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0ebfa3
        self.assertTrue('

All Projects (2)

' in output.data)
Pierre-Yves Chibon 0ebfa3
Pierre-Yves Chibon 0ebfa3
        user = tests.FakeUser()
Pierre-Yves Chibon 0ebfa3
        with tests.user_set(progit.APP, user):
Pierre-Yves Chibon 0ebfa3
            output = self.app.get('/?repopage=abc&forkpage=def')
Pierre-Yves Chibon 0ebfa3
            self.assertTrue(
Pierre-Yves Chibon 0ebfa3
                '<section class="project_list" id="repos">' in output.data)</section>
Pierre-Yves Chibon 0ebfa3
            self.assertTrue('

My Forks (0)

' in output.data)
Pierre-Yves Chibon 0ebfa3
            self.assertTrue(
Pierre-Yves Chibon 0ebfa3
                '<section class="project_list" id="myforks">' in output.data)</section>
Pierre-Yves Chibon 0ebfa3
            self.assertTrue('

My Projects (0)

' in output.data)
Pierre-Yves Chibon 0ebfa3
            self.assertTrue(
Pierre-Yves Chibon 0ebfa3
                '<section class="project_list" id="myrepos">' in output.data)</section>
Pierre-Yves Chibon 0ebfa3
            self.assertTrue('

All Projects (2)

' in output.data)
Pierre-Yves Chibon 0ebfa3
Pierre-Yves Chibon 78d005
    def test_view_users(self):
Pierre-Yves Chibon 7827f1
        """ Test the view_users endpoint. """
Pierre-Yves Chibon 78d005
Pierre-Yves Chibon 78d005
        output = self.app.get('/users/?page=abc')
Pierre-Yves Chibon 78d005
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 78d005
        self.assertTrue('

2 users registered.

' in output.data)
Pierre-Yves Chibon 78d005
        self.assertTrue('' in output.data)
Pierre-Yves Chibon 78d005
        self.assertTrue('' in output.data)
Pierre-Yves Chibon 78d005
Pierre-Yves Chibon 045b56
    def test_view_user(self):
Pierre-Yves Chibon 7827f1
        """ Test the view_user endpoint. """
Pierre-Yves Chibon 045b56
Pierre-Yves Chibon 045b56
        output = self.app.get('/user/pingou?repopage=abc&forkpage=def')
Pierre-Yves Chibon 045b56
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 045b56
        self.assertTrue(
Pierre-Yves Chibon 045b56
            '<section class="project_list" id="repos">' in output.data)</section>
Pierre-Yves Chibon 8bcb94
        self.assertTrue('

Projects (0)

' in output.data)
Pierre-Yves Chibon 045b56
        self.assertTrue(
Pierre-Yves Chibon 045b56
            '<section class="project_list" id="forks">' in output.data)</section>
Pierre-Yves Chibon 8bcb94
        self.assertTrue('

Forks (0)

' in output.data)
Pierre-Yves Chibon 045b56
Pierre-Yves Chibon 8bcb94
        tests.create_projects(self.session)
Pierre-Yves Chibon 293dcb
        self.gitrepos = tests.create_projects_git(
Pierre-Yves Chibon 8bcb94
            progit.APP.config['GIT_FOLDER'])
Pierre-Yves Chibon 8bcb94
Pierre-Yves Chibon 8bcb94
        output = self.app.get('/user/pingou?repopage=abc&forkpage=def')
Pierre-Yves Chibon 8bcb94
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 8bcb94
        self.assertTrue(
Pierre-Yves Chibon 8bcb94
            '<section class="project_list" id="repos">' in output.data)</section>
Pierre-Yves Chibon 8bcb94
        self.assertTrue('

Projects (2)

' in output.data)
Pierre-Yves Chibon 8bcb94
        self.assertTrue(
Pierre-Yves Chibon 8bcb94
            '<section class="project_list" id="forks">' in output.data)</section>
Pierre-Yves Chibon 8bcb94
        self.assertTrue('

Forks (0)

' in output.data)
Pierre-Yves Chibon 045b56
Pierre-Yves Chibon cfad13
Pierre-Yves Chibon cfad13
if __name__ == '__main__':
Pierre-Yves Chibon cfad13
    SUITE = unittest.TestLoader().loadTestsFromTestCase(ProgitFlaskApptests)
Pierre-Yves Chibon cfad13
    unittest.TextTestRunner(verbosity=2).run(SUITE)