def testDeleteCollectionRemote(self): # drive RESTful API via wrapper tca = TreeCollectionsAPI(self.domains, get_from='api') # remove any prior clones of our tests collection? or let them pile up for now? cl = tca.collection_list cid = 'jimallman/doomed-collection' if cid not in cl: # add our dummy collection so just we can delete it cjson = get_empty_collection() commit_msg = 'Creating temporary collection via API wrapper' result = tca.post_collection(cjson, cid, commit_msg) cl = tca.collection_list self.assertEqual(result['error'], 0) self.assertEqual(result['merge_needed'], False) self.assertEqual(result['resource_id'], cid) self.assertTrue(cid in cl) # now try to clobber it try: c = tca.get_collection(cid) except HTTPError as err: raise_http_error_with_more_detail(err) except Exception as err: raise err else: tca.delete_collection(cid, c['sha']) # is it really gone? cl = tca.collection_list self.assertTrue(cid not in cl)
def testCreateCollectionRemote(self): # drive RESTful API via wrapper tca = TreeCollectionsAPI(self.domains, get_from='api') # remove any prior clones of our tests collection? or let them pile up for now? cl = tca.collection_list test_collection_name = 'My test collection' test_collection_id_base = 'jimallman/my-test-collection' expected_id = test_collection_id_base while expected_id in cl: # keep generating ids until we find a new one expected_id = increment_slug(expected_id) # generate a new collection and name it cjson = get_empty_collection() cjson['name'] = test_collection_name # N.B. this name already exists! should force a new, serial id cslug = slugify(cjson['name']) cid = 'jimallman/{}'.format(cslug) # TODO: generate a unique URL based on this json, and modify it internally? commit_msg = 'Test of creating collections via API wrapper' result = tca.post_collection(cjson, cid, commit_msg) cl = tca.collection_list self.assertEqual(result['error'], 0) self.assertEqual(result['merge_needed'], False) self.assertEqual(result['resource_id'], expected_id) self.assertTrue(expected_id in cl)
def testCreated(self): c = get_empty_collection() aa = validate_collection(c) errors = aa[0] self.assertTrue(len(errors) == 0)
from peyotl.collections_store.validation import validate_collection from peyotl import write_as_json import sys # Expecting a lot of lines like pg_2359_4962 for 'pg_2359', 'tree4962' inp_fn = sys.argv[1] with open(inp_fn, 'rU') as inp: lines = [] for line in inp: line = line.strip() if (not line) or (line == 'taxonomy'): continue assert line.endswith('.tre') frag = line[:-4] s = frag.split('_') study_id, tree_frag = '_'.join(s[:-1]), s[-1] tree_id = 'tree' + tree_frag lines.append((study_id, tree_id)) c = get_empty_collection() d = c['decisions'] for pair in lines: d.append({'SHA': '', 'decision': 'INCLUDED', 'name': '', 'studyID': pair[0], 'treeID': pair[1] }) assert not (validate_collection(c)[0]) write_as_json(c, sys.stdout)
selected_study_found = True else: continue ga = ps.create_git_action(study_id) with ga.lock(): ga.checkout(sha) if copy_phylesystem_file_if_differing(ga, sha, inc, out_dir, generic2concrete): num_moved += 1 ga.checkout_master() debug('{} total trees'.format(len(included))) debug('{} JSON files copied'.format(num_moved)) if selected_study is not None: if selected_study_found: sys.exit(0) error('The selected tree {}_{}.json was not found in the collection\n.'.format(selected_study, selected_tree)) sys.exit(1) # now we write a "concrete" version of this snapshot coll_name = os.path.split(args.collection)[-1] concrete_collection = get_empty_collection() concrete_collection['description'] = 'Concrete form of collection "{}"'.format(coll_name) cd_list = concrete_collection['decisions'] for inc in included: concrete = generic2concrete[id(inc)] cd_list.append(concrete) concrete_fn = os.path.join(out_dir, 'concrete_' + coll_name) write_as_json(concrete_collection, concrete_fn)
selected_study_found = True else: continue ga = ps.create_git_action(study_id) with ga.lock(): ga.checkout(sha) if copy_phylesystem_file_if_differing(ga, sha, inc, out_dir, generic2concrete): num_moved += 1 ga.checkout_master() debug('{} total trees'.format(len(included))) debug('{} JSON files copied'.format(num_moved)) if selected_study is not None: if selected_study_found: sys.exit(0) error( 'The selected tree {}_{}.json was not found in the collection\n.'. format(selected_study, selected_tree)) sys.exit(1) # now we write a "concrete" version of this snapshot coll_name = os.path.split(args.collection)[-1] concrete_collection = get_empty_collection() concrete_collection[ 'description'] = 'Concrete form of collection "{}"'.format(coll_name) cd_list = concrete_collection['decisions'] for inc in included: concrete = generic2concrete[id(inc)] cd_list.append(concrete) concrete_fn = os.path.join(out_dir, 'concrete_' + coll_name) write_as_json(concrete_collection, concrete_fn)