def test_old_location_helpers(self): """ Test the functions intended to help with the conversion from old locations to locators """ location_tuple = ('i4x', 'mit', 'eecs.6002x', 'course', 't3_2013') location = Location(location_tuple) self.assertEqual(location, Locator.to_locator_or_location(location)) self.assertEqual(location, Locator.to_locator_or_location(location_tuple)) self.assertEqual(location, Locator.to_locator_or_location(list(location_tuple))) self.assertEqual(location, Locator.to_locator_or_location(location.dict())) locator = BlockUsageLocator(package_id='foo.bar', branch='alpha', block_id='deep') self.assertEqual(locator, Locator.to_locator_or_location(locator)) self.assertEqual(locator.as_course_locator(), Locator.to_locator_or_location(locator.as_course_locator())) self.assertEqual(location, Locator.to_locator_or_location(location.url())) self.assertEqual(locator, Locator.to_locator_or_location(locator.url())) self.assertEqual(locator, Locator.to_locator_or_location(locator.__dict__)) asset_location = Location(['c4x', 'mit', 'eecs.6002x', 'asset', 'selfie.jpeg']) self.assertEqual(asset_location, Locator.to_locator_or_location(asset_location)) self.assertEqual(asset_location, Locator.to_locator_or_location(asset_location.url())) def_location_url = "defx://version/" + '{:024x}'.format(random.randrange(16 ** 24)) self.assertEqual(DefinitionLocator(def_location_url), Locator.to_locator_or_location(def_location_url)) with self.assertRaises(ValueError): Locator.to_locator_or_location(22) with self.assertRaises(ValueError): Locator.to_locator_or_location("hello.world.not.a.url") self.assertIsNone(Locator.parse_url("unknown://foo.bar/baz"))
def create_asset_entries(self, cstore, number): """ Create the fake entries """ course_filter = Location( XASSET_LOCATION_TAG, category="asset", course=self.course.location.course, org=self.course.location.org ) # purge existing entries (a bit brutal but hopefully tests are independent enuf to not trip on this) cstore.fs_files.remove(course_filter.dict()) base_entry = { "displayname": "foo.jpg", "chunkSize": 262144, "length": 0, "uploadDate": datetime(2012, 1, 2, 0, 0), "contentType": "image/jpeg", } for i in range(number): base_entry["displayname"] = "{:03x}.jpeg".format(i) base_entry["uploadDate"] += timedelta(hours=i) base_entry["_id"] = course_filter.replace(name=base_entry["displayname"]).dict() cstore.fs_files.insert(base_entry) return course_filter.dict()
def test_old_location_helpers(self): """ Test the functions intended to help with the conversion from old locations to locators """ location_tuple = ('i4x', 'mit', 'eecs.6002x', 'course', 't3_2013') location = Location(location_tuple) self.assertEqual(location, Locator.to_locator_or_location(location)) self.assertEqual(location, Locator.to_locator_or_location(location_tuple)) self.assertEqual(location, Locator.to_locator_or_location(list(location_tuple))) self.assertEqual(location, Locator.to_locator_or_location(location.dict())) locator = BlockUsageLocator(course_id='foo.bar', branch='alpha', usage_id='deep') self.assertEqual(locator, Locator.to_locator_or_location(locator)) self.assertEqual( locator.as_course_locator(), Locator.to_locator_or_location(locator.as_course_locator())) self.assertEqual(location, Locator.to_locator_or_location(location.url())) self.assertEqual(locator, Locator.to_locator_or_location(locator.url())) self.assertEqual(locator, Locator.to_locator_or_location(locator.__dict__)) asset_location = Location( ['c4x', 'mit', 'eecs.6002x', 'asset', 'selfie.jpeg']) self.assertEqual(asset_location, Locator.to_locator_or_location(asset_location)) self.assertEqual(asset_location, Locator.to_locator_or_location(asset_location.url())) def_location_url = "defx://version/" + '{:024x}'.format( random.randrange(16**24)) self.assertEqual(DefinitionLocator(def_location_url), Locator.to_locator_or_location(def_location_url)) with self.assertRaises(ValueError): Locator.to_locator_or_location(22) with self.assertRaises(ValueError): Locator.to_locator_or_location("hello.world.not.a.url") self.assertIsNone(Locator.parse_url("unknown://foo.bar/baz"))
def create_asset_entries(self, cstore, number): """ Create the fake entries """ course_filter = Location( XASSET_LOCATION_TAG, category='asset', course=self.course.location.course, org=self.course.location.org ) base_entry = { 'displayname': 'foo.jpg', 'chunkSize': 262144, 'length': 0, 'uploadDate': datetime(2012, 1, 2, 0, 0), 'contentType': 'image/jpeg', } for i in range(number): base_entry['displayname'] = '{:03x}.jpeg'.format(i) base_entry['uploadDate'] += timedelta(hours=i) base_entry['_id'] = course_filter.replace(name=base_entry['displayname']).dict() cstore.fs_files.insert(base_entry) return course_filter.dict()
def create_asset_entries(self, cstore, number): """ Create the fake entries """ course_filter = Location( XASSET_LOCATION_TAG, category='asset', course=self.course.location.course, org=self.course.location.org ) # purge existing entries (a bit brutal but hopefully tests are independent enuf to not trip on this) cstore.fs_files.remove(location_to_query(course_filter)) base_entry = { 'displayname': 'foo.jpg', 'chunkSize': 262144, 'length': 0, 'uploadDate': datetime(2012, 1, 2, 0, 0), 'contentType': 'image/jpeg', } for i in range(number): base_entry['displayname'] = '{:03x}.jpeg'.format(i) base_entry['uploadDate'] += timedelta(hours=i) base_entry['_id'] = course_filter.replace(name=base_entry['displayname']).dict() cstore.fs_files.insert(base_entry) return course_filter.dict()