Esempio n. 1
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]
Esempio n. 2
0
    def test_time_slot_reciever_JSON(self):
        """
        This method will test the time slot receiver JSON view of the scheduling page. The expected result of this test
        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(days=1)

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

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

        response = time_slot_reciever_JSON(request)

        # Assert that a response has been retrieved.
        assert response

        response_dict = eval(str(response))

        no_of_hours = math.ceil(((project_config["closing_time"].hour*60 + project_config["closing_time"].minute) -
                                (project_config["starting_time"].hour*60 + project_config["starting_time"].minute)) / 60)
        # Assert the response holds the correct data.
        assert len(response_dict["hours"]) == no_of_hours
Esempio n. 3
0
    def test_time_slot_receiver_JSON_timestring_failure(self):
        """
        This method will test the functionality of the time_slot_receiver_JSON view. The expected result of this test
        is for the view to catch an error because the timestring for which the time_slot should be retrieved is in the
        wrong format.
        """
        # Set up a dummy request for testing poor formatting of the timestring
        request = DummyRequest(route='/sheduler.json')
        request.POST["date"] = datetime.datetime.now()

        # Assert that an exception is thrown due to the timestring not being formatted correctly
        try:
            response = time_slot_reciever_JSON(request)
        except HTTPBadRequest as e:
            assert e.args[0] == "Timestring was not formatted correctly!"