Пример #1
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)
Пример #2
0
 def _slugify_internal_collection_name(self, json_repr):
     """Parse the JSON, find its name, return a slug of its name"""
     collection = self._coerce_json_to_collection(json_repr)
     if collection is None:
         return None
     internal_name = collection['name']
     return slugify(internal_name)
Пример #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 _slugify_internal_collection_name(self, json_repr):
     """Parse the JSON, find its name, return a slug of its name"""
     collection = self._coerce_json_to_collection(json_repr)
     if collection is None:
         return None
     internal_name = collection['name']
     return slugify(internal_name)
Пример #5
0
 def _build_amendment_id(self, json_repr):
     """Parse the JSON, return a slug in the form '{subtype}-{first ottid}-{last-ottid}'."""
     amendment = self._coerce_json_to_amendment(json_repr)
     if amendment is None:
         return None
     amendment_subtype = "additions"
     # TODO: Look more deeply once we have other subtypes!
     first_ottid = amendment["TODO"]
     last_ottid = amendment["TODO"]
     return slugify("{s}-{f}-{l}".format(s=amendment_subtype, f=first_ottid, l=last_ottid))
Пример #6
0
 def _build_amendment_id(self, json_repr):
     """Parse the JSON, return a slug in the form '{subtype}-{first ottid}-{last-ottid}'."""
     amendment = self._coerce_json_to_amendment(json_repr)
     if amendment is None:
         return None
     amendment_subtype = 'additions'
     # TODO: Look more deeply once we have other subtypes!
     first_ottid = amendment['TODO']
     last_ottid = amendment['TODO']
     return slugify('{s}-{f}-{l}'.format(s=amendment_subtype,
                                         f=first_ottid,
                                         l=last_ottid))
Пример #7
0
 def testSlugify(self):
     from peyotl.utility.str_util import slugify
     self.assertEqual('simple-test', slugify('Simple Test'))
     self.assertEqual('no-punctuation-allowed', slugify('No punctuation allowed!?'))
     self.assertEqual('no-extra-spaces-', slugify('No \t extra   spaces   '))
     self.assertEqual('untitled', slugify(''))
     self.assertEqual('untitled', slugify('!?'))
     # TODO: allow broader Unicode strings and their capitalization rules?
     # self.assertEqual(u'километр', slugify(u'Километр'))
     self.assertEqual(u'untitled', slugify(u'Километр'))  # no support for now
Пример #8
0
 def testSlugify(self):
     from peyotl.utility.str_util import slugify
     self.assertEqual('simple-test', slugify('Simple Test'))
     self.assertEqual('no-punctuation-allowed',
                      slugify('No punctuation allowed!?'))
     self.assertEqual('no-extra-spaces-',
                      slugify('No \t extra   spaces   '))
     self.assertEqual('untitled', slugify(''))
     self.assertEqual('untitled', slugify('!?'))
     # TODO: allow broader Unicode strings and their capitalization rules?
     # self.assertEqual(u'километр', slugify(u'Километр'))
     self.assertEqual(u'untitled',
                      slugify(u'Километр'))  # no support for now