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)