示例#1
0
	def test_fix_on_patch(self):
		"""if parameter `effective_date` in URL query string has value `fix`, the change should not be logged into the `changes` field"""
		vpapi.patch(
			'people/%s' % self.person_id,
			{'email': '*****@*****.**'},
			effective_date='fix')
		result = vpapi.get('people/%s' % self.person_id)
		self.assertNotIn('changes', result)
示例#2
0
	def test_changes_on_patch_with_effective_date(self):
		"""if parameter `effective_date` is sent in URL query string then the change should be assumed at the given date and not today"""
		vpapi.patch(
			'people/%s' % self.person_id,
			{'email': '*****@*****.**'},
			effective_date='2000-01-01')
		expected_change = {
			'property': 'email',
			'value': '*****@*****.**',
			'end_date': '1999-12-31'
		}
		result = vpapi.get('people/%s' % self.person_id)
		self.assertIn(expected_change, result.get('changes'))
示例#3
0
	def test_changes_on_patch(self):
		"""changed value in any of the fields with tracked history should be logged into the `changes` field with `end_date` equal to yesterday. Explicitly sent changes should be merged with the automatically managed ones."""
		explicit_change = {
			'property': 'abc',
			'value': 'xyz'
		}
		vpapi.patch(
			'people/%s' % self.person_id,
			{'email': '*****@*****.**', 'changes': [explicit_change]})
		expected_change = {
			'property': 'email',
			'value': '*****@*****.**',
			'end_date': datestring_add(date.today().isoformat(), -1)
		}
		result = vpapi.get('people/%s' % self.person_id)
		self.assertIn('changes', result)
		self.assertEqual(len(result['changes']), 2)
		self.assertEqual(expected_change, result['changes'][0])
		self.assertEqual(explicit_change, result['changes'][1])
示例#4
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'])
示例#5
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)