def test_confirmation_receiver_JSON_failure(self): """ This method tests the confirmation receiver JSON view of the confirmation page. The expected result of this test is for the session to have already been added to the database and to fail to be added again. """ # Add pattern and time to database time = datetime.datetime.now().replace(minute=5, second=0, microsecond=0) + datetime.timedelta(days=1) with transaction.manager: DBSession.add(Run(create_input_pattern(), time, "")) DBSession.commit # Set up request request = DummyRequest(route='/confirm.json') request.session["pattern"] = create_input_pattern() 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) # Test response has arrived assert response_dict # Assert that the data was not successfully stored. assert not response_dict["success"] # Assert that the response has been given a failure message. assert response_dict["failure_message"] # Assert that the session still exists. 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
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
def test_confirmation_receiver_HTTP_failure(self): """ This method tests the functionality of the confirmation receiver view. The expected result of this test is for the view to throw an exception because there has been a HTTP failure. """ # Set up a request to test the HTTP failure logic request = DummyRequest(route='/confirmation_receiver.json') # Assert an exception has been raised because the session 'has timed out' try: response = confirmation_receiver_JSON(request) except HTTPBadRequest as e: assert e.args[0] == "Session Timeout"