Example #1
0
    def test_confine_to_station(self):
        passenger = self.passenger
        order = create_test_order(passenger)
        confining_station = create_another_TLV_station()

        order.confining_station = confining_station
        order.save()

        # order, should get confining station
        resuscitate_work_stations()
        self.assertTrue(
            choose_workstation(order).station == confining_station,
            "confining station is expected")

        # order out of confining station service radius, should still assign the order
        order.from_lat, order.from_lon = FAR_AWAY_LAT, FAR_AWAY_LON
        order.to_lat, order.to_lon = None, None
        order.save()
        refresh_order(order)
        self.assertTrue(
            choose_workstation(order).station == confining_station,
            "confining station is expected")

        # create a REJECTED assignment by confining_station, should get None
        assignment = OrderAssignment(
            order=order,
            station=confining_station,
            work_station=confining_station.work_stations.all()[0],
            status=REJECTED)
        assignment.save()
        refresh_order(order)
        self.assertTrue(
            choose_workstation(order) is None, "no ws is expected.")
Example #2
0
    def test_choose_workstation_order_default_and_originating(self):
        """
        Test the order when we have a default and an originating station
        """
        order = self.order
        passenger = self.passenger

        tel_aviv_station = self.tel_aviv_station  # should have 2 work stations (from fixtures)
        default_station = create_another_TLV_station(num_of_ws=2)
        originating_station = create_another_TLV_station(num_of_ws=2)

        # set originating and default station
        order.originating_station = originating_station
        order.save()

        passenger.default_station = default_station
        passenger.save()
        order.passenger = passenger
        order.save()

        resuscitate_work_stations()

        # round trip, in the following order
        for station in [originating_station
                        ] * 2 + [default_station] * 2 + [tel_aviv_station] * 2:
            ws = choose_workstation(order)
            self.assertTrue(
                ws.station == station,
                "wrong station order: expected %s got %s" %
                (station, ws.station))

        # order should return to originating_station
        ws = choose_workstation(order)
        self.assertTrue(ws.station == originating_station,
                        "originating station is expected")
Example #3
0
    def _run_ignored_or_rejected_test(self, status):
        order = self.order

        tel_aviv = self.tel_aviv_station
        tel_aviv_ws1 = tel_aviv.work_stations.all()[0]
        tel_aviv_ws2 = tel_aviv.work_stations.all()[1]

        tel_aviv_2 = create_another_TLV_station()
        tel_aviv_ws3 = tel_aviv_2.work_stations.all()[0]

        resuscitate_work_stations()

        # create an IGNORED/REJECTED assignment by first station (ws1, ws2), should get ws3
        assignment = OrderAssignment(order=order,
                                     station=tel_aviv,
                                     work_station=tel_aviv_ws1,
                                     status=status)
        assignment.save()
        ws_list = compute_ws_list(order)
        self.assertTrue(
            tel_aviv_ws1 not in ws_list and tel_aviv_ws2 not in ws_list,
            "this station ignored the order.")

        next_ws = choose_workstation(order)
        self.assertTrue(next_ws == tel_aviv_ws3, "tel aviv ws3 is expected.")

        # create an IGNORED/REJECTED assignment by ws3, should get None
        assignment = OrderAssignment(order=order,
                                     station=tel_aviv_2,
                                     work_station=tel_aviv_ws3,
                                     status=status)
        assignment.save()
        refresh_order(order)
        self.assertTrue(
            choose_workstation(order) is None, "no ws is expected.")
Example #4
0
    def test_choose_workstation_order_default_and_originating(self):
        """
        Test the order when we have a default and an originating station
        """
        order = self.order
        passenger = self.passenger

        tel_aviv_station = self.tel_aviv_station # should have 2 work stations (from fixtures)
        default_station = create_another_TLV_station(num_of_ws=2)
        originating_station = create_another_TLV_station(num_of_ws=2)

        # set originating and default station
        order.originating_station = originating_station
        order.save()

        passenger.default_station = default_station
        passenger.save()
        order.passenger = passenger
        order.save()

        resuscitate_work_stations()

        # round trip, in the following order
        for station in [originating_station]*2 + [default_station]*2 + [tel_aviv_station]*2:
            ws = choose_workstation(order)
            self.assertTrue(ws.station == station, "wrong station order: expected %s got %s" % (station, ws.station))

        # order should return to originating_station
        ws = choose_workstation(order)
        self.assertTrue(ws.station == originating_station, "originating station is expected")
Example #5
0
    def test_choose_workstation_basics(self):
        order = self.order

        tel_aviv_ws1 = self.tel_aviv_station.work_stations.all()[0]
        tel_aviv_ws2 = self.tel_aviv_station.work_stations.all()[1]
        jerusalem_ws = self.jerusalem_station.work_stations.all()[0]

        # work stations are dead
        self.assertTrue(
            choose_workstation(order) is None,
            "work station are dead, none is expected")

        # live work station but it's in Jerusalem (order is from tel aviv)
        jerusalem_ws.is_online = True
        jerusalem_ws.save()
        self.assertTrue(
            choose_workstation(order) is None,
            "work station are dead, none is expected")
        refresh_order(order)

        # live but don't accept orders
        set_accept_orders_false([tel_aviv_ws1, tel_aviv_ws2])
        resuscitate_work_stations()
        self.assertTrue(
            choose_workstation(order) is None,
            "don't accept orders, none is expected.")
        refresh_order(order)

        # tel_aviv_ws2 is live and accepts orders
        set_accept_orders_true([tel_aviv_ws2])
        resuscitate_work_stations()
        self.assertTrue(
            choose_workstation(order) == tel_aviv_ws2,
            "tel aviv work station 2 is expected.")
        refresh_order(order)
Example #6
0
    def _run_ignored_or_rejected_test(self, status):
        order = self.order

        tel_aviv = self.tel_aviv_station
        tel_aviv_ws1 = tel_aviv.work_stations.all()[0]
        tel_aviv_ws2 = tel_aviv.work_stations.all()[1]

        tel_aviv_2 = create_another_TLV_station()
        tel_aviv_ws3 = tel_aviv_2.work_stations.all()[0]

        resuscitate_work_stations()

        # create an IGNORED/REJECTED assignment by first station (ws1, ws2), should get ws3
        assignment = OrderAssignment(order=order, station=tel_aviv, work_station=tel_aviv_ws1, status=status)
        assignment.save()
        ws_list = compute_ws_list(order)
        self.assertTrue(tel_aviv_ws1 not in ws_list and tel_aviv_ws2 not in ws_list, "this station ignored the order.")

        next_ws = choose_workstation(order)
        self.assertTrue(next_ws == tel_aviv_ws3, "tel aviv ws3 is expected.")

        # create an IGNORED/REJECTED assignment by ws3, should get None
        assignment = OrderAssignment(order=order, station=tel_aviv_2, work_station=tel_aviv_ws3, status=status)
        assignment.save()
        refresh_order(order)
        self.assertTrue(choose_workstation(order) is None, "no ws is expected.")
Example #7
0
    def test_choose_workstation_basics(self):
        order = self.order

        tel_aviv_ws1 = self.tel_aviv_station.work_stations.all()[0]
        tel_aviv_ws2 = self.tel_aviv_station.work_stations.all()[1]
        jerusalem_ws = self.jerusalem_station.work_stations.all()[0]

        # work stations are dead
        self.assertTrue(choose_workstation(order) is None, "work station are dead, none is expected")

        # live work station but it's in Jerusalem (order is from tel aviv)
        jerusalem_ws.is_online = True
        jerusalem_ws.save()
        self.assertTrue(choose_workstation(order) is None, "work station are dead, none is expected")
        refresh_order(order)

        # live but don't accept orders
        set_accept_orders_false([tel_aviv_ws1, tel_aviv_ws2])
        resuscitate_work_stations()
        self.assertTrue(choose_workstation(order) is None, "don't accept orders, none is expected.")
        refresh_order(order)

        # tel_aviv_ws2 is live and accepts orders
        set_accept_orders_true([tel_aviv_ws2])
        resuscitate_work_stations()
        self.assertTrue(choose_workstation(order) == tel_aviv_ws2, "tel aviv work station 2 is expected.")
        refresh_order(order)
Example #8
0
    def test_dispatcher_sort_by_distance(self):
        order = self.order
        tel_aviv_station = self.tel_aviv_station
        resuscitate_work_stations()
        self.assertEqual(choose_workstation(order).station, tel_aviv_station)

        refresh_order(order)
        
        another_station = create_another_TLV_station() # create a closer station to order
        resuscitate_work_stations()

        self.assertEqual(choose_workstation(order).station, another_station)
        self.assertEqual(choose_workstation(order).station, tel_aviv_station)
Example #9
0
    def test_originating_station(self):
        passenger = self.passenger
        order = create_test_order(passenger)

        tel_aviv_station = self.tel_aviv_station
        originating_station = create_another_TLV_station()

        order.originating_station = originating_station
        order.save()

        # set the originating station
        self.client.post(reverse('ordering.order_manager.book_order'),
                         data={"order_id": order.id})
        passenger = Passenger.objects.get(id=passenger.id)  # refresh passenger
        self.assertTrue(
            passenger.originating_station == originating_station,
            "passenger.originating_station should be tel_aviv_station and not %s"
            % passenger.originating_station)
        refresh_order(order)

        # resuscitate work stations and order
        resuscitate_work_stations()
        self.assertTrue(
            choose_workstation(order).station == originating_station,
            "originating station is expected")

        # check originating station overrides last assignment date criteria
        tel_aviv_station.last_assignment_date = datetime.datetime.now()
        tel_aviv_station.save()
        refresh_order(order)
        self.assertTrue(
            choose_workstation(order).station == originating_station,
            "originating station is expected")

        # test same originating and default stations results in one assignment
        passenger.default_station = originating_station
        passenger.save()
        order = refresh_order(order)
        order.passenger = passenger
        order.save()
        self.assertTrue(
            order.passenger.default_station == order.originating_station,
            "originating and default stations are not the same")

        resuscitate_work_stations()
        ws_list = compute_ws_list(order)
        count = ws_list.count(originating_station.work_stations.all()[0])
        self.assertTrue(
            count == 1,
            "originating (==default) station should appear exactly once (got %d)"
            % count)
Example #10
0
    def test_dispatcher_sort_by_distance(self):
        order = self.order
        tel_aviv_station = self.tel_aviv_station
        resuscitate_work_stations()
        self.assertEqual(choose_workstation(order).station, tel_aviv_station)

        refresh_order(order)

        another_station = create_another_TLV_station(
        )  # create a closer station to order
        resuscitate_work_stations()

        self.assertEqual(choose_workstation(order).station, another_station)
        self.assertEqual(choose_workstation(order).station, tel_aviv_station)
Example #11
0
    def test_choose_workstation_order(self):
        order = self.order
        resuscitate_work_stations()

        station1 = self.tel_aviv_station  # should have 2 work stations (from fixtures)
        station2 = create_another_TLV_station(num_of_ws=2)

        resuscitate_work_stations()

        ws_list = compute_ws_list(order)

        # stations should alternate
        self.assertTrue(
            ws_list[0].station == ws_list[2].station
            and ws_list[1].station == ws_list[3].station,
            "stations should alternate")

        # work stations should alternate
        self.assertTrue(ws_list[0] != ws_list[2] and ws_list[1] != ws_list[3],
                        "work stations should alternate")

        #
        # scenario: station x -> station y (reject) -> station x
        #
        order = create_test_order()
        first_ws = choose_workstation(order)
        second_ws = choose_workstation(order)

        assignment = OrderAssignment(order=order,
                                     station=second_ws.station,
                                     work_station=second_ws,
                                     status=REJECTED)
        assignment.save()
        refresh_order(order)

        third_ws = choose_workstation(order)

        self.assertTrue(third_ws.station == first_ws.station)

        #
        # scenario: station x -> station y (not taken) -> station x -> station y other ws
        #
        order = create_test_order()
        first_ws = choose_workstation(order)
        second_ws = choose_workstation(order)

        assignment = OrderAssignment(order=order,
                                     station=second_ws.station,
                                     work_station=second_ws,
                                     status=NOT_TAKEN)
        assignment.save()

        third_ws = choose_workstation(order)
        fourth_ws = choose_workstation(order)

        self.assertTrue(second_ws.station == fourth_ws.station
                        and second_ws != fourth_ws)
Example #12
0
    def test_default_station(self):
        order = self.order
        passenger = self.passenger
        tel_aviv_station = self.tel_aviv_station
        default_station = create_another_TLV_station()

        passenger.default_station = default_station
        passenger.save()
        order.passenger = passenger
        order.save()

        # resuscitate work stations and order
        resuscitate_work_stations()
        self.assertTrue(choose_workstation(order).station == default_station, "default station is expected.")

        # check default station overrides last assignment date criteria
        tel_aviv_station.last_assignment_date = datetime.datetime.now()
        tel_aviv_station.save()
        refresh_order(order)
        self.assertTrue(choose_workstation(order).station == default_station, "default station is expected")
Example #13
0
    def test_originating_station(self):
        passenger = self.passenger
        order = create_test_order(passenger)

        tel_aviv_station = self.tel_aviv_station
        originating_station = create_another_TLV_station()

        order.originating_station = originating_station
        order.save()

        # set the originating station
        self.client.post(reverse('ordering.order_manager.book_order'), data={"order_id": order.id})
        passenger = Passenger.objects.get(id=passenger.id) # refresh passenger
        self.assertTrue(passenger.originating_station == originating_station, "passenger.originating_station should be tel_aviv_station and not %s" % passenger.originating_station)
        refresh_order(order)
        
        # resuscitate work stations and order
        resuscitate_work_stations()
        self.assertTrue(choose_workstation(order).station == originating_station, "originating station is expected")

        # check originating station overrides last assignment date criteria
        tel_aviv_station.last_assignment_date = datetime.datetime.now()
        tel_aviv_station.save()
        refresh_order(order)
        self.assertTrue(choose_workstation(order).station == originating_station, "originating station is expected")


        # test same originating and default stations results in one assignment
        passenger.default_station = originating_station
        passenger.save()
        order = refresh_order(order)
        order.passenger = passenger
        order.save()
        self.assertTrue(order.passenger.default_station == order.originating_station, "originating and default stations are not the same")

        resuscitate_work_stations()
        ws_list = compute_ws_list(order)
        count = ws_list.count(originating_station.work_stations.all()[0])
        self.assertTrue(count == 1, "originating (==default) station should appear exactly once (got %d)" % count)
Example #14
0
    def test_default_station(self):
        order = self.order
        passenger = self.passenger
        tel_aviv_station = self.tel_aviv_station
        default_station = create_another_TLV_station()

        passenger.default_station = default_station
        passenger.save()
        order.passenger = passenger
        order.save()

        # resuscitate work stations and order
        resuscitate_work_stations()
        self.assertTrue(
            choose_workstation(order).station == default_station,
            "default station is expected.")

        # check default station overrides last assignment date criteria
        tel_aviv_station.last_assignment_date = datetime.datetime.now()
        tel_aviv_station.save()
        refresh_order(order)
        self.assertTrue(
            choose_workstation(order).station == default_station,
            "default station is expected")
Example #15
0
    def test_confine_to_station(self):
        passenger = self.passenger
        order = create_test_order(passenger)
        confining_station = create_another_TLV_station()

        order.confining_station = confining_station
        order.save()

        # order, should get confining station
        resuscitate_work_stations()
        self.assertTrue(choose_workstation(order).station == confining_station, "confining station is expected")

        # order out of confining station service radius, should still assign the order
        order.from_lat, order.from_lon = FAR_AWAY_LAT, FAR_AWAY_LON
        order.to_lat, order.to_lon = None, None
        order.save()
        refresh_order(order)
        self.assertTrue(choose_workstation(order).station == confining_station, "confining station is expected")

        # create a REJECTED assignment by confining_station, should get None
        assignment = OrderAssignment(order=order, station=confining_station, work_station=confining_station.work_stations.all()[0], status=REJECTED)
        assignment.save()
        refresh_order(order)
        self.assertTrue(choose_workstation(order) is None, "no ws is expected.")
Example #16
0
    def test_choose_workstation_order(self):
        order = self.order
        resuscitate_work_stations()

        station1 = self.tel_aviv_station # should have 2 work stations (from fixtures)
        station2 = create_another_TLV_station(num_of_ws=2)

        resuscitate_work_stations()
        
        ws_list = compute_ws_list(order)

        # stations should alternate
        self.assertTrue(ws_list[0].station == ws_list[2].station and ws_list[1].station == ws_list[3].station, "stations should alternate")

        # work stations should alternate
        self.assertTrue(ws_list[0] != ws_list[2] and ws_list[1] != ws_list[3], "work stations should alternate")

        #
        # scenario: station x -> station y (reject) -> station x
        #
        order = create_test_order()
        first_ws = choose_workstation(order)
        second_ws = choose_workstation(order)

        assignment = OrderAssignment(order=order, station=second_ws.station, work_station=second_ws, status=REJECTED)
        assignment.save()
        refresh_order(order)

        third_ws = choose_workstation(order)

        self.assertTrue(third_ws.station == first_ws.station)

        #
        # scenario: station x -> station y (not taken) -> station x -> station y other ws
        #
        order = create_test_order()
        first_ws = choose_workstation(order)
        second_ws = choose_workstation(order)

        assignment = OrderAssignment(order=order, station=second_ws.station, work_station=second_ws, status=NOT_TAKEN)
        assignment.save()

        third_ws = choose_workstation(order)
        fourth_ws = choose_workstation(order)

        self.assertTrue(second_ws.station == fourth_ws.station and second_ws != fourth_ws)