Beispiel #1
0
    def test_run_get_time_slots_for_day_with_runs(self):
        """
        This method tests the ability of the runs table to retrieve the available time slots in a given day. The
        expected result of this test is for the number of retrieved time slots to be equal to the number of five
        minute time slots in a day minus two (for two runs).
        """
        # Give the method a future date and receive correct no. of time-slots for that date
        date = datetime.date.today() + datetime.timedelta(days=2)

        min_time = project_config["starting_time"]
        max_time = project_config["closing_time"]
        # Calculate the no. of hours in a given day to test
        no_mins = (max_time.hour*60 + max_time.minute) - (min_time.hour*60 + min_time.minute)
        no_time_slots = math.ceil(no_mins / 5)

        date = datetime.datetime.combine(date, datetime.time(hour=12, minute=0, second=0, microsecond=0))

        runs = [
            Run(create_input_pattern(), date, self._insert_name),
            Run(create_input_pattern(), date + datetime.timedelta(minutes=5), self._insert_name)]
        with transaction.manager:
            DBSession.add_all(runs)
            DBSession.commit

        time_slots = Run.get_time_slots_for_day(date, datetime.datetime.now())

        # Assert that the correct number of available time slots have been retrieved.
        assert no_time_slots - len(runs) == len(time_slots)
Beispiel #2
0
    def test_time_slot_receiver_JSON_runs(self):
        """
        This method tests the time slot receiver JSON view when there are runs in the server-side database. The
        expected result of this pattern is for the correct JSON response to be retrieved.
        """
        request = DummyRequest(route='/scheduler.json')

        if project_config["start_date"]:
            input_date = datetime.datetime.combine(project_config["start_date"], datetime.time())
        else:
            input_date = datetime.datetime.today() + datetime.timedelta(hours=1)

        user_input = int(time.mktime(input_date.timetuple()) * 1000)

        request.content_type = "application/json"
        request.POST["date"] = str(user_input)

        # Insert runs that will the next hour with even minutes that are a multiple of 10
        with transaction.manager:
            runs = []
            for minutes in range(0, 60, 10):
                runs.append(Run(create_input_pattern(), datetime.datetime(input_date.year, input_date.month,
                                                                          input_date.day, input_date.hour, minutes), ""))
            DBSession.add_all(runs)
            DBSession.commit()

        response = time_slot_reciever_JSON(request)

        # Assert that a response has been received.
        assert response

        response_dict = eval(str(response))
        for min in range(0, 60, 10):
            # Assert that the given slot is not in the response (means there is a run at this point)
            assert min not in response_dict[input_date.hour]
Beispiel #3
0
    def test_run_get_unsent_runs(self):
        """
        This method tests the ability of the runs table to retrieve the runs than have not yet been sent to the
        raspberry pi. The expected result of this test is that the unsent runs can be correctly retrieved.
        """

        time_slot = datetime.datetime.now() + datetime.timedelta(days=35)

        # Create some runs to go into the table
        runs = [
            Run(create_input_pattern(), time_slot, self._insert_name),
            Run(create_input_pattern(), time_slot + datetime.timedelta(minutes=5), self._insert_name),
            Run(create_input_pattern(), time_slot + datetime.timedelta(minutes=10), self._insert_name)
        ]

        # Add runs to table
        with transaction.manager:
            DBSession.add_all(runs)
            DBSession.commit()

        new_sent_runs = Run.get_unsent_runs(time_slot - datetime.timedelta(minutes=5))

        # Assert that the collected runs have been retrieved
        assert new_sent_runs
        # Assert that the list of sent runs contains the correct number of runs
        assert len(new_sent_runs) == 3

        # Create some more runs to go into the table
        new_runs = [
            Run(create_input_pattern(), time_slot + datetime.timedelta(minutes=15), self._insert_name),
            Run(create_input_pattern(), time_slot + datetime.timedelta(minutes=20), self._insert_name),
            Run(create_input_pattern(), time_slot + datetime.timedelta(minutes=25), self._insert_name)
        ]

        # Add these runs to the table
        with transaction.manager:
            DBSession.add_all(new_runs)
            DBSession.commit()

        new_sent_runs = Run.get_unsent_runs(time_slot - datetime.timedelta(minutes=5))

        # Assert that the collected runs have been retrieved
        assert new_sent_runs
        # Assert that the list of sent runs still contains the correct number of runs
        assert len(new_sent_runs) == 3
Beispiel #4
0
    def test_run_get_runs_for_day_with_runs(self):
        """
        This method tests the ability of the runs table to retrieve every run set to be played on a given day. The
        expected result should be for the call to result in the same number of runs as previously added.
        """
        dt = datetime.datetime.now() + datetime.timedelta(days=1)
        dt = dt.replace(minute=0, second=0, microsecond=0)

        runs = [
            Run(create_input_pattern(), dt, self._insert_name),
            Run(create_input_pattern(), dt + datetime.timedelta(minutes=5), self._insert_name)]
        with transaction.manager:
            DBSession.add_all(runs)
            DBSession.commit

        date = datetime.date.today() + datetime.timedelta(days=1)
        dayRuns = Run.get_runs_for_day(date)
        # Assert that the correct number of runs have been retrieved
        assert dayRuns == runs