Skip to content

Commit

Permalink
test organization
Browse files Browse the repository at this point in the history
and a few field renames
  • Loading branch information
aaxelb committed Jan 22, 2024
1 parent d3828b7 commit bceae6b
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 45 deletions.
2 changes: 1 addition & 1 deletion addon_service/authorized_storage_account/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions addon_service/configured_storage_addon/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 8 additions & 7 deletions addon_service/configured_storage_addon/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from rest_framework_json_api.utils import get_resource_type_from_model

from addon_service.models import (
AuthorizedStorageAccount,
ConfiguredStorageAddon,
InternalResource,
)
Expand All @@ -13,29 +14,29 @@

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:
model = ConfiguredStorageAddon
fields = [
"url",
"root_folder",
"authorized_storage_account",
"internal_resource",
"base_account",
"authorized_resource",
]
4 changes: 2 additions & 2 deletions addon_service/management/commands/fill_garbage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions addon_service/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,15 @@ 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",
to="addon_service.authorizedstorageaccount",
),
),
(
"internal_resource",
"authorized_resource",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="configured_storage_addons",
Expand Down
4 changes: 2 additions & 2 deletions addon_service/tests/_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
15 changes: 0 additions & 15 deletions addon_service/tests/test_base.py

This file was deleted.

Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from addon_service.tests._helpers import get_test_request


# smoke-test api
class TestAuthorizedStorageAccountAPI(APITestCase):
@classmethod
def setUpTestData(cls):
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from addon_service.tests._helpers import get_test_request


# smoke-test api
class TestConfiguredStorageAddonAPI(APITestCase):
@classmethod
def setUpTestData(cls):
Expand Down Expand Up @@ -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(
Expand All @@ -96,8 +101,8 @@ def test_get(self):
self.assertEqual(
set(_content["data"]["relationships"].keys()),
{
"authorized_storage_account",
"internal_resource",
"base_account",
"authorized_resource",
},
)

Expand All @@ -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
Expand All @@ -128,11 +137,11 @@ 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)
self.assertEqual(
_content["data"]["id"],
str(self._csa.authorized_storage_account_id),
str(self._csa.base_account_id),
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from addon_service.tests._helpers import get_test_request


# smoke-test api
class TestExternalStorageServiceAPI(APITestCase):
@classmethod
def setUpTestData(cls):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from addon_service.tests._helpers import get_test_request


# smoke-test api
class TestInternalResourceAPI(APITestCase):
@classmethod
def setUpTestData(cls):
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from addon_service.tests._helpers import get_test_request


# smoke-test api
class TestInternalUserAPI(APITestCase):
@classmethod
def setUpTestData(cls):
Expand Down

0 comments on commit bceae6b

Please sign in to comment.