def test_empties(self): profile = new_profile() expected = [['links', 'item', 0], ['version'], ['attributes', 'contentencoded'], ['attributes', 'contenttemplated'], ['attributes', 'description'], ['attributes', 'tags', 0], ['attributes', 'published'], ['attributes', 'teaser'], ['attributes', 'byline']] for empty_path in empty_values(profile): self.assertIn(empty_path, expected)
def test_new_profile(self): profile = new_profile() self.assertIn('links', profile) self.assertIn('attributes', profile) self.assertIn('version', profile) self.assertNotIn('collection', profile['links']) self.assertNotIn('REQUIRED', profile) self.assertNotIn('OPTIONAL', profile) self.assertIn('title', profile['attributes']) self.assertIn('byline', profile['attributes']) self.assertIn('guid', profile['attributes'])
def test_validate_fail_incorrect_value_type(self): profile = new_profile() for path in find_value(profile, 'REQUIRED_VALUE'): set_nested_value(profile, path, 'Fixed!') # Clobber list with new dictionary test_copy = copy.deepcopy(profile) test_copy['links']['alternate'] = {'WRONG': 'Bad Value'} self.assertFalse(validate(test_copy)[0]) # Clobber list with string test_copy = copy.deepcopy(profile) set_nested_value(test_copy, ['links', 'item'], 'Bad Value') self.assertFalse(validate(test_copy)[0]) # Clobber string with new dictionary test_copy = copy.deepcopy(profile) test_copy['attributes']['guid'] = [{'new Key': 'Bad Value'}] self.assertFalse(validate(test_copy)[0])
def test_validate_fail_missing_required(self): profile = new_profile() self.assertFalse(validate(profile))
def test_validate_pass(self): profile = new_profile() for path in find_value(profile, 'REQUIRED_VALUE'): set_nested_value(profile, path, 'Fixed!') self.assertTrue(validate(profile))
def test_edit_profile(self): profile = new_profile() test_item = self.datadoc.items[1] new_data = edit_profile(profile, test_item) self.assertEqual(new_data['attributes']['contentencoded'], test_item['attributes']['contentencoded'])
def test_new_profile_with_collection(self): collection_url = "http://SOMECOLLECTION" profile = new_profile(collection=collection_url) self.assertIn('collection', profile['links']) self.assertEqual(profile['links']['collection'][0]['href'], collection_url)