def _remote_survey_url_polyphenol_ffq(transaction, account_id, source_id, language_tag): st_repo = SurveyTemplateRepo(transaction) # right now, ID won't exist # future plans to allow surveys to behave more flexibly will use this # functionality to allow participants to re-join in-progress surveys polyphenol_ffq_id, study = \ st_repo.get_polyphenol_ffq_id_if_exists(account_id, source_id) if polyphenol_ffq_id is None: # The Polyphenol FFQ belongs to Danone and they're interested in # tracking results that come from their sponsored studies # separately from other samples. We pass 'THDMI' as the study for # THDMI samples and 'Microsetta' for all other samples. Therefore, # we need to determine if the source has any THDMI-associated samples. # Without investing significant developer effort to build a category # system around projects, a basic text search is the best compromise. study = 'Microsetta' sample_repo = SampleRepo(transaction) samples = sample_repo.get_samples_by_source(account_id, source_id) for s in samples: for s_p in s.sample_projects: if s_p.startswith('THDMI'): study = 'THDMI' break polyphenol_ffq_id = st_repo.create_polyphenol_ffq_entry( account_id, source_id, language_tag, study) return polyphenol_ffq.gen_ffq_url(polyphenol_ffq_id, study, language_tag)
def test_create_polyphenol_ffq_entry_valid(self): with Transaction() as t: template_repo = SurveyTemplateRepo(t) obs = template_repo.create_polyphenol_ffq_entry( TEST1_ACCOUNT_ID, TEST1_SOURCE_ID, 'en_US', 'THDMI') try: uuid.UUID(obs) valid_uuid_returned = True except ValueError: valid_uuid_returned = False self.assertTrue(valid_uuid_returned)
def test_get_polyphenol_ffq_id_if_exists_true(self): with Transaction() as t: template_repo = SurveyTemplateRepo(t) test_pffq_id = \ template_repo.create_polyphenol_ffq_entry(TEST1_ACCOUNT_ID, TEST1_SOURCE_ID, 'en_US', 'THDMI') obs = \ template_repo.get_polyphenol_ffq_id_if_exists(TEST1_ACCOUNT_ID, TEST1_SOURCE_ID) self.assertEqual((test_pffq_id, 'THDMI'), obs)
def test_create_polyphenol_ffq_entry_invalid(self): with Transaction() as t: template_repo = SurveyTemplateRepo(t) with self.assertRaises(InvalidTextRepresentation): template_repo.create_polyphenol_ffq_entry( '', TEST1_SOURCE_ID, '', '')