-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #272 from maykinmedia/issue/admin-add-permission-w…
…ithout-properties Issue/admin add permission without properties
- Loading branch information
Showing
4 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}, | ||
} | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters