Skip to content
Snippets Groups Projects
  • Mitchell Moore's avatar
    Added test scripts to check redir and test outputs. Added overlay on account... · 16a7dcc0
    Mitchell Moore authored
    Added test scripts to check redir and test outputs. Added overlay on account request submiission. Basic CSS changes.
    
    - Added testing script to utilize 'testing' config.
    - (fix) fix src file reference
    - Semantic fix for route order
    - Semantic fix for variable name/position.
    - (fix) indexing fix for redir args and test output.
    - (fix) issue with icons not showing
    - (fix) variable reference of fullname to success page.
    - Clean up readme typos and make it more concise.
    - Feat check account existence
    - Added base.html to inherit form values from Signup.html
    - Clean up code to function properly
    - add 'validators' dependency
    - fix fullname reference in submit statement
    - Fix default title error
    - fix routing logic in index
    - remove dev comments
    - Fix falure logic routing and edit error message
    - Apply css formatting to jinja elements and fix form size issues
    - Reintroduce form label/instruction
    - Produce overlay window with text from jobcomposer tutorial
    - add temporary functionality to call window for testing
    - replace next and escape button with loading.gif
    - Edited text formating/content of notification window
    - Refactor gif to center
    16a7dcc0
tests.py 2.57 KiB
# tests.py

import unittest

import flask
from flask import abort, url_for, g
from flask_testing import TestCase

from app import create_app


class TestBase(TestCase):

    def create_app(self):
        app = create_app('testing')
        return app

    def setUp(self):
        """
        Will be called before every test
        """
        app = create_app('testing')
        return app

    def tearDown(self):
        """
        Will be called after every test
        """


class TestModels(TestBase):
    # TODO: make tests
    pass


class TestViews(TestBase):
    # TODO: make tests

    def test_index_view(self):
        """
        Test that homepage is accessible.
        """

        response = self.client.get(url_for('index'))
        self.assertEqual(response.status_code, 200)

        # with self.app.test_client() as c:
        #     rv = c.get('/')
        #     assert flask.session['REMOTE_USER'] == 'bobby'

    def test_page_resources(self):
        """
        Test that all resources load are found.
        """
        with self.app.test_request_context('/?redir=test'):
            assert flask.request.path == '/'
            c = flask.app.request.args['redir']
            assert c == 'test'

    # def test_logout_view(self):
    #     """
    #     Test that logout link is inaccessible without login
    #     and redirects to login page then to logout
    #     """
    #     target_url = url_for('auth.logout')
    #     redirect_url = url_for('auth.login', next=target_url)
    #     response = self.client.get(target_url)
    #     self.assertEqual(response.status_code, 302)
    #     self.assertRedirects(response, redirect_url)\


class TestErrorPages(TestBase):

    def test_403_forbidden(self):
        # create route to abort the request with the 403 Error
        @self.app.route('/403')
        def forbidden_error():
            abort(403)

        response = self.client.get('/403')
        self.assertEqual(response.status_code, 403)
        self.assertTrue("403 Error" in response.data)

    def test_404_not_found(self):
        response = self.client.get('/nothinghere')
        self.assertEqual(response.status_code, 404)
        self.assertTrue("404 Error" in response.data)

    def test_500_internal_server_error(self):
        # create route to abort the request with the 500 Error
        @self.app.route('/500')
        def internal_server_error():
            abort(500)

        response = self.client.get('/500')
        self.assertEqual(response.status_code, 500)
        self.assertTrue("500 Error" in response.data)


if __name__ == '__main__':
    unittest.main()