Skip to content

Commit

Permalink
Modified the validation to accept country of origin in uppercase
Browse files Browse the repository at this point in the history
  • Loading branch information
Sangeetha-Bheeman committed Aug 22, 2023
1 parent fdd6f5b commit a992add
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ def test_CountryOfOrigin_check_CountryOfOrigin_is_valid():
assert instance.validate() is False
assert len(instance.errors) > 0

instance = CountryOfOrigin(Input("United Kingdom"))
instance = CountryOfOrigin(Input("UNITED KINGDOM"))
assert instance.validate() is True
assert len(instance.errors) == 0
2 changes: 1 addition & 1 deletion tests/message_properties/definitions/test_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ def test_sample_is_invalid(invalid_sample):
check_presence_error(instance.errors, error_codes.ERROR_2_NOT_STRING, "cost_code")
check_presence_error(instance.errors, error_codes.ERROR_2_NOT_STRING, "final_nano_drop_280")
check_presence_error(instance.errors, error_codes.ERROR_2_NOT_STRING, "final_nano_drop_230")
assert len(instance.errors) == 14
assert len(instance.errors) == 15
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class CountryOfOrigin(MessageProperty):
"""MessageProperty subclass to manage parsing of a valid country of origin provided by another
MessageProperty. The concentration has to be a country string from the list provided in
MessageProperty. The country has to be a country string from the list provided in
tol_lab_share.config.insdc.
Eg: 'Australia'
"""
Expand All @@ -25,10 +25,16 @@ def check_is_valid_country(self):
If that is not the case, it will trigger an error (not valid country insdc).
"""
logger.debug("CountryOfOrigin::check_is_valid_country")
result = False
if not self._input.validate():
return False
return result

if self.check_is_string():
for country in COUNTRIES:
if self._input.value.lower() == country.lower():
result = True
self._input.value = country

result = self._input.value.lower() in [country.lower() for country in COUNTRIES]
if not result:
self.trigger_error(error_codes.ERROR_4_NOT_VALID_COUNTRY_INSDC, text=f"input_value: {self._input.value}")
return result

0 comments on commit a992add

Please sign in to comment.