def test_set_curate(self): trial = set_curated(self.trial) assert 'curated_on' in trial, trial trial = self._check_trial_post(trial) # send again trial = set_curated(trial) assert 'curated_on' in trial, trial assert 'last_updated' in trial and trial['last_updated'] == self.today, trial for field in self.trial_status_fields: assert field in trial['_summary'], '%s\n\n%s' % (trial['_summary'], field) self._check_trial_post(trial) # update trial = set_updated(trial) assert 'curated_on' in trial, trial assert 'last_updated' in trial and trial['last_updated'], trial for field in self.trial_status_fields: assert field in trial['_summary'], '%s\n\n%s' % (trial['_summary'], field) self._check_trial_post(trial)
def test_set_curate(self): trial = set_curated(self.trial) assert 'curated_on' in trial, trial build_trial_elasticsearch_fields([trial]) # send again trial = set_curated(trial) assert 'curated_on' in trial, trial assert 'last_updated' in trial and trial[ 'last_updated'] == self.today, trial for field in self.trial_status_fields: assert field in trial['_summary'], '%s\n\n%s' % (trial['_summary'], field) build_trial_elasticsearch_fields([trial]) # update trial = set_updated(trial) assert 'curated_on' in trial, trial assert 'last_updated' in trial and trial['last_updated'], trial for field in self.trial_status_fields: assert field in trial['_summary'], '%s\n\n%s' % (trial['_summary'], field)
def test_set_curate(self): trial = set_curated(self.trial) assert 'curated_on' in trial, trial trial = self._check_trial_post(trial) # send again trial = set_curated(trial) assert 'curated_on' in trial, trial assert 'last_updated' in trial and trial[ 'last_updated'] == self.today, trial for field in self.trial_status_fields: assert field in trial['_summary'], '%s\n\n%s' % (trial['_summary'], field) self._check_trial_post(trial) # update trial = set_updated(trial) assert 'curated_on' in trial, trial assert 'last_updated' in trial and trial['last_updated'], trial for field in self.trial_status_fields: assert field in trial['_summary'], '%s\n\n%s' % (trial['_summary'], field) self._check_trial_post(trial)
def test_updatedt_with_curatedt(self): # set up today = dt.datetime.now().strftime('%B %d, %Y') old = 'October 27, 2016' on_trial['_genomic'] = {'hugo_symbol': [{'value': 'TEST'}]} on_trial['_clinical'] = {'disease_status': [{'value': ['TEST']}]} # set both dates to OLD on_trial['curated_on'] = old on_trial['last_updated'] = old assert on_trial['curated_on'] == old, self._debug( on_trial, 'curated_on') assert on_trial['last_updated'] == old, self._debug( on_trial, 'last_updated') # set "last_updated" to TODAY trial = set_updated(on_trial) assert trial['curated_on'] == old, self._debug(trial, 'curated_on') assert trial['last_updated'] == today, self._debug( trial, 'last_updated') # check dates are preserved after trial_insert is called trial['protocol_no'] = '01-001' trial = trial_insert([trial]) trial = trial[0] assert trial['curated_on'] == old, self._debug(trial, 'curated_on') assert trial['last_updated'] == today, self._debug( trial, 'last_updated') # check the other way around on_trial['curated_on'] = old trial['last_updated'] = old assert trial['curated_on'] == old, self._debug(trial, 'curated_on') assert trial['last_updated'] == old, self._debug(trial, 'last_updated') trial = set_curated(on_trial) assert trial['curated_on'] == today, self._debug(trial, 'curated_on') assert trial['last_updated'] == today, self._debug( trial, 'last_updated') trial = trial_insert([trial]) trial = trial[0] assert trial['curated_on'] == today, self._debug(trial, 'curated_on') assert trial['last_updated'] == today, self._debug( trial, 'last_updated')
def test_updatedt_with_curatedt(self): # set up today = dt.datetime.now().strftime('%B %d, %Y') old = 'October 27, 2016' on_trial['_genomic'] = {'hugo_symbol': [{'value': 'TEST'}]} on_trial['_clinical'] = {'disease_status': [{'value': ['TEST']}]} # set both dates to OLD on_trial['curated_on'] = old on_trial['last_updated'] = old assert on_trial['curated_on'] == old, self._debug(on_trial, 'curated_on') assert on_trial['last_updated'] == old, self._debug(on_trial, 'last_updated') # set "last_updated" to TODAY trial = set_updated(on_trial) assert trial['curated_on'] == old, self._debug(trial, 'curated_on') assert trial['last_updated'] == today, self._debug(trial, 'last_updated') # check dates are preserved after trial_insert is called trial = trial_insert([trial]) trial = trial[0] assert trial['curated_on'] == old, self._debug(trial, 'curated_on') assert trial['last_updated'] == today, self._debug(trial, 'last_updated') # check the other way around on_trial['curated_on'] = old trial['last_updated'] = old assert trial['curated_on'] == old, self._debug(trial, 'curated_on') assert trial['last_updated'] == old, self._debug(trial, 'last_updated') trial = set_curated(on_trial) assert trial['curated_on'] == today, self._debug(trial, 'curated_on') assert trial['last_updated'] == today, self._debug(trial, 'last_updated') trial = trial_insert([trial]) trial = trial[0] assert trial['curated_on'] == today, self._debug(trial, 'curated_on') assert trial['last_updated'] == today, self._debug(trial, 'last_updated')
def index(): # set headers. headers = { 'Content-Type': 'application/json', 'Authorization': 'Basic ' + base64.b64encode(f'{API_TOKEN}:'.encode('utf-8')).decode('utf-8'), } # render the form. if request.method == 'GET': # render the page return _render_trials() # render the response else: # check if the post request has the file part if 'file' not in request.files: return "no file" #return redirect(request.url) # ensure file is present. file = request.files['file'] if file.filename == '': return "empty filename" if file: # create trial. try: # load the trial. trial_new = yaml.load(file) except yaml.YAMLError as exc: # set yaml error. r_code = 512 r_text = exc return "%s</br></br>%s" % (r_code, r_text) # Deal with "disease_site_code" type exception trial_new = _handle_exc(trial_new) # create the request. qstr = "where=%s" % json.dumps( ({ "protocol_no": trial_new['protocol_no'] })) # get the trial list from db. url = '%s/trial?%s' % (API_ADDRESS, qstr) r = requests.get(url, headers=headers) output = r.json() # set curated on field trial_new = set_curated(trial_new) # detected a new trial. if len(output['_items']) == 0: # post the trial. url = '%s/trial' % (API_ADDRESS) r = requests.post(url, json=trial_new, headers=headers) r_code = r.status_code r_text = r.text else: # get info. trial = output['_items'][0] trial_id = str(trial['_id']) etag = trial['_etag'] # strip meta for key in list(trial.keys()): if key[0] == "_": del trial[key] trial['_id'] = trial_id # add the defaults headers['If-Match'] = etag # post the trial. url = '%s/trial/%s' % (API_ADDRESS, trial_id) r = requests.put(url, json=trial_new, headers=headers) r_code = r.status_code r_text = json.dumps(r.json(), indent=4) # render index if good. if r_code > 199 and r_code < 300: return _render_trials() # render the error return "%s</br></br>%s" % (r_code, r_text)