-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
!43 fixes #6
- Loading branch information
Showing
5 changed files
with
399 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
app/settings/tests/unit/external_links/test_external_links.py
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,18 @@ | ||
import pytest | ||
import unittest | ||
import requests | ||
|
||
from django.test import TestCase, Client | ||
|
||
from app.tests.abstract.models import TenancyModel | ||
|
||
from settings.models.external_link import ExternalLink | ||
|
||
|
||
|
||
class ExternalLinkTests( | ||
TestCase, | ||
TenancyModel, | ||
): | ||
|
||
model = ExternalLink |
72 changes: 72 additions & 0 deletions
72
app/settings/tests/unit/external_links/test_external_links_core_history.py
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,72 @@ | ||
import pytest | ||
import unittest | ||
import requests | ||
|
||
from django.test import TestCase, Client | ||
|
||
from access.models import Organization | ||
|
||
from core.models.history import History | ||
from core.tests.abstract.history_entry import HistoryEntry | ||
from core.tests.abstract.history_entry_parent_model import HistoryEntryParentItem | ||
|
||
from settings.models.external_link import ExternalLink | ||
|
||
|
||
|
||
class ExternalLinkHistory(TestCase, HistoryEntry, HistoryEntryParentItem): | ||
|
||
model = ExternalLink | ||
|
||
|
||
@classmethod | ||
def setUpTestData(self): | ||
""" Setup Test """ | ||
|
||
organization = Organization.objects.create(name='test_org') | ||
|
||
self.organization = organization | ||
|
||
self.item_create = self.model.objects.create( | ||
name = 'test_item_' + self.model._meta.model_name , | ||
organization = self.organization | ||
) | ||
|
||
|
||
self.history_create = History.objects.get( | ||
action = History.Actions.ADD[0], | ||
item_pk = self.item_create.pk, | ||
item_class = self.model._meta.model_name, | ||
) | ||
|
||
|
||
self.item_change = self.item_create | ||
self.item_change.name = 'test_item_' + self.model._meta.model_name + '_changed' | ||
self.item_change.save() | ||
|
||
self.field_after_expected_value = '{"name": "test_item_' + self.model._meta.model_name + '_changed"}' | ||
|
||
self.history_change = History.objects.get( | ||
action = History.Actions.UPDATE[0], | ||
item_pk = self.item_change.pk, | ||
item_class = self.model._meta.model_name, | ||
) | ||
|
||
self.item_delete = self.model.objects.create( | ||
name = 'test_item_delete_' + self.model._meta.model_name , | ||
organization = self.organization | ||
) | ||
|
||
self.deleted_pk = self.item_delete.pk | ||
|
||
self.item_delete.delete() | ||
|
||
self.history_delete = History.objects.filter( | ||
item_pk = self.deleted_pk, | ||
item_class = self.model._meta.model_name, | ||
) | ||
|
||
self.history_delete_children = History.objects.filter( | ||
item_parent_pk = self.deleted_pk, | ||
item_parent_class = self.model._meta.model_name, | ||
) |
92 changes: 92 additions & 0 deletions
92
app/settings/tests/unit/external_links/test_external_links_history_permission.py
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,92 @@ | ||
import pytest | ||
import unittest | ||
import requests | ||
|
||
from django.contrib.auth.models import AnonymousUser, User | ||
from django.contrib.contenttypes.models import ContentType | ||
from django.test import TestCase | ||
|
||
from access.models import Organization, Team, TeamUsers, Permission | ||
|
||
from core.tests.abstract.history_permissions import HistoryPermissions | ||
|
||
from settings.models.external_link import ExternalLink | ||
|
||
|
||
|
||
class ExternalLinkHistoryPermissions(TestCase, HistoryPermissions): | ||
|
||
|
||
item_model = ExternalLink | ||
|
||
|
||
@classmethod | ||
def setUpTestData(self): | ||
"""Setup Test | ||
1. Create an organization for user and item | ||
2. create an organization that is different to item | ||
3. Create a device | ||
4. Add history device history entry as item | ||
5. create a user | ||
6. create user in different organization (with the required permission) | ||
""" | ||
|
||
organization = Organization.objects.create(name='test_org') | ||
|
||
self.organization = organization | ||
|
||
different_organization = Organization.objects.create(name='test_different_organization') | ||
|
||
self.item = self.item_model.objects.create( | ||
organization=organization, | ||
name = 'deviceone' | ||
) | ||
|
||
self.history = self.model.objects.get( | ||
item_pk = self.item.id, | ||
item_class = self.item._meta.model_name, | ||
action = self.model.Actions.ADD, | ||
) | ||
|
||
view_permissions = Permission.objects.get( | ||
codename = 'view_' + self.model._meta.model_name, | ||
content_type = ContentType.objects.get( | ||
app_label = self.model._meta.app_label, | ||
model = self.model._meta.model_name, | ||
) | ||
) | ||
|
||
view_team = Team.objects.create( | ||
team_name = 'view_team', | ||
organization = organization, | ||
) | ||
|
||
view_team.permissions.set([view_permissions]) | ||
|
||
|
||
self.no_permissions_user = User.objects.create_user(username="test_no_permissions", password="password") | ||
|
||
|
||
self.view_user = User.objects.create_user(username="test_user_view", password="password") | ||
teamuser = TeamUsers.objects.create( | ||
team = view_team, | ||
user = self.view_user | ||
) | ||
|
||
self.different_organization_user = User.objects.create_user(username="test_different_organization_user", password="password") | ||
|
||
|
||
different_organization_team = Team.objects.create( | ||
team_name = 'different_organization_team', | ||
organization = different_organization, | ||
) | ||
|
||
different_organization_team.permissions.set([ | ||
view_permissions, | ||
]) | ||
|
||
TeamUsers.objects.create( | ||
team = different_organization_team, | ||
user = self.different_organization_user | ||
) |
188 changes: 188 additions & 0 deletions
188
app/settings/tests/unit/external_links/test_external_links_permission.py
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,188 @@ | ||
import pytest | ||
import unittest | ||
import requests | ||
|
||
from django.contrib.auth.models import AnonymousUser, User | ||
from django.contrib.contenttypes.models import ContentType | ||
from django.shortcuts import reverse | ||
from django.test import TestCase | ||
|
||
from access.models import Organization, Team, TeamUsers, Permission | ||
|
||
from app.tests.abstract.model_permissions import ModelPermissions | ||
|
||
from settings.models.external_link import ExternalLink | ||
|
||
|
||
|
||
class ExternalLinkPermissions(TestCase, ModelPermissions): | ||
|
||
|
||
model = ExternalLink | ||
|
||
app_label = 'settings' | ||
|
||
app_namespace = 'Settings' | ||
|
||
url_name_view = '_external_link_view' | ||
|
||
url_name_add = '_external_link_add' | ||
|
||
url_name_change = '_external_link_change' | ||
|
||
url_name_delete = '_external_link_delete' | ||
|
||
url_delete_response = reverse('Settings:External Links') | ||
|
||
|
||
@classmethod | ||
def setUpTestData(self): | ||
"""Setup Test | ||
1. Create an organization for user and item | ||
. create an organization that is different to item | ||
2. Create a device | ||
3. create teams with each permission: view, add, change, delete | ||
4. create a user per team | ||
""" | ||
|
||
organization = Organization.objects.create(name='test_org') | ||
|
||
self.organization = organization | ||
|
||
different_organization = Organization.objects.create(name='test_different_organization') | ||
|
||
|
||
self.item = self.model.objects.create( | ||
organization=organization, | ||
name = 'deviceone' | ||
) | ||
|
||
|
||
self.url_view_kwargs = {'pk': self.item.id} | ||
|
||
self.add_data = {'device': 'device', 'organization': self.organization.id} | ||
|
||
self.url_change_kwargs = {'pk': self.item.id} | ||
|
||
self.change_data = {'device': 'device'} | ||
|
||
self.url_delete_kwargs = {'pk': self.item.id} | ||
|
||
self.delete_data = {'device': 'device'} | ||
|
||
|
||
view_permissions = Permission.objects.get( | ||
codename = 'view_' + self.model._meta.model_name, | ||
content_type = ContentType.objects.get( | ||
app_label = self.model._meta.app_label, | ||
model = self.model._meta.model_name, | ||
) | ||
) | ||
|
||
view_team = Team.objects.create( | ||
team_name = 'view_team', | ||
organization = organization, | ||
) | ||
|
||
view_team.permissions.set([view_permissions]) | ||
|
||
|
||
|
||
add_permissions = Permission.objects.get( | ||
codename = 'add_' + self.model._meta.model_name, | ||
content_type = ContentType.objects.get( | ||
app_label = self.model._meta.app_label, | ||
model = self.model._meta.model_name, | ||
) | ||
) | ||
|
||
add_team = Team.objects.create( | ||
team_name = 'add_team', | ||
organization = organization, | ||
) | ||
|
||
add_team.permissions.set([add_permissions]) | ||
|
||
|
||
|
||
change_permissions = Permission.objects.get( | ||
codename = 'change_' + self.model._meta.model_name, | ||
content_type = ContentType.objects.get( | ||
app_label = self.model._meta.app_label, | ||
model = self.model._meta.model_name, | ||
) | ||
) | ||
|
||
change_team = Team.objects.create( | ||
team_name = 'change_team', | ||
organization = organization, | ||
) | ||
|
||
change_team.permissions.set([change_permissions]) | ||
|
||
|
||
|
||
delete_permissions = Permission.objects.get( | ||
codename = 'delete_' + self.model._meta.model_name, | ||
content_type = ContentType.objects.get( | ||
app_label = self.model._meta.app_label, | ||
model = self.model._meta.model_name, | ||
) | ||
) | ||
|
||
delete_team = Team.objects.create( | ||
team_name = 'delete_team', | ||
organization = organization, | ||
) | ||
|
||
delete_team.permissions.set([delete_permissions]) | ||
|
||
|
||
self.no_permissions_user = User.objects.create_user(username="test_no_permissions", password="password") | ||
|
||
|
||
self.view_user = User.objects.create_user(username="test_user_view", password="password") | ||
teamuser = TeamUsers.objects.create( | ||
team = view_team, | ||
user = self.view_user | ||
) | ||
|
||
self.add_user = User.objects.create_user(username="test_user_add", password="password") | ||
teamuser = TeamUsers.objects.create( | ||
team = add_team, | ||
user = self.add_user | ||
) | ||
|
||
self.change_user = User.objects.create_user(username="test_user_change", password="password") | ||
teamuser = TeamUsers.objects.create( | ||
team = change_team, | ||
user = self.change_user | ||
) | ||
|
||
self.delete_user = User.objects.create_user(username="test_user_delete", password="password") | ||
teamuser = TeamUsers.objects.create( | ||
team = delete_team, | ||
user = self.delete_user | ||
) | ||
|
||
|
||
self.different_organization_user = User.objects.create_user(username="test_different_organization_user", password="password") | ||
|
||
|
||
different_organization_team = Team.objects.create( | ||
team_name = 'different_organization_team', | ||
organization = different_organization, | ||
) | ||
|
||
different_organization_team.permissions.set([ | ||
view_permissions, | ||
add_permissions, | ||
change_permissions, | ||
delete_permissions, | ||
]) | ||
|
||
TeamUsers.objects.create( | ||
team = different_organization_team, | ||
user = self.different_organization_user | ||
) |
Oops, something went wrong.