From ce093d16bd52a82a016feca3d0c4bb6f3c0e36e5 Mon Sep 17 00:00:00 2001 From: Drew Shafer Date: Mon, 8 Jun 2020 17:56:50 -0500 Subject: [PATCH] black --- .../machinery/filtering.py | 5 +- tests/filters.py | 12 +++-- tests/test_filters.py | 46 +++++++++++-------- 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/django_declarative_apis/machinery/filtering.py b/django_declarative_apis/machinery/filtering.py index 31f5f42..06b8075 100644 --- a/django_declarative_apis/machinery/filtering.py +++ b/django_declarative_apis/machinery/filtering.py @@ -42,10 +42,11 @@ def _get_unexpanded_field_value(inst, field_name, field_type): if not field_type.model_class: return DEFAULT_UNEXPANDED_VALUE - display_key = field_type.display_key or field_type.model_class._meta.pk.name inst_field_name = field_type.inst_field_name or field_name - is_multiple = isinstance(inst.__class__._meta.get_field(inst_field_name), ManyToOneRel) + is_multiple = isinstance( + inst.__class__._meta.get_field(inst_field_name), ManyToOneRel + ) if is_multiple: # special case for keys that have multiple values (for instance, inverse fk relations) diff --git a/tests/filters.py b/tests/filters.py index 6f35db5..3024ec2 100644 --- a/tests/filters.py +++ b/tests/filters.py @@ -45,8 +45,8 @@ models.TestModel: { "pk": ALWAYS, "int_field": ALWAYS, - "renamed_expandable_dict": expandable(inst_field_name='expandable_dict'), - "renamed_expandable_string": expandable(inst_field_name='expandable_string'), + "renamed_expandable_dict": expandable(inst_field_name="expandable_dict"), + "renamed_expandable_string": expandable(inst_field_name="expandable_string"), }, models.ParentModel: { "nonstandard_id": ALWAYS, @@ -56,9 +56,13 @@ }, models.ChildModel: { "pk": ALWAYS, - "renamed_test": expandable(model_class=models.TestModel, inst_field_name='test'), + "renamed_test": expandable( + model_class=models.TestModel, inst_field_name="test" + ), "name": ALWAYS, - "renamed_parent": expandable(model_class=models.ParentModel, inst_field_name='parent'), + "renamed_parent": expandable( + model_class=models.ParentModel, inst_field_name="parent" + ), }, } diff --git a/tests/test_filters.py b/tests/test_filters.py index d31d1f4..2472840 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -186,31 +186,39 @@ def test_rename_expandable_foreign_key(self): self.p1c1, filters.RENAMED_EXPANDABLE_MODEL_FIELDS ) - self.assertEqual(filtered['renamed_test'], {'id': self.p1c1.test.pk}) - self.assertEqual(filtered['renamed_parent'], {'nonstandard_id': self.p1c1.parent.pk}) + self.assertEqual(filtered["renamed_test"], {"id": self.p1c1.test.pk}) + self.assertEqual( + filtered["renamed_parent"], {"nonstandard_id": self.p1c1.parent.pk} + ) filtered = filtering.apply_filters_to_object( - self.p1c1, filters.RENAMED_EXPANDABLE_MODEL_FIELDS, - expand_header='renamed_test,renamed_parent' + self.p1c1, + filters.RENAMED_EXPANDABLE_MODEL_FIELDS, + expand_header="renamed_test,renamed_parent", ) - self.assertTrue(2, len(filtered['renamed_test'])) - self.assertIn('int_field', filtered['renamed_test']) - self.assertNotIn('renamed_expandable_dict', filtered['renamed_test']) - self.assertTrue(4, len(filtered['renamed_parent'])) + self.assertTrue(2, len(filtered["renamed_test"])) + self.assertIn("int_field", filtered["renamed_test"]) + self.assertNotIn("renamed_expandable_dict", filtered["renamed_test"]) + self.assertTrue(4, len(filtered["renamed_parent"])) filtered = filtering.apply_filters_to_object( - self.p1c1, filters.RENAMED_EXPANDABLE_MODEL_FIELDS, - expand_header='renamed_test,renamed_test.renamed_expandable_dict' + self.p1c1, + filters.RENAMED_EXPANDABLE_MODEL_FIELDS, + expand_header="renamed_test,renamed_test.renamed_expandable_dict", + ) + self.assertTrue(3, len(filtered["renamed_test"])) + self.assertIn("renamed_expandable_dict", filtered["renamed_test"]) + self.assertEqual( + self.test_model.expandable_dict, + filtered["renamed_test"]["renamed_expandable_dict"], ) - self.assertTrue(3, len(filtered['renamed_test'])) - self.assertIn('renamed_expandable_dict', filtered['renamed_test']) - self.assertEqual(self.test_model.expandable_dict, filtered['renamed_test']['renamed_expandable_dict']) - self.assertNotIn('renamed_expandable_string', filtered['renamed_test']) + self.assertNotIn("renamed_expandable_string", filtered["renamed_test"]) filtered = filtering.apply_filters_to_object( - self.p1c1, filters.RENAMED_EXPANDABLE_MODEL_FIELDS, - expand_header='renamed_test,renamed_test.renamed_expandable_dict,renamed_test.renamed_expandable_string' + self.p1c1, + filters.RENAMED_EXPANDABLE_MODEL_FIELDS, + expand_header="renamed_test,renamed_test.renamed_expandable_dict,renamed_test.renamed_expandable_string", ) - self.assertTrue(4, len(filtered['renamed_test'])) - self.assertIn('renamed_expandable_dict', filtered['renamed_test']) - self.assertIn('renamed_expandable_string', filtered['renamed_test']) + self.assertTrue(4, len(filtered["renamed_test"])) + self.assertIn("renamed_expandable_dict", filtered["renamed_test"]) + self.assertIn("renamed_expandable_string", filtered["renamed_test"])