From eccd4f097ee147e9562b6846d993aef36654abd2 Mon Sep 17 00:00:00 2001 From: PonyM Date: Tue, 31 Jan 2023 14:29:12 +0100 Subject: [PATCH] Add nullable field description to analytics table --- caluma/caluma_analytics/filters.py | 9 ++---- .../0007_add_analytics_description_field.py | 28 +++++++++++++++++++ caluma/caluma_analytics/models.py | 1 + caluma/caluma_analytics/schema.py | 1 + caluma/caluma_analytics/serializers.py | 1 + caluma/caluma_analytics/tests/test_table.py | 24 +++++++++++++++- 6 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 caluma/caluma_analytics/migrations/0007_add_analytics_description_field.py diff --git a/caluma/caluma_analytics/filters.py b/caluma/caluma_analytics/filters.py index bcf71c88e..744d79276 100644 --- a/caluma/caluma_analytics/filters.py +++ b/caluma/caluma_analytics/filters.py @@ -6,15 +6,12 @@ class AnalyticsTableFilterSet(MetaFilterSet): - search = SearchFilter(fields=("slug", "name")) + search = SearchFilter(fields=("slug", "name", "description")) slugs = MultipleChoiceFilter(field_name="slug") class Meta: model = models.AnalyticsTable - fields = ( - "slug", - "name", - ) + fields = ("slug", "name", "description") class AnalyticsFieldFilterSet(MetaFilterSet): @@ -53,7 +50,7 @@ class AnalyticsTableOrderSet(FilterSet): meta = MetaFieldOrdering() attribute = AttributeOrderingFactory( models.AnalyticsTable, - fields=["created_at", "modified_at", "slug", "name"], + fields=["created_at", "modified_at", "slug", "name", "description"], ) class Meta: diff --git a/caluma/caluma_analytics/migrations/0007_add_analytics_description_field.py b/caluma/caluma_analytics/migrations/0007_add_analytics_description_field.py new file mode 100644 index 000000000..5195c8c64 --- /dev/null +++ b/caluma/caluma_analytics/migrations/0007_add_analytics_description_field.py @@ -0,0 +1,28 @@ +# Generated by Django 3.2.16 on 2023-01-31 09:25 + +from django.db import migrations +import localized_fields.fields.field + + +class Migration(migrations.Migration): + + dependencies = [ + ("caluma_analytics", "0006_rename_form_slug_fields"), + ] + + operations = [ + migrations.AddField( + model_name="analyticstable", + name="description", + field=localized_fields.fields.field.LocalizedField( + blank=True, null=True, required=[] + ), + ), + migrations.AddField( + model_name="historicalanalyticstable", + name="description", + field=localized_fields.fields.field.LocalizedField( + blank=True, null=True, required=[] + ), + ), + ] diff --git a/caluma/caluma_analytics/models.py b/caluma/caluma_analytics/models.py index 6ba941442..d67d3998a 100644 --- a/caluma/caluma_analytics/models.py +++ b/caluma/caluma_analytics/models.py @@ -15,6 +15,7 @@ class AnalyticsTable(SlugModel): disable_visibilities = models.BooleanField(default=False) name = LocalizedField(blank=False, null=False, required=False) + description = LocalizedField(blank=True, null=True, required=False) starting_object = models.CharField(max_length=250, choices=STARTING_OBJECT_CHOICES) diff --git a/caluma/caluma_analytics/schema.py b/caluma/caluma_analytics/schema.py index 5dbf28db0..d8eba1a8e 100644 --- a/caluma/caluma_analytics/schema.py +++ b/caluma/caluma_analytics/schema.py @@ -160,6 +160,7 @@ class Meta: "result_data", "fields", "name", + "description", "starting_object", ] diff --git a/caluma/caluma_analytics/serializers.py b/caluma/caluma_analytics/serializers.py index d5a4ebbc1..1351e3441 100644 --- a/caluma/caluma_analytics/serializers.py +++ b/caluma/caluma_analytics/serializers.py @@ -23,6 +23,7 @@ class Meta: fields = [ "slug", "name", + "description", "starting_object", "created_at", "modified_at", diff --git a/caluma/caluma_analytics/tests/test_table.py b/caluma/caluma_analytics/tests/test_table.py index 39a8a5171..2f0c7a8dd 100644 --- a/caluma/caluma_analytics/tests/test_table.py +++ b/caluma/caluma_analytics/tests/test_table.py @@ -63,6 +63,18 @@ } """ +QUERY_SEARCH_TABLE = """ + query($search: String!) { + allAnalyticsTables(filter: [{ search: $search }]) { + edges { + node { + slug + } + } + } + } +""" + def test_create_table(db, snapshot, schema_executor): result = schema_executor( @@ -71,15 +83,25 @@ def test_create_table(db, snapshot, schema_executor): "table_input": { "slug": "test-table", "name": "Test table thingy", + "description": "Foo bar", "startingObject": "CASES", } }, ) assert not result.errors - assert models.AnalyticsTable.objects.filter(pk="test-table").exists() + item = models.AnalyticsTable.objects.filter(pk="test-table").first() + assert str(item.description) == "Foo bar" snapshot.assert_match(result.data) + assert result.data["saveAnalyticsTable"]["analyticsTable"] + print(result.data) + + result = schema_executor(QUERY_SEARCH_TABLE, variable_values={"search": "bar Foo"}) + assert not result.errors + assert ( + len(result.data["allAnalyticsTables"]["edges"]) == 1 + ), "Search in description should work" @pytest.mark.parametrize(