Esempio n. 1
0
	def test_file_mirroring(self):
		"""URLs in the mirrored fields should be relocated and the referenced files downloaded"""
		# check that the file has been relocated and downloaded
		mirrored_url = 'http://files.parldata.eu/xx/example/people/%s/image.png' % self.person_id
		pathfile = '../files.parldata.eu/xx/example/people/%s/image' % self.person_id
		result = vpapi.get('people/%s' % self.person_id)
		self.assertEqual(result['image'], mirrored_url)
		self.assertEqual(len(glob.glob(pathfile + '.*')), 1)

		# check that the file is not mirrored again if the source hasn't changed
		vpapi.patch('people/%s' % self.person_id, {'image': self.sample_image_url})
		result = vpapi.get('people/%s' % self.person_id)
		self.assertEqual(result['image'], mirrored_url)
		self.assertEqual(len(glob.glob(pathfile + '.*')), 1)

		# check that new file is mirrored if the source file changes
		new_image = 'http://upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png'
		vpapi.patch('people/%s' % self.person_id, {'image': new_image})
		result = vpapi.get('people/%s' % self.person_id)
		self.assertEqual(result['image'], mirrored_url.replace('.png', '.2.png'))
		self.assertEqual(len(glob.glob(pathfile + '.*')), 2)

		# check that non-existent remote URLs are not mirrored
		nonexistent_image = 'http://example.notexists'
		vpapi.patch('people/%s' % self.person_id, {'image': nonexistent_image})
		result = vpapi.get('people/%s' % self.person_id)
		self.assertEqual(result['image'], nonexistent_image)
		self.assertEqual(len(glob.glob(pathfile + '.*')), 2)

		# check that mirrored files are deleted with entity deletion
		vpapi.delete('people/%s' % self.person_id)
		self.assertEqual(len(glob.glob(pathfile + '.*')), 0)
Esempio n. 2
0
	def test_id_field(self):
		"""entity should use `id` instead of `_id`"""
		result = vpapi.get('people/%s' % self.person_id)
		self.assertIn('id', result)
		self.assertNotIn('_id', result)
		result = vpapi.post('people', self.person_with_id)
		self.assertIn('id', result)
		self.assertNotIn('_id', result)
		self.assertEqual(result['id'], self.person_with_id['id'])
		result = vpapi.patch('people/%s' % result['id'], {'name': 'Baggins, Bilbo'})
		self.assertEqual(result['id'], self.person_with_id['id'])
		vpapi.delete('people/%s' % self.person_with_id['id'])
Esempio n. 3
0
	def setUp(self):
		# authorize to xx/example parliament
		vpapi.parliament('xx/example')
		vpapi.authorize('scraper', 'secret')

		# ensure exactly one person with the sample value
		result = vpapi.get('people', where={'identifiers': {'$elemMatch': self.sample_identifier}})
		if result['_items']:
			vpapi.delete('people/%s' % result['_items'][0]['id'])
		result = vpapi.post('people', self.sample_person)
		self.person_id = result['id']
		# and no person with specified id
		result = vpapi.get('people', where={'id': self.person_with_id['id']})
		if result['_items']:
			vpapi.delete('people/%s' % self.person_with_id['id'])

		# ensure exactly one organization with the sample value
		result = vpapi.get('organizations', where={'name': 'ABC, Inc.'})
		if result['_items']:
			vpapi.delete('organizations/%s' % result['_items'][0]['id'])
		result = vpapi.post('organizations', self.sample_organization)
		self.organization_id = result['id']

		# ensure exactly one membership with the sample value
		result = vpapi.get('memberships', where={'label': 'Kitchen assistant at ABC, Inc.'})
		if result['_items']:
			vpapi.delete('memberships/%s' % result['_items'][0]['id'])
		self.sample_membership['person_id'] = self.person_id
		self.sample_membership['organization_id'] = self.organization_id
		result = vpapi.post('memberships', self.sample_membership)
		self.membership_id = result['id']
Esempio n. 4
0
	def tearDown(self):
		# remove entities and files created for testing
		try:
			vpapi.delete('people/%s' % self.person_id)
			vpapi.delete('organizations/%s' % self.organization_id)
			vpapi.delete('memberships/%s' % self.membership_id)
		except requests.exceptions.HTTPError:
			pass