Skip to content

Commit

Permalink
fix #1885
Browse files Browse the repository at this point in the history
  • Loading branch information
antgonza committed Jul 11, 2016
1 parent 9f32be2 commit f407569
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
11 changes: 8 additions & 3 deletions qiita_db/metadata_template/base_metadata_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -1381,9 +1381,14 @@ def validate(self, restriction_dict):
# test values
if datatype == datetime:
val = str(val)
formats = ['%m/%d/%Y %H:%M:%S', '%m/%d/%Y %H:%M',
'%m/%d/%Y %H', '%m/%d/%Y', '%m/%Y',
'%Y']
formats = [
# 4 digits year
'%m/%d/%Y %H:%M:%S', '%m/%d/%Y %H:%M',
'%m/%d/%Y %H', '%m/%d/%Y', '%m/%Y', '%Y',
# 2 digits year
'%m/%d/%y %H:%M:%S', '%m/%d/%y %H:%M',
'%m/%d/%y %H', '%m/%d/%y', '%m/%y', '%y'
]
date = None
for fmt in formats:
try:
Expand Down
37 changes: 32 additions & 5 deletions qiita_db/metadata_template/test/test_sample_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -2196,26 +2196,53 @@ def test_validate_errors(self):
self.assertIn('2.Sample2, wrong value "wrong latitude"', message)
self.assertIn('2.Sample1, wrong value "wrong date"', message)

def test_validate_errors_timestampA(self):
def test_validate_errors_timestampA_year4digits(self):
self.metadata.set_value('Sample1', 'collection_timestamp',
'09/20/2016 12:00')
self.metadata.set_value('Sample2', 'collection_timestamp',
'09/20/2016 12')
'9/20/2016 12')
self.metadata.set_value('Sample3', 'collection_timestamp',
'09/20/2016')

qdb.metadata_template.sample_template.SampleTemplate.create(
self.metadata, self.new_study)
with catch_warnings(record=True) as warn:
qdb.metadata_template.sample_template.SampleTemplate.create(
self.metadata, self.new_study)
# the warnings should be empty
self.assertEqual(warn, [])

def test_validate_errors_timestampB(self):
def test_validate_errors_timestampA_year2digits(self):
self.metadata.set_value('Sample1', 'collection_timestamp',
'09/20/16 12:00')
self.metadata.set_value('Sample2', 'collection_timestamp',
'9/20/16 12')
self.metadata.set_value('Sample3', 'collection_timestamp',
'09/20/16')

with catch_warnings(record=True) as warn:
qdb.metadata_template.sample_template.SampleTemplate.create(
self.metadata, self.new_study)
# the warnings should be empty
self.assertEqual(warn, [])

def test_validate_errors_timestampB_year4digits(self):
self.metadata.set_value('Sample1', 'collection_timestamp',
'12/2016')
self.metadata.set_value('Sample2', 'collection_timestamp',
'2016')
with catch_warnings(record=True) as warn:
qdb.metadata_template.sample_template.SampleTemplate.create(
self.metadata, self.new_study)
# the warnings should be empty
self.assertEqual(warn, [])

def test_validate_errors_timestampB_year2digits(self):
self.metadata.set_value('Sample1', 'collection_timestamp',
'12/16')
self.metadata.set_value('Sample2', 'collection_timestamp',
'16')
with catch_warnings(record=True) as warn:
qdb.metadata_template.sample_template.SampleTemplate.create(
self.metadata, self.new_study)
# the warnings should be empty
self.assertEqual(warn, [])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ These are the columns required for successfully submit your data to EBI:
| | or ``mm/dd/yyyy hh`` | |
| | or ``mm/dd/yyyy`` | |
| | or ``mm/yyyy`` | |
| | or ``yyyy`` | |
| | or ``yyyy``. | |
| | Years are supported as | |
| | 4 ``yyyy`` or 2 ``yy`` | |
| | digits | |
+----------------------------------+-------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
| ``physical_specimen_location`` | free text | Where you would go to find physical sample or DNA, regardless of whether it is still available or not. |
+----------------------------------+-------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
Expand Down

0 comments on commit f407569

Please sign in to comment.