Example #1
0
    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
Example #2
0
 def test_insert(self):
     '''
     Test insertion of data into the runs table
     '''
     with transaction.manager:
         run = Run(create_input_pattern(), datetime.datetime.now(), self._insert_name)
         DBSession.add(run)
         DBSession.commit()
Example #3
0
 def test_insert(self):
     """
     This method tests the ability of the runs table to insert a new row. The expected result of this test is for
     a row to be inserted into the table correctly.
     """
     with transaction.manager:
         run = Run(create_input_pattern(), datetime.datetime.now(), self._insert_name)
         DBSession.add(run)
         DBSession.commit()
def test_run_transmitter_view():
    """
    This function tests the functionality of the run_transmitter view. The expected result of this
    test is that the view functions correctly and retrieves currently unsent runs for the raspberry pi.
    """
    time_slot = datetime.datetime.now() + datetime.timedelta(days=5)

    # Add a pattern and time to the database for testing
    with transaction.manager:
        DBSession.add(Run(create_input_pattern(), time_slot, ""))
        DBSession.commit()

    # Set up request
    request = DummyRequest(route="/run_transmitter.json")
    time_slot -= datetime.timedelta(hours=1)
    request.POST["min_time"] = time_slot.isoformat()

    # Call the view
    response = run_transmitter_view(request)

    # Test that the view has returned a response
    assert response
Example #5
0
    def insert_run(cls, pattern, time_slot):
        """
        Ensures that the pattern and time_slot meet validation
        and inserts the run into the run table.

        This method ensures that the pattern and time slot meet validation before inserting the run into the runs table
        of the server-side database.

        @param pattern The pattern to input into the table.
        @param time_slot The datetime at which the pattern should be run.
        """
        now = datetime.datetime.now()

        # Perform validation checks
        cls._validate_time_slot(now, time_slot)
        if cls.get_run_for_time_slot(time_slot):
            raise RunSlotTakenError("Time slots already has a run associated")

        # Insert pattern and time slot into database
        with transaction.manager:
            DBSession.add(Run(pattern, time_slot, ""))
            DBSession.commit()