Skip to content

Commit

Permalink
Merge pull request #767 from Amsterdam/filter_fuzy_street
Browse files Browse the repository at this point in the history
Query address fuzzy on case filter
  • Loading branch information
mguikema authored Jan 25, 2022
2 parents 8f91926 + d30f790 commit 5e57fcb
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 161 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- run: python3.9 -m pip install -r requirements.txt
working-directory: e2e-tests

- run: API_HOST=http://127.0.0.1:8080/api/v1 LOGLEVEL=INFO python3.9 -m unittest
- run: API_HOST=http://127.0.0.1:8080/api/v1 python3.9 -m unittest
working-directory: e2e-tests

###################################################
Expand Down
26 changes: 14 additions & 12 deletions app/apps/cases/tests/tests_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,9 @@ def test_authenticated_post_create(self):
url,
{
"description": "Foo",
"theme": theme.pk,
"reason": reason.pk,
"address": {"bag_id": "foo bag ID"},
"theme_id": theme.pk,
"reason_id": reason.pk,
"bag_id": "foo bag ID",
},
format="json",
)
Expand All @@ -359,9 +359,9 @@ def test_authenticated_post_create_fail_wrong_theme(self):
url,
{
"description": "Foo",
"theme": 10,
"reason": reason.pk,
"address": {"bag_id": "foo bag ID"},
"theme_id": 10,
"reason_id": reason.pk,
"bag_id": "foo bag ID",
},
format="json",
)
Expand Down Expand Up @@ -403,9 +403,9 @@ def test_authenticated_post_create_wrong_theme_reason_relation(self):
url,
{
"description": "Foo",
"theme": theme_b.pk,
"reason": reason.pk,
"address": {"bag_id": "foo bag ID"},
"theme_id": theme_b.pk,
"reason_id": reason.pk,
"bag_id": "foo bag ID",
},
format="json",
)
Expand All @@ -428,14 +428,16 @@ def test_authenticated_post_create_author(self):
url,
{
"description": "Foo",
"theme": theme.pk,
"reason": reason.pk,
"address": {"bag_id": "foo bag ID"},
"theme_id": theme.pk,
"reason_id": reason.pk,
"bag_id": "foo bag ID",
},
format="json",
)

test_user = get_test_user()
print("test_authenticated_post_create_author")
print(response.data)
case = Case.objects.get(id=response.data["id"])

self.assertEquals(case.author, test_user)
Expand Down
10 changes: 5 additions & 5 deletions app/apps/cases/tests/tests_models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import date, datetime, timezone
from datetime import date
from uuid import UUID

from apps.cases.models import Case, CaseReason, CaseState, CaseStateType, CaseTheme
Expand Down Expand Up @@ -134,15 +134,15 @@ def test_create_case_has_valid_automatic_identification(self):
def test_auto_start_date(self):
""" If a start data isn't specified, it should be set to the current time """
case = baker.make(Case)
self.assertEquals(case.start_date, datetime(2019, 12, 25, tzinfo=timezone.utc))
self.assertEquals(case.start_date, date(2019, 12, 25))

@freeze_time("2019-12-25")
def test_set_start_date(self):
""" If a start data is specified, it should be set to correctly """
date = datetime(2020, 1, 1, tzinfo=timezone.utc)
case = baker.make(Case, start_date=date)
start_date = date(2020, 1, 1)
case = baker.make(Case, start_date=start_date)

self.assertEquals(case.start_date, date)
self.assertEquals(case.start_date, start_date)

def test_set_state(self):
""" set_state function creates a state with the given name """
Expand Down
23 changes: 23 additions & 0 deletions app/apps/cases/views/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
StartWorkflowSerializer,
WorkflowOptionSerializer,
)
from django.db.models import Q
from django.shortcuts import get_object_or_404
from django_filters import rest_framework as filters
from drf_spectacular.types import OpenApiTypes
Expand All @@ -35,10 +36,28 @@ class CaseFilter(filters.FilterSet):
queryset=CaseStateType.objects.all(), method="get_state_types"
)
ton_ids = CharArrayFilter(field_name="ton_ids", lookup_expr="contains")
street_name = filters.CharFilter(method="get_fuzy_street_name")
number = filters.CharFilter(method="get_number")
suffix = filters.CharFilter(method="get_suffix")
postal_code = filters.CharFilter(method="get_postal_code")

def get_fuzy_street_name(self, queryset, name, value):
return queryset.filter(address__street_name__trigram_similar=value)

def get_number(self, queryset, name, value):
return queryset.filter(address__number=value)

def get_suffix(self, queryset, name, value):
return queryset.filter(
Q(address__suffix__iexact=value) | Q(address_suffix_letter__iexact=value)
)

def get_open_cases(self, queryset, name, value):
return queryset.filter(end_date__isnull=value)

def get_postal_code(self, queryset, name, value):
return queryset.filter(address__postal_code__iexact=value.replace(" ", ""))

def get_state_types(self, queryset, name, value):
if value:
return queryset.filter(
Expand All @@ -55,6 +74,10 @@ class Meta:
"reason",
"sensitive",
"ton_ids",
"street_name",
"number",
"suffix",
"postal_code",
]


Expand Down
57 changes: 7 additions & 50 deletions app/apps/workflow/user_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,73 +390,30 @@ class task_afwachten_casus_overleg(user_task):
_task_name = "task_afwachten_casus_overleg"
due_date = relativedelta(weeks=1)


class task_sub_workflow_opstellen_digitale_analyse(user_task):
due_date = relativedelta(days=3)


class task_opstelllen_rapport_van_bevindingen_1(user_task):
due_date = relativedelta(days=3)


class task_create_picture_rapport_1(user_task):
due_date = relativedelta(days=3)


class task_opstellen_digitale_analyse(user_task):
due_date = relativedelta(days=3)


class task_create_picture_rapport_2(user_task):
due_date = relativedelta(days=3)


class task_opstelllen_rapport_van_bevindingen_2(user_task):
due_date = relativedelta(days=3)


class task_opstellen_verzoek_tot_inlichtingen(user_task):
due_date = relativedelta(days=3)


# future tasks

# class x(user_task):
# """Opstellen intrekken besluit"""
# due_date = relativedelta(weeks=2)


# class x(user_task):
# """Nakijken intrekken besluit"""
# due_date = relativedelta(weeks=1)


# class x(user_task):
# """Verwerken intrekken besluit"""
# due_date = relativedelta(days=2)


# class x(user_task):
# """Intrekken invordering"""
# due_date = relativedelta(weeks=2)


# class x(user_task):
# """wobverzoek"""
# due_date = relativedelta(weeks=2)


################## Extra taken bij handhavingsverzoek???


# class x(user_task):
# """Afwijzen handhavingsverzoek (na toezicht)"""
# due_date = relativedelta(weeks=2)


# class x(user_task):
# """Opstellen aanvraag buiten behandeling laten"""
# due_date = relativedelta(weeks=2)


# class x(user_task):
# """Verwerken en opsturen brief"""
# due_date = relativedelta(days=2)


# class x(user_task):
# """Versturen ontvangstbevestiging"""
# due_date = relativedelta(weeks=1)
2 changes: 1 addition & 1 deletion e2e-tests/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def get_names_from_tasks(self, tasks):
def create_case(self, data):
events = [CaseEvent]

if "identification" in data and data["identification"]:
if "citizen_reports" in data and data["citizen_reports"]:
events.append(CitizenReportEvent)

return Case(
Expand Down
19 changes: 16 additions & 3 deletions e2e-tests/api/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,24 @@ def get_case_mock(
description_citizenreport=None,
identification=None,
):
return {
case_data = {
"theme_id": theme_id,
"reason_id": reason,
"bag_id": bag_id,
"subject_ids": subjects,
"description_citizenreport": description_citizenreport,
"identification": identification,
}

if identification:
case_data["citizen_reports"] = [
{
"identification": identification,
"reporter_name": "Arie",
"reporter_phone": "0612345678",
"reporter_email": "[email protected]",
"advertisement_linklist": [],
"description_citizenreport": description_citizenreport,
"nuisance": False,
}
]

return case_data
2 changes: 1 addition & 1 deletion e2e-tests/unittest.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ plugins = nose2.plugins.mp

[multiprocess]
always-on = True
processes = 3
processes = 12
32 changes: 0 additions & 32 deletions testing/README.md

This file was deleted.

56 changes: 0 additions & 56 deletions testing/api/client.py

This file was deleted.

0 comments on commit 5e57fcb

Please sign in to comment.