Пример #1
0
 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)
Пример #2
0
 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)
Пример #3
0
 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)
Пример #4
0
 def testFetchCollectionRemote(self):
     # drive RESTful API via wrapper
     tca = TreeCollectionsAPI(self.domains, get_from='api')
     try:
         c = tca.get_collection('jimallman/my-test-collection')
     except HTTPError as err:
         raise_http_error_with_more_detail(err)
     except Exception as err:
         raise err
     else:
         # N.B. we get the JSON "wrapper" with history, etc.
         cn = c['data']['name']
         self.assertTrue(cn == u'My test collection')
Пример #5
0
 def testFetchCollectionRemote(self):
     # drive RESTful API via wrapper
     tca = TreeCollectionsAPI(self.domains, get_from='api')
     try:
         c = tca.get_collection('jimallman/my-test-collection')
     except HTTPError as err:
         raise_http_error_with_more_detail(err)
     except Exception as err:
         raise err
     else:
         # N.B. we get the JSON "wrapper" with history, etc.
         cn = c['data']['name']
         self.assertTrue(cn == u'My test collection')
Пример #6
0
 def testRemoteSugar(self):
     tca = TreeCollectionsAPI(self.domains, get_from='api')
     try:
         test_collections_api(self, tca)
     except HTTPError as err:
         raise_http_error_with_more_detail(err)
     except Exception as err:
         raise err
Пример #7
0
 def testPushFailureState(self):
     tca = TreeCollectionsAPI(self.domains, get_from='api')
     sl = tca.push_failure_state
     if sl[0] is not True:
         pprint(
             '\npush-failure (possibly a stale result? re-run to find out!):\n'
         )
         pprint(sl)
     self.assertTrue(sl[0] is True)
Пример #8
0
 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)
Пример #9
0
 def testConfig(self):
     tca = TreeCollectionsAPI(self.domains, get_from='api')
     x = tca.store_config
     self.assertTrue('assumed_doc_version' in x.keys())
Пример #10
0
 def testExternalSugar(self):
     tca = TreeCollectionsAPI(self.domains, get_from='external')
     test_collections_api(self, tca)
Пример #11
0
 def setUp(self):
     self.tca = TreeCollectionsAPI(None,
                                   get_from='local',
                                   locals_repos_dict=test_repos)