import unittest

from no_global_flask_app.views import (
    get_route_index,
    get_route_foo,
    get_route_bar,
    get_app,
)


class TestNGFAViewsRouteConfiguration(unittest.TestCase):
    """Mutate the global instance of Flask to test the routes without
    directly testing the functions configured for the respective view.

    """

    def setUp(self):
        app = get_app(True)
        self.client = app.test_client()

    def tearDown(self):
        pass

    def get_mutated_function(self, fname):
        def get_mutated_response():
            return f"mutated to only test the endpoint for {fname}"

        return get_mutated_response

    def test_index(self):
        fname = "index"
        self.client.application.view_functions[fname] = self.get_mutated_function(fname)
        response = self.client.get(get_route_index())
        self.assertTrue(
            response.status_code == 200, "Passing test should return status code 200"
        )

    def test_foo(self):
        fname = "foo"
        self.client.application.view_functions[fname] = self.get_mutated_function(fname)
        response = self.client.get(get_route_foo())
        self.assertTrue(
            response.status_code == 200, "Passing test should return status code 200"
        )

    def test_bar(self):
        fname = "bar"
        self.client.application.view_functions[fname] = self.get_mutated_function(fname)
        response = self.client.get(get_route_bar())
        self.assertTrue(
            response.status_code == 200, "Passing test should return status code 200"
        )

    def test_bad_route(self):
        response = self.client.get(f"{get_route_foo()}/asdfasdsfasdfasdfasdfasdf")
        self.assertFalse(
            response.status_code == 200, "Passing test should return status code 200"
        )
