Ejemplo n.º 1
0
    def test_confirmation_page_data_not_in_POST_or_session(self):
        """
        This method will test the ability of the create view to access the correct page data from the session and/or
        POST. The expected result of this test is for the create view to raise an exception because the viewing
        information has not been passed to the confirmation page.
        """
        # Set up the request for testing the 'confirmation' page without viewing date
        request = DummyRequest(route='/create')
        request.POST["create_page"] = "confirmation"

        # Assert that an exception is thrown because a viewing date has not been stored in session or POST
        try:
            response = create_view(request)
        except ArgumentError as e:
            assert e.args[0] == "Viewing date was not submitted"

        # Set up the request for testing the 'confirmation' page without viewing hour
        request.POST["viewing_date"] = datetime.datetime(2014, 7, 21, 12, 30, 3).strftime("%d/%m/%Y")

        # Assert that an exception is thrown because a viewing hour has not been stored in session or POST
        try:
            response = create_view(request)
        except ArgumentError as e:
            assert e.args[0] == "Viewing hour was not submitted"

        # Set up the request for testing the 'confirmation' page without viewing slot
        request.POST["viewing_hour"] = datetime.datetime.now().hour

        # Assert that an exception is thrown because a viewing slot has not been stored in session or POST
        try:
            response = create_view(request)
        except ArgumentError as e:
            assert e.args[0] == "Viewing slot was not submitted"
Ejemplo n.º 2
0
    def test_session_data_for_pattern_input(self):
        """
        This method will test the ability of the create view to access the correct page data from the session. The
        expected result of this test is for the correct page data to be available for the 'pattern input' page.
        """
        # Set up the request for testing the 'create pattern' page on session
        session_request = DummyRequest(route='/create')
        session_request.session["create_page"] = "pattern_input"

        session_response = create_view(session_request)

        # Assert that the response contains the correct page data
        assert session_response["title"] == "Create Pattern"
        assert session_response["page"] == "patternpage"
Ejemplo n.º 3
0
    def test_confirmation_viewing_date_formatting_failure(self):
        """
        This method will test the ability of the create view to access the correct page data fro the session or
        POST. The expected result of this test is for the create view to raise an exception because the viewing date
        is the wrong format.
        """
        # Set up the request for testing the 'confirmation' page with a wrongly formatted viewing date
        request = DummyRequest(route='/create')
        request.POST["create_page"] = "confirmation"
        request.POST["viewing_date"] = datetime.datetime.today()

        # Assert that an exception is thrown because the viewing date is of the wrong format
        try:
            response = create_view(request)
        except ArgumentError as e:
            assert e.args[0] == "Viewing date incorrectly formatted"
Ejemplo n.º 4
0
    def test_create(self):
        """
        This method tests the pattern input view, emulating a user visiting the create pattern page for the first time.
        At this point, there is no pattern waiting in the session. The expected result of this test is for the user's
        pattern and page information to be correctly stored.
        """
        request = DummyRequest(route='/create')

        response = create_view(request)

        # Assert that a response was received.
        assert response

        # Assert that the response contains the correct data for this point of the process.
        assert response["page"] == "patternpage"
        assert response["title"] == "Create Pattern"
        assert "pattern" not in response.keys()
Ejemplo n.º 5
0
    def test_POST_page_data_for_scheduling(self):
        """
        This method will test the ability of the create view to access the correct page data from the POST. The
        expected result of this test is for the correct page data to be available for the 'scheduling' page.
        """
        # Set up the request for testing the 'scheduling' page on POST
        post_request = DummyRequest(route='/create')
        post_request.POST["create_page"] = "scheduler"

        post_response = create_view(post_request)

        # Assert that the response contains the correct page data
        assert post_response["title"] == "Scheduler"
        assert post_response["page"] == "patternpage"
        assert isinstance(post_response["viewing_date"], str)
        assert isinstance(post_response["viewing_hour"], int)
        assert isinstance(post_response["viewing_slot"], int)
Ejemplo n.º 6
0
    def test_create_page_after_confirmation(self):
        """
        This method tests the ability of the create view to recognise once a user has completed the pattern creation
        process. The expected result of this test is for the view to be recognise this state correctly.
        """
        # Set up a request to test the post-confirmation logic
        class session_dict(dict):
            def invalidate(self):
                pass
        request = MagicMock()
        d = session_dict()
        d["confirmed"] = "true"
        request.session = d

        response = create_view(request)

        # Assert that the 'user' has been rerouted to the beginning of the process
        assert isinstance(response, HTTPFound)
Ejemplo n.º 7
0
    def test_pattern_input_view_pattern(self):
        """
        This method the pattern input view, emulating when a user is revisiting the create pattern page and a pattern
        they have already created is waiting for them in the session. The expected result of this test is for the
        changes the user makes on this page to be correctly stored.
        """
        request = DummyRequest(route='/create')
        input = create_input_pattern()
        request.session["pattern"] = input

        response = create_view(request)

        # Assert that a response has been received.
        assert response

        # Assert that the response contains the correct data for this point in the process.
        assert response["page"] == "patternpage"
        assert response["title"] == "Create Pattern"
        assert response["pattern"] == input.replace('\n', "\\n")
Ejemplo n.º 8
0
    def test_session_page_data_for_scheduling(self):
        """
        This method will test the ability of the create view to access the correct page data from the session. The
        expected result of this test is for the correct page data to be available for the 'scheduling' page.
        """
        # Set up the request for testing the 'scheduling' page on session
        session_request = DummyRequest(route='/create')
        session_request.session["create_page"] = "scheduler"
        session_request.session["viewing_date"] = datetime.datetime.today().strftime("%d/%m/%Y")
        session_request.session["viewing_hour"] = datetime.datetime.now().hour
        session_request.session["viewing_slot"] = 25 # hard-coded because it must be a multiple of 5

        session_response = create_view(session_request)

        # Assert that the response contains the correct page data
        assert session_response["title"] == "Scheduler"
        assert session_response["page"] == "patternpage"
        assert isinstance(session_response["viewing_date"], str)
        assert isinstance(session_response["viewing_hour"], int)
        assert isinstance(session_response["viewing_slot"], int)
Ejemplo n.º 9
0
    def test_POST_page_data_for_confirmation(self):
        """
        This method will test the ability of the create view to access the correct page data from POST. The
        expected result of this test is for the correct page data to be available for the 'confirmation' page.
        """
        # Set up the request for testing the 'confirmation' page on POST
        post_request = DummyRequest(route='/create')
        post_request.POST["create_page"] = "confirmation"
        post_request.POST["viewing_date"] = datetime.datetime.today().strftime("%d/%m/%Y")
        post_request.POST["viewing_hour"] = datetime.datetime.now().hour
        post_request.POST["viewing_slot"] = 25 # hard-coded because it must be a multiple of 5

        post_response = create_view(post_request)

        # Assert that the response contains the correct page data
        assert post_response["title"] == "Confirmation"
        assert post_response["page"] == "patternpage"
        assert isinstance(post_response["viewing_date"], str)
        assert isinstance(post_response["viewing_hour"], int)
        assert isinstance(post_response["viewing_slot"], int)
        assert isinstance(post_response["display_address"], str)