-
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.
- Loading branch information
Showing
5 changed files
with
433 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import pytest | ||
import unittest | ||
|
||
from django.test import TestCase | ||
|
||
from access.models import Organization | ||
|
||
from app.tests.abstract.models import TenancyModel | ||
|
||
from itim.models.clusters import Cluster | ||
|
||
|
||
|
||
@pytest.mark.django_db | ||
class ClusterModel( | ||
TestCase, | ||
TenancyModel | ||
): | ||
|
||
model = Cluster | ||
|
||
@classmethod | ||
def setUpTestData(self): | ||
"""Setup Test | ||
1. Create an organization for user and item | ||
2. Create an item | ||
""" | ||
|
||
self.organization = Organization.objects.create(name='test_org') | ||
|
||
|
||
self.item = self.model.objects.create( | ||
organization = self.organization, | ||
name = 'one', | ||
) | ||
|
||
self.second_item = self.model.objects.create( | ||
organization = self.organization, | ||
name = 'one_two', | ||
) |
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,78 @@ | ||
|
||
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 itim.models.clusters import Cluster | ||
|
||
|
||
|
||
class ClusterHistory(TestCase, HistoryEntry, HistoryEntryParentItem): | ||
|
||
|
||
model = Cluster | ||
|
||
|
||
@classmethod | ||
def setUpTestData(self): | ||
""" Setup Test """ | ||
|
||
organization = Organization.objects.create(name='test_org') | ||
|
||
self.organization = organization | ||
|
||
self.item_parent = self.model.objects.create( | ||
name = 'test_item_parent_' + self.model._meta.model_name, | ||
organization = self.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": "' + self.item_change.name + '"}' | ||
|
||
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.item_parent._meta.model_name, | ||
) |
95 changes: 95 additions & 0 deletions
95
app/itim/tests/unit/cluster/test_cluster_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,95 @@ | ||
# from django.conf import settings | ||
from django.contrib.auth import get_user_model | ||
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, Client | ||
|
||
import pytest | ||
import unittest | ||
import requests | ||
|
||
from access.models import Organization, Team, TeamUsers, Permission | ||
|
||
from itim.models.clusters import Cluster | ||
|
||
from core.tests.abstract.history_permissions import HistoryPermissions | ||
|
||
|
||
|
||
class ClusterHistoryPermissions(TestCase, HistoryPermissions): | ||
|
||
|
||
item_model = Cluster | ||
|
||
|
||
@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 | ||
) |
Oops, something went wrong.