Exemplo n.º 1
0
    def test_matching_postal_code(self):
        POSTAL_CODE = "1012GW"
        address = baker.make(Address, postal_code=POSTAL_CODE)

        results = search(postal_code=POSTAL_CODE)
        self.assertEquals(len(results), 1)
        self.assertEquals(results[0], address)
Exemplo n.º 2
0
    def test_matching_street_name(self):
        STREET_NAME = "Warmoesstraat"
        address = baker.make(Address, street_name=STREET_NAME)

        results = search(street_name=STREET_NAME)
        self.assertEquals(len(results), 1)
        self.assertEquals(results[0], address)
Exemplo n.º 3
0
    def test_similar_street_name(self):
        STREET_NAME = "Warmoesstraat"
        SIMILAR_STREET_NAME = "Warmosstraat"
        address = baker.make(Address, street_name=STREET_NAME)

        results = search(street_name=SIMILAR_STREET_NAME)
        self.assertEquals(len(results), 1)
        self.assertEquals(results[0], address)
Exemplo n.º 4
0
    def test_matching_postal_code_mid_space(self):
        POSTAL_CODE_CORRECT = "1012GW"
        POSTAL_CODE_SPACE = "1012 GW"
        address = baker.make(Address, postal_code=POSTAL_CODE_CORRECT)

        results = search(postal_code=POSTAL_CODE_SPACE)
        self.assertEquals(len(results), 1)
        self.assertEquals(results[0], address)
Exemplo n.º 5
0
    def test_matching_street_name_numer(self):
        STREET_NAME = "Warmoesstraat"
        address = baker.make(Address,
                             street_name=STREET_NAME,
                             number=1,
                             suffix="A")
        baker.make(Address, street_name=STREET_NAME, number=2, suffix="A")
        baker.make(Address, street_name=STREET_NAME, number=11, suffix="A")

        results = search(street_name=STREET_NAME, number=1, suffix="A")
        self.assertEquals(len(results), 1)
        self.assertEquals(results[0], address)
Exemplo n.º 6
0
    def test_matching_postal_code_number_suffix(self):
        POSTAL_CODE = "1012GW"
        SUFFIX = "A"

        address = baker.make(Address,
                             postal_code=POSTAL_CODE,
                             number=1,
                             suffix=SUFFIX)
        baker.make(Address, postal_code=POSTAL_CODE, number=2, suffix=SUFFIX)
        baker.make(Address, postal_code=POSTAL_CODE, number=3, suffix=SUFFIX)

        results = search(postal_code=POSTAL_CODE, number=1, suffix=SUFFIX)
        self.assertEquals(len(results), 1)
        self.assertEquals(results[0], address)
Exemplo n.º 7
0
    def search(self, request):
        postal_code = request.GET.get(postal_code_parameter.name, None)
        street_name = request.GET.get(street_name_parameter.name, None)
        number = request.GET.get(street_number_parameter.name, None)
        suffix = request.GET.get(suffix_parameter.name, None)
        team = request.GET.get(team_parameter.name, None)

        if postal_code is None and street_name is None:
            return HttpResponseBadRequest(
                "A postal_code or street_name queryparameter should be provided"
            )
        if postal_code is not None and number is None:
            return HttpResponseBadRequest("number queryparameter is required")
        if street_name is not None and number is None:
            return HttpResponseBadRequest("number queryparameter is required")

        address_queryset = search(
            street_name=street_name,
            postal_code=postal_code,
            number=number,
            suffix=suffix,
        )

        cases = Case.objects.none()
        for address in address_queryset:
            cases = cases | address.cases.all()

        cases = cases.filter(end_date=None)

        if team:
            cases = cases.filter(team=team)

        paginator = PageNumberPagination()
        context = paginator.paginate_queryset(cases, request)
        serializer = CaseSerializer(context, many=True)

        return paginator.get_paginated_response(serializer.data)
Exemplo n.º 8
0
    def test_multiple_similar_street_name(self):
        SIMILAR_STREET_NAMES = [
            "Warmosstraat",
            "Warmoesstrat",
            "Wamoesstraat",
            "Warmoestraat",
            "Warmeostraat",
            "aarmoestraat",
            "Warmoestraat",
        ]
        OTHER_STREET_NAMES = [
            "Elleboogsteeg",
            "Waterpoortsteeg",
            "Kogge­straat",
            "Ramskooi",
        ]

        STREET_NAMES = SIMILAR_STREET_NAMES + OTHER_STREET_NAMES

        for street_name in STREET_NAMES:
            baker.make(Address, street_name=street_name)

        results = search(street_name="Warmoesstraat")
        self.assertEquals(len(results), len(SIMILAR_STREET_NAMES))
Exemplo n.º 9
0
    def test_no_matching_postal_code(self):
        baker.make(Address, postal_code="1012GW")

        results = search(postal_code="Foo")
        self.assertEquals(len(results), 0)
Exemplo n.º 10
0
    def test_no_matching_street_name(self):
        baker.make(Address, street_name="Foo")

        results = search(street_name="Warmoesstraat")
        self.assertEquals(len(results), 0)
Exemplo n.º 11
0
 def test_no_results(self):
     results = search()
     self.assertEquals(len(results), 0)