Skip to content

Commit

Permalink
Added missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed Dec 21, 2021
1 parent 292c7c9 commit bd43212
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
1 change: 1 addition & 0 deletions core/common/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ class OCLTestCase(TestCase, BaseTestCase):
def setUpClass(cls):
super().setUpClass()
call_command("loaddata", "core/fixtures/base_entities.yaml")
call_command("loaddata", "core/fixtures/auth_groups.yaml")

def tearDown(self):
super().tearDown()
Expand Down
13 changes: 13 additions & 0 deletions core/integration_tests/tests_orgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ def test_get_200(self):
self.assertEqual(response.data['id'], self.org.mnemonic)
self.assertEqual(response.data['name'], 'Stark Enterprises')
self.assertFalse('overview' in response.data)
self.assertFalse('client_configs' in response.data)

def test_get_200_with_overview(self):
response = self.client.get(
Expand All @@ -188,6 +189,18 @@ def test_get_200_with_overview(self):
self.assertEqual(response.data['id'], self.org.mnemonic)
self.assertTrue('overview' in response.data)

def test_get_200_with_configs(self):
response = self.client.get(
f'/orgs/{self.org.mnemonic}/?includeClientConfigs=true',
HTTP_AUTHORIZATION='Token ' + self.token,
format='json'
)

self.assertEqual(response.status_code, 200)
self.assertEqual(response.data['uuid'], str(self.org.id))
self.assertEqual(response.data['id'], self.org.mnemonic)
self.assertTrue('client_configs' in response.data)

def test_get_404(self):
response = self.client.get(
'/orgs/foobar/',
Expand Down
30 changes: 28 additions & 2 deletions core/sources/tests/tests.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import factory
from django.core.exceptions import ValidationError
from django.db import transaction, IntegrityError
from mock import patch, Mock, ANY
from mock import patch, Mock, ANY, PropertyMock

from core.common.constants import HEAD, ACCESS_TYPE_EDIT, ACCESS_TYPE_NONE, ACCESS_TYPE_VIEW
from core.common.constants import HEAD, ACCESS_TYPE_EDIT, ACCESS_TYPE_NONE, ACCESS_TYPE_VIEW, \
CUSTOM_VALIDATION_SCHEMA_OPENMRS
from core.common.tasks import seed_children
from core.common.tests import OCLTestCase
from core.concepts.models import Concept
Expand Down Expand Up @@ -576,6 +577,31 @@ def test_hierarchy_without_hierarchy_root(self):
name=parentless_concept.display_name, children=[parentless_concept_child.uri])
)

def test_is_validation_necessary(self):
source = OrganizationSourceFactory()

self.assertFalse(source.is_validation_necessary())

source.custom_validation_schema = CUSTOM_VALIDATION_SCHEMA_OPENMRS

self.assertFalse(source.is_validation_necessary())

source.active_concepts = 1
self.assertTrue(source.is_validation_necessary())

@patch('core.sources.models.Source.head', new_callable=PropertyMock)
def test_is_hierarchy_root_belonging_to_self(self, head_mock):
root = Concept(id=1, parent_id=100)
source = Source(id=1, hierarchy_root=root, version='HEAD')
head_mock.return_value = source
self.assertFalse(source.is_hierarchy_root_belonging_to_self())
source_v1 = Source(id=1, hierarchy_root=root, version='v1')
self.assertFalse(source_v1.is_hierarchy_root_belonging_to_self())

root.parent_id = 1
self.assertTrue(source.is_hierarchy_root_belonging_to_self())
self.assertTrue(source_v1.is_hierarchy_root_belonging_to_self())


class TasksTest(OCLTestCase):
@patch('core.common.models.ConceptContainerModel.index_children')
Expand Down
15 changes: 14 additions & 1 deletion core/users/tests/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.contrib.auth.models import Group
from mock import Mock, patch, ANY
from rest_framework.authtoken.models import Token

Expand All @@ -7,7 +8,7 @@
from core.common.tests import OCLTestCase, OCLAPITestCase
from core.orgs.models import Organization
from core.sources.tests.factories import OrganizationSourceFactory
from core.users.constants import USER_OBJECT_TYPE
from core.users.constants import USER_OBJECT_TYPE, OCL_SERVERS_GROUP
from core.users.models import UserProfile
from core.users.tests.factories import UserProfileFactory

Expand Down Expand Up @@ -204,6 +205,18 @@ def test_mark_verified(self):
self.assertIsNone(user.verification_token)
user.save.assert_not_called()

def test_auth_groups(self):
user = UserProfileFactory()
self.assertEqual(user.auth_groups.count(), 0)

user.groups.add(Group.objects.get(name=OCL_SERVERS_GROUP))

self.assertEqual(user.auth_groups.count(), 1)

def test_is_valid_auth_group(self):
self.assertFalse(UserProfile.is_valid_auth_group('foobar'))
self.assertTrue(UserProfile.is_valid_auth_group(OCL_SERVERS_GROUP))


class TokenAuthenticationViewTest(OCLAPITestCase):
def test_login(self):
Expand Down

0 comments on commit bd43212

Please sign in to comment.