Beispiel #1
0
    def test_reporting(self):

        states = Report.states

        dp = DropPoint(1, lat=0, lng=0, level=1)

        first_time = datetime.today()
        first_state = states[0]
        first_report = Report(dp, state=first_state, time=first_time)

        db.session.commit()

        self.assertEqual(first_report.time, first_time,
                         "Report creation time not as expected.")

        self.assertEqual(first_report.state, first_state,
                         "Report state not as expected.")

        self.assertEqual(
            dp.reports[0], first_report,
            "First report not first report of associated drop point.")

        self.assertEqual(dp.get_last_report(), first_report,
                         "get_last_report() did not return first report.")

        self.assertEqual(dp.get_last_state(), first_state,
                         "get_last_state() did not return state.")

        self.assertEqual(dp.get_total_report_count(), 1,
                         "get_total_report_count() not as expected.")

        self.assertEqual(dp.get_new_report_count(), 1,
                         "get_new_report_count() not as expected.")

        self.assertEqual(
            dp.get_new_reports()[0], first_report,
            "First element returned by get_new_reports() not the report wanted."
        )

        second_time = datetime.today()
        second_state = states[-1]
        second_report = Report(dp, state=second_state, time=second_time)

        db.session.commit()

        self.assertEqual(second_report.state, second_state,
                         "Report state not as expected.")

        self.assertEqual(
            dp.reports[-1], second_report,
            "Second report not last report of associated drop point.")

        self.assertEqual(dp.get_last_report(), second_report,
                         "get_last_report() did not return second report.")

        self.assertEqual(dp.get_last_state(), second_state,
                         "get_last_state() did not return second state.")

        self.assertEqual(dp.get_total_report_count(), 2,
                         "get_total_report_count() not as expected.")

        self.assertEqual(dp.get_new_report_count(), 2,
                         "get_new_report_count() not as expected.")

        self.assertEqual(
            dp.get_new_reports()[0], second_report,
            "First element returned by get_new_reports() not the report wanted."
        )
Beispiel #2
0
    def test_getters(self):

        dp_number = 1
        time = datetime.today()

        dp = DropPoint(dp_number, time=time, lat=0, lng=0, level=1)

        db.session.commit()

        self.assertEqual(
            DropPoint.get(dp_number), dp,
            "DropPoint.get() did not return the drop point created.")

        wrong_numbers = (dp_number + 1, -1, "foo", None)

        for number in wrong_numbers:
            self.assertIsNone(
                DropPoint.get(number),
                "DropPoint.get() for wrong number number did not return None.")

        self.assertIsInstance(
            dp.get_current_location(), Location,
            "get_current_location() is not a Location object.")

        self.assertEqual(dp.get_last_state(), Report.states[1],
                         "get_last_state() did not return the default state.")

        self.assertEqual(dp.get_total_report_count(), 0,
                         "get_total_report_count() did not return 0.")

        self.assertEqual(dp.get_new_report_count(), 0,
                         "get_new_report_count() did not return 0.")

        self.assertFalse(dp.get_last_visit(),
                         "get_last_visit() returned something not False.")

        self.assertFalse(dp.get_last_report(),
                         "get_last_report() returned something not False.")

        self.assertFalse(dp.get_new_reports(),
                         "get_new_reports() returned something not False.")

        self.assertGreater(dp.get_visit_interval(), 0,
                           "get_visit_interval() returned a value <= 0.")

        self.assertIsInstance(dp.get_history(), list,
                              "get_history() did not return a list.")

        for elem in dp.get_history():
            self.assertIsInstance(
                elem, dict, "get_history() did not return a list of dicts.")

        # The history should have 2 entries:
        # 1. drop point creation
        # 2. location setting
        assumed_history_length = 2

        self.assertEqual(len(dp.get_history()), assumed_history_length,
                         "get_history() does not have a length of 3.")

        self.assertIsInstance(DropPoint.get_dps_json(), str,
                              "get_dps_json() did not return a string.")

        self.assertGreater(len(DropPoint.get_dps_json()), 1,
                           "get_dps_json() did return a string too short.")

        self.assertEqual(
            DropPoint.get_dps_json(datetime.today()), "{}",
            "get_dps_json() for now did not return an empty JSON object.")

        self.assertEqual(DropPoint.get_dps_json(datetime.today()), "{}",
                         "get_dps_json() JSON object for now not empty.")

        self.assertEqual(
            DropPoint.get_dps_json(time), "{}",
            "get_dps_json() JSON object for creation time not empty.")

        self.assertNotEqual(
            DropPoint.get_dps_json(time - timedelta(seconds=1)), "{}",
            "get_dps_json() JSON object for time < creation time empty.")
Beispiel #3
0
    def test_construction(self):

        actions = Visit.actions

        dp = DropPoint(1, lat=0, lng=0, level=1)

        first_time = datetime.today()
        first_action = actions[1]
        first_visit = Visit(dp, action=first_action, time=first_time)

        db.session.commit()

        self.assertEqual(
            first_visit.time, first_time,
            "Visit creation time not as expected."
        )

        self.assertEqual(
            first_visit.action, first_action,
            "Visit action not as expected."
        )

        self.assertEqual(
            dp.visits[0], first_visit,
            "First visit not first visit of associated drop point."
        )

        self.assertEqual(
            dp.get_last_visit(), first_visit,
            "get_last_visit() did not return first visit."
        )

        report_time = datetime.today()
        report_state = Report.states[0]
        report = Report(dp, state=report_state, time=report_time)

        second_time = datetime.today()
        second_action = actions[0]
        second_visit = Visit(dp, action=second_action, time=second_time)

        db.session.commit()

        self.assertEqual(
            second_visit.action, second_action,
            "Visit action not as expected."
        )

        self.assertEqual(
            dp.visits[-1], second_visit,
            "Second visit not last visit of associated drop point."
        )

        self.assertEqual(
            dp.get_last_visit(), second_visit,
            "get_last_visit() did not return second visit."
        )

        self.assertNotEqual(
            dp.get_last_state(), report_state,
            "get_last_state() returns unchanged state after visit."
        )

        self.assertEqual(
            dp.get_new_report_count(), 0,
            "get_new_report_count() nonzero after visit."
        )

        self.assertFalse(
            dp.get_new_reports(),
            "get_new_reports() returned something not False after visit."
        )

        self.assertEqual(
            dp.get_last_report(), report,
            "get_last_report() did not return report after visit."
        )

        self.assertEqual(
            dp.get_total_report_count(), 1,
            "get_total_report_count() not as expected after visit."
        )