def test_get_cases_for_date_fail(self, mock):
        """
        Fails if the date is in the wrong format
        """
        itinerary = Itinerary.objects.create()
        itinerary.add_case("FOO_CASE_ID_A")

        with self.assertRaises(ValidationError):
            Itinerary.get_cases_for_date("fooo")
    def test_get_unplanned_cases_empty(self, mock_get_cases_from_bwv, mock):
        """
        Should return all cases for another date
        """
        FOO_CASE_ID_A = "FOO_CASE_ID_A"
        FOO_CASE_ID_B = "FOO_CASE_ID_B"
        FOO_CASE_ID_C = "FOO_CASE_ID_C"
        FOO_CASE_ID_D = "FOO_CASE_ID_D"

        itinerary = Itinerary.objects.create()
        itinerary.add_case(FOO_CASE_ID_A)
        itinerary.add_case(FOO_CASE_ID_B)

        itinerary = Itinerary.objects.create()
        itinerary.add_case(FOO_CASE_ID_C)

        all_cases = [
            {
                "id": FOO_CASE_ID_A
            },
            {
                "id": FOO_CASE_ID_B
            },
            {
                "id": FOO_CASE_ID_C
            },
            {
                "id": FOO_CASE_ID_D
            },
        ]
        # Mock the results from the BWV query
        mock_get_cases_from_bwv.return_value = all_cases

        cases = Itinerary.get_unplanned_cases("2018-01-01", "FOO_STADIUM", [])
        self.assertEquals(cases, all_cases)
예제 #3
0
    def unplanned(self, request):
        """ Returns a list of unplanned cases, based on the given date and stadium """
        serializer = UnplannedCasesSerializer(data=request.GET)
        is_valid = serializer.is_valid()

        if not is_valid:
            return JsonResponse(
                {"message": "Could not validate data", "errors": serializer.errors},
                status=HttpResponseBadRequest.status_code,
            )

        date = request.GET.get("date")
        stadium = request.GET.get("stadium")
        itinerary = Itinerary.objects.filter(id=request.GET.get("itinerary_id"))
        projects = (
            list(
                itinerary.first()
                .settings.day_settings.team_settings.project_choices.all()
                .values_list("name", flat=True)
            )
            if itinerary
            else list(Project.objects.all().values_list("name", flat=True))
        )

        unplanned_cases = Itinerary.get_unplanned_cases(date, stadium, projects)
        cases = add_fraud_predictions(unplanned_cases)

        return JsonResponse({"cases": cases})
    def test_get_cases_for_date_empty(self, mock):
        """
        Should return cases which are in itineraries for the given date
        """
        itinerary = Itinerary.objects.create()
        itinerary.add_case("FOO_CASE_ID_A")
        itinerary.add_case("FOO_CASE_ID_B")

        itinerary = Itinerary.objects.create()
        itinerary.add_case("FOO_CASE_ID_C")

        # Get cases for another date
        cases = Itinerary.get_cases_for_date("2018-10-20")
        self.assertEquals(cases, [])
    def test_get_cases_for_date(self, mock):
        """
        Should return cases which are in itineraries for the given date
        """
        itinerary = Itinerary.objects.create()
        itinerary.add_case("FOO_CASE_ID_A")
        itinerary.add_case("FOO_CASE_ID_B")

        itinerary = Itinerary.objects.create()
        itinerary.add_case("FOO_CASE_ID_C")

        cases = Itinerary.get_cases_for_date("2019-12-25")
        cases_expected = [
            Case.get("FOO_CASE_ID_A"),
            Case.get("FOO_CASE_ID_B"),
            Case.get("FOO_CASE_ID_C"),
        ]
        self.assertEquals(cases, cases_expected)
    def test_get_unplanned_cases(self, mock_get_cases_from_bwv, mock):
        """
        Should return cases which are in itineraries for the given date
        """
        FOO_CASE_ID_A = "FOO_CASE_ID_A"
        FOO_CASE_ID_B = "FOO_CASE_ID_B"
        FOO_CASE_ID_C = "FOO_CASE_ID_C"
        FOO_CASE_ID_D = "FOO_CASE_ID_D"

        itinerary = Itinerary.objects.create()
        itinerary.add_case(FOO_CASE_ID_A)
        itinerary.add_case(FOO_CASE_ID_B)

        itinerary = Itinerary.objects.create()
        itinerary.add_case(FOO_CASE_ID_C)

        all_cases = [
            {
                "id": FOO_CASE_ID_A
            },
            {
                "id": FOO_CASE_ID_B
            },
            {
                "id": FOO_CASE_ID_C
            },
            {
                "id": FOO_CASE_ID_D
            },
        ]
        # Mock the results from the BWV query
        mock_get_cases_from_bwv.return_value = all_cases

        cases = Itinerary.get_unplanned_cases("2019-12-25", "FOO_STADIUM", [])
        # Should only return the unplanned FOO_CASE_ID_D
        self.assertEquals(cases, [{"id": FOO_CASE_ID_D}])