Esempio n. 1
0
    def test_confirmation_receiver_JSON(self):
        """
        This method tests the confirmation receiver JSON view of the confirmation page. The expected result of this
        test is for the content of a session to be successfully added to the server-side database.
        """
        request = DummyRequest(route='/confirm.json')

        # Create a pattern to be saved to the database
        request.session["pattern"] = create_input_pattern()
        # Create a time and date to be saved for the pattern on the database
        time = datetime.datetime.now().replace(minute=0, second=0, microsecond=0) + datetime.timedelta(days=1)
        request.session["viewing_date"] = time.strftime("%d/%m/%Y")
        request.session["viewing_hour"] = time.strftime("%H")
        request.session["viewing_slot"] = time.strftime("%M")

        response_dict = confirmation_receiver_JSON(request)

        # Assert that a response has been retrieved.
        assert response_dict
        # Assert the data has been successfully stored to the database.
        assert response_dict["success"]

        # Assert that the data is inside the database.
        assert Run.get_run_for_time_slot(time)

        # Assert that the session has been emptied.
        assert not "pattern" in request.session
        assert not "viewing_date" in request.session
        assert not "viewing_hour" in request.session
        assert not "viewing_slot" in request.session