Skip to content

Commit

Permalink
Fixing flaky test for openmrs concept schema
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed Jan 3, 2022
1 parent df466ff commit 3db5df2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
23 changes: 23 additions & 0 deletions core/concepts/validators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from django.conf import settings
from django.core.cache import cache
from django.core.exceptions import ValidationError
from pydash import get

from core.common.constants import (
NA, YES, NO, CUSTOM_VALIDATION_SCHEMA_OPENMRS, FIVE_MINS, HEAD, REFERENCE_VALUE_SOURCE_MNEMONICS
Expand All @@ -24,6 +26,7 @@ def __init__(self):
self.validator_map = {
CUSTOM_VALIDATION_SCHEMA_OPENMRS: OpenMRSConceptValidator
}
self._test_cache = {}
self.reference_values = {}
self.repo = None
self.validation_schema = None
Expand All @@ -38,6 +41,8 @@ def with_repo(self, repo):
return self

def with_reference_values(self):
if get(settings, 'TEST_MODE', False):
return self.with_reference_values_from_dict() # django.core.cache doesn't work with parallel tests
ocl_org_filter = Organization.objects.get(mnemonic='OCL')
if 'reference_sources' not in cache:
cache.set(
Expand All @@ -57,6 +62,24 @@ def with_reference_values(self):

return self

def with_reference_values_from_dict(self):
ocl_org_filter = Organization.objects.get(mnemonic='OCL')

if 'reference_sources' not in self._test_cache:
self._test_cache['reference_sources'] = ocl_org_filter.source_set.filter(
mnemonic__in=REFERENCE_VALUE_SOURCE_MNEMONICS, version=HEAD)

sources = self._test_cache.get('reference_sources')

self.reference_values = {}
for source in sources:
if source.mnemonic not in cache:
self._test_cache[source.mnemonic] = self._get_reference_values(source)
reference_values = self._test_cache.get(source.mnemonic)
self.reference_values[source.mnemonic] = reference_values

return self

@staticmethod
def _get_reference_values(reference_value_source):
return list(reference_value_source.get_concept_name_locales().values_list('name', flat=True))
Expand Down
3 changes: 0 additions & 3 deletions core/integration_tests/tests_concepts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import unittest

from mock import ANY

from core.common.constants import CUSTOM_VALIDATION_SCHEMA_OPENMRS
Expand Down Expand Up @@ -225,7 +223,6 @@ def test_put_200(self):
self.assertTrue(concept.is_versioned_object)
self.assertEqual(concept.datatype, "None")

@unittest.skip('Flaky test, needs fixing')
def test_put_200_openmrs_schema(self): # pylint: disable=too-many-statements
self.create_lookup_concept_classes()
source = OrganizationSourceFactory(custom_validation_schema=CUSTOM_VALIDATION_SCHEMA_OPENMRS)
Expand Down

0 comments on commit 3db5df2

Please sign in to comment.