Skip to content

Commit

Permalink
Merge pull request #272 from maykinmedia/issue/admin-add-permission-w…
Browse files Browse the repository at this point in the history
…ithout-properties

Issue/admin add permission without properties
  • Loading branch information
annashamray committed Dec 14, 2021
2 parents 4d9f719 + b1bde31 commit 450be70
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/objects/conf/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@

if "test" in sys.argv:
NOTIFICATIONS_DISABLED = True
TWO_FACTOR_PATCH_ADMIN = False
TWO_FACTOR_FORCE_OTP_ADMIN = False

# Override settings with local settings.
try:
Expand Down
Empty file.
45 changes: 45 additions & 0 deletions src/objects/tests/admin/test_token_permissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from django.urls import reverse_lazy

from django_webtest import WebTest
from requests_mock import Mocker

from objects.accounts.tests.factories import UserFactory
from objects.token.tests.factories import ObjectTypeFactory, TokenAuthFactory

from ..utils import mock_objecttype, mock_objecttype_version, mock_service_oas_get

OBJECT_TYPES_API = "https://example.com/objecttypes/v1/"


class AddPermissionTests(WebTest):
url = reverse_lazy("admin:token_permission_add")

@Mocker()
def test_add_permission_choices_without_properties(self, m):
user = UserFactory(is_superuser=True, is_staff=True)
self.app.set_user(user)
object_type = ObjectTypeFactory.create(service__api_root=OBJECT_TYPES_API)
TokenAuthFactory.create()

# mock objecttypes api
mock_service_oas_get(m, OBJECT_TYPES_API, "objecttypes")
m.get(object_type.url, json=mock_objecttype(object_type.url))
version1 = mock_objecttype_version(object_type.url, attrs={"jsonSchema": {}})
version2 = mock_objecttype_version(object_type.url, attrs={"version": 2})
m.get(f"{object_type.url}/versions", json=[version1, version2])

response = self.app.get(self.url)

self.assertEqual(response.status_code, 200)
self.assertEqual(
response.context["data_field_choices"],
{
object_type.id: {
1: {},
2: {
"diameter": "record__data__diameter",
"plantDate": "record__data__plantDate",
},
}
},
)
2 changes: 1 addition & 1 deletion src/objects/token/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_data_field_choices(self):
data_fields[object_type.id] = {
version["version"]: {
prop: f"record__data__{prop}"
for prop in list(version["jsonSchema"]["properties"].keys())
for prop in list(version["jsonSchema"].get("properties", {}).keys())
}
for version in response
}
Expand Down

0 comments on commit 450be70

Please sign in to comment.