From a9d0c69d46d27b40ea90c1e90541c9c74bea6a10 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Mon, 22 Jan 2024 10:30:37 -0500 Subject: [PATCH] more-tests --- .../authorized_storage_account/models.py | 2 +- .../configured_storage_addon/models.py | 4 ++-- .../configured_storage_addon/serializers.py | 15 ++++++++------- .../management/commands/fill_garbage.py | 4 ++-- addon_service/migrations/0001_initial.py | 4 ++-- addon_service/tests/_factories.py | 4 ++-- addon_service/tests/test_base.py | 15 --------------- addon_service/tests/test_by_type/__init__.py | 0 .../test_authorized_storage_account.py | 5 ++--- .../test_configured_storage_addon.py | 19 ++++++++++++++----- .../test_external_storage_service.py | 1 - .../test_internal_resource.py | 5 ++--- .../{ => test_by_type}/test_internal_user.py | 1 - 13 files changed, 35 insertions(+), 44 deletions(-) delete mode 100644 addon_service/tests/test_base.py create mode 100644 addon_service/tests/test_by_type/__init__.py rename addon_service/tests/{ => test_by_type}/test_authorized_storage_account.py (97%) rename addon_service/tests/{ => test_by_type}/test_configured_storage_addon.py (90%) rename addon_service/tests/{ => test_by_type}/test_external_storage_service.py (99%) rename addon_service/tests/{ => test_by_type}/test_internal_resource.py (98%) rename addon_service/tests/{ => test_by_type}/test_internal_user.py (99%) diff --git a/addon_service/authorized_storage_account/models.py b/addon_service/authorized_storage_account/models.py index 7ada099e..f4b4b6a1 100644 --- a/addon_service/authorized_storage_account/models.py +++ b/addon_service/authorized_storage_account/models.py @@ -5,7 +5,7 @@ class AuthorizedStorageAccount(AddonsServiceBaseModel): - # TODO: capabilities = ArrayField(...) + # TODO: authorized_capabilities = ArrayField(...) default_root_folder = models.CharField(blank=True) external_storage_service = models.ForeignKey( diff --git a/addon_service/configured_storage_addon/models.py b/addon_service/configured_storage_addon/models.py index f1c68fa4..dd1a8131 100644 --- a/addon_service/configured_storage_addon/models.py +++ b/addon_service/configured_storage_addon/models.py @@ -6,12 +6,12 @@ class ConfiguredStorageAddon(AddonsServiceBaseModel): root_folder = models.CharField() - authorized_storage_account = models.ForeignKey( + base_account = models.ForeignKey( "addon_service.AuthorizedStorageAccount", on_delete=models.CASCADE, related_name="configured_storage_addons", ) - internal_resource = models.ForeignKey( + authorized_resource = models.ForeignKey( "addon_service.InternalResource", on_delete=models.CASCADE, related_name="configured_storage_addons", diff --git a/addon_service/configured_storage_addon/serializers.py b/addon_service/configured_storage_addon/serializers.py index 832be36a..e5c63902 100644 --- a/addon_service/configured_storage_addon/serializers.py +++ b/addon_service/configured_storage_addon/serializers.py @@ -3,6 +3,7 @@ from rest_framework_json_api.utils import get_resource_type_from_model from addon_service.models import ( + AuthorizedStorageAccount, ConfiguredStorageAddon, InternalResource, ) @@ -13,22 +14,22 @@ class ConfiguredStorageAddonSerializer(serializers.HyperlinkedModelSerializer): url = serializers.HyperlinkedIdentityField(view_name=f"{RESOURCE_NAME}-detail") - authorized_storage_account = ResourceRelatedField( - queryset=ConfiguredStorageAddon.objects.all(), + base_account = ResourceRelatedField( + queryset=AuthorizedStorageAccount.objects.all(), many=False, related_link_view_name=f"{RESOURCE_NAME}-related", ) - internal_resource = ResourceRelatedField( + authorized_resource = ResourceRelatedField( queryset=InternalResource.objects.all(), many=False, related_link_view_name=f"{RESOURCE_NAME}-related", ) included_serializers = { - "authorized_storage_account": ( + "base_account": ( "addon_service.serializers.AuthorizedStorageAccountSerializer" ), - "internal_resource": "addon_service.serializers.InternalResourceSerializer", + "authorized_resource": "addon_service.serializers.InternalResourceSerializer", } class Meta: @@ -36,6 +37,6 @@ class Meta: fields = [ "url", "root_folder", - "authorized_storage_account", - "internal_resource", + "base_account", + "authorized_resource", ] diff --git a/addon_service/management/commands/fill_garbage.py b/addon_service/management/commands/fill_garbage.py index 9aa7e8c4..a918b532 100644 --- a/addon_service/management/commands/fill_garbage.py +++ b/addon_service/management/commands/fill_garbage.py @@ -41,7 +41,7 @@ def handle_label(self, label, **options): resource_uri=f"http://osf.example/r{label}{_j}", ) _csa = db.ConfiguredStorageAddon.objects.create( - authorized_storage_account=_asa, - internal_resource=_ir, + base_account=_asa, + authorized_resource=_ir, ) return str(_csa) diff --git a/addon_service/migrations/0001_initial.py b/addon_service/migrations/0001_initial.py index 66b8547f..6d5f8334 100644 --- a/addon_service/migrations/0001_initial.py +++ b/addon_service/migrations/0001_initial.py @@ -215,7 +215,7 @@ class Migration(migrations.Migration): ("modified", models.DateTimeField()), ("root_folder", models.CharField()), ( - "authorized_storage_account", + "base_account", models.ForeignKey( on_delete=django.db.models.deletion.CASCADE, related_name="configured_storage_addons", @@ -223,7 +223,7 @@ class Migration(migrations.Migration): ), ), ( - "internal_resource", + "authorized_resource", models.ForeignKey( on_delete=django.db.models.deletion.CASCADE, related_name="configured_storage_addons", diff --git a/addon_service/tests/_factories.py b/addon_service/tests/_factories.py index 1be76fa4..5b0b5610 100644 --- a/addon_service/tests/_factories.py +++ b/addon_service/tests/_factories.py @@ -70,5 +70,5 @@ class Meta: model = db.ConfiguredStorageAddon root_folder = "/" - authorized_storage_account = factory.SubFactory(AuthorizedStorageAccountFactory) - internal_resource = factory.SubFactory(InternalResourceFactory) + base_account = factory.SubFactory(AuthorizedStorageAccountFactory) + authorized_resource = factory.SubFactory(InternalResourceFactory) diff --git a/addon_service/tests/test_base.py b/addon_service/tests/test_base.py deleted file mode 100644 index 59b87a29..00000000 --- a/addon_service/tests/test_base.py +++ /dev/null @@ -1,15 +0,0 @@ -from django.test import TestCase - -from ._factories import InternalUserFactory - - -class TestTestCase(TestCase): - def test_tests(self): - """Simple base test to test test infrastructure""" - pass - - def test_model(self): - """Simple base test to test test models""" - user = InternalUserFactory(user_uri="http://osf.example/hurts") - user.save() - self.assertEqual(user.user_uri, "http://osf.example/hurts") diff --git a/addon_service/tests/test_by_type/__init__.py b/addon_service/tests/test_by_type/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/addon_service/tests/test_authorized_storage_account.py b/addon_service/tests/test_by_type/test_authorized_storage_account.py similarity index 97% rename from addon_service/tests/test_authorized_storage_account.py rename to addon_service/tests/test_by_type/test_authorized_storage_account.py index 2780f46b..1c5b5406 100644 --- a/addon_service/tests/test_authorized_storage_account.py +++ b/addon_service/tests/test_by_type/test_authorized_storage_account.py @@ -14,7 +14,6 @@ from addon_service.tests._helpers import get_test_request -# smoke-test api class TestAuthorizedStorageAccountAPI(APITestCase): @classmethod def setUpTestData(cls): @@ -84,7 +83,7 @@ def test_configured_storage_addons__several(self): _accounts = set( _factories.ConfiguredStorageAddonFactory.create_batch( size=3, - authorized_storage_account=self._asa, + base_account=self._asa, ) ) self.assertEqual( @@ -157,7 +156,7 @@ def test_get_related__empty(self): def test_get_related__several(self): _addons = _factories.ConfiguredStorageAddonFactory.create_batch( size=5, - authorized_storage_account=self._asa, + base_account=self._asa, ) _resp = self._related_view( get_test_request(), diff --git a/addon_service/tests/test_configured_storage_addon.py b/addon_service/tests/test_by_type/test_configured_storage_addon.py similarity index 90% rename from addon_service/tests/test_configured_storage_addon.py rename to addon_service/tests/test_by_type/test_configured_storage_addon.py index d351d163..cecbe897 100644 --- a/addon_service/tests/test_configured_storage_addon.py +++ b/addon_service/tests/test_by_type/test_configured_storage_addon.py @@ -12,7 +12,6 @@ from addon_service.tests._helpers import get_test_request -# smoke-test api class TestConfiguredStorageAddonAPI(APITestCase): @classmethod def setUpTestData(cls): @@ -78,7 +77,13 @@ class TestConfiguredStorageAddonViewSet(TestCase): @classmethod def setUpTestData(cls): cls._csa = _factories.ConfiguredStorageAddonFactory() - cls._view = ConfiguredStorageAddonViewSet.as_view({"get": "retrieve"}) + cls._view = ConfiguredStorageAddonViewSet.as_view( + { + "post": "create", + "get": "retrieve", + "patch": "update", + } + ) def test_get(self): _resp = self._view( @@ -96,8 +101,8 @@ def test_get(self): self.assertEqual( set(_content["data"]["relationships"].keys()), { - "authorized_storage_account", - "internal_resource", + "base_account", + "authorized_resource", }, ) @@ -115,6 +120,10 @@ def test_wrong_user(self): ) self.assertEqual(_resp.status_code, HTTPStatus.FORBIDDEN) + # def test_create(self): + # _post_req = get_test_request(user=self._user, method='post') + # self._view(_post_req, pk= + class TestConfiguredStorageAddonRelatedView(TestCase): @classmethod @@ -128,7 +137,7 @@ def test_get_related(self): _resp = self._related_view( get_test_request(), pk=self._csa.pk, - related_field="authorized_storage_account", + related_field="base_account", ) self.assertEqual(_resp.status_code, HTTPStatus.OK) _content = json.loads(_resp.rendered_content) diff --git a/addon_service/tests/test_external_storage_service.py b/addon_service/tests/test_by_type/test_external_storage_service.py similarity index 99% rename from addon_service/tests/test_external_storage_service.py rename to addon_service/tests/test_by_type/test_external_storage_service.py index e8f09a09..f603cde5 100644 --- a/addon_service/tests/test_external_storage_service.py +++ b/addon_service/tests/test_by_type/test_external_storage_service.py @@ -13,7 +13,6 @@ from addon_service.tests._helpers import get_test_request -# smoke-test api class TestExternalStorageServiceAPI(APITestCase): @classmethod def setUpTestData(cls): diff --git a/addon_service/tests/test_internal_resource.py b/addon_service/tests/test_by_type/test_internal_resource.py similarity index 98% rename from addon_service/tests/test_internal_resource.py rename to addon_service/tests/test_by_type/test_internal_resource.py index a65db681..6b4f303d 100644 --- a/addon_service/tests/test_internal_resource.py +++ b/addon_service/tests/test_by_type/test_internal_resource.py @@ -13,7 +13,6 @@ from addon_service.tests._helpers import get_test_request -# smoke-test api class TestInternalResourceAPI(APITestCase): @classmethod def setUpTestData(cls): @@ -76,7 +75,7 @@ def test_configured_storage_addons__several(self): _accounts = set( _factories.ConfiguredStorageAddonFactory.create_batch( size=3, - internal_resource=self._resource, + authorized_resource=self._resource, ) ) self.assertEqual( @@ -152,7 +151,7 @@ def test_get_related__empty(self): def test_get_related__several(self): _addons = _factories.ConfiguredStorageAddonFactory.create_batch( size=5, - internal_resource=self._resource, + authorized_resource=self._resource, ) _resp = self._related_view( get_test_request(), diff --git a/addon_service/tests/test_internal_user.py b/addon_service/tests/test_by_type/test_internal_user.py similarity index 99% rename from addon_service/tests/test_internal_user.py rename to addon_service/tests/test_by_type/test_internal_user.py index 34eb354e..f2de9195 100644 --- a/addon_service/tests/test_internal_user.py +++ b/addon_service/tests/test_by_type/test_internal_user.py @@ -14,7 +14,6 @@ from addon_service.tests._helpers import get_test_request -# smoke-test api class TestInternalUserAPI(APITestCase): @classmethod def setUpTestData(cls):