예제 #1
0
class PollRepositoryTestCase(TestCase, Utility):
	sut = None
	data = None
	
	def setUp(self):
		self.sut = PollRepository()
		
	def test_when_retrieving_poll_by_unique_id_then_the_correct_poll_is_returned(self):
		uniqueId = self.getUniqueId()
		poll = Poll()
		poll.uniqueId = uniqueId
		poll.save();
		
		result = self.sut.getPollByUniqueId(uniqueId)
	
		self.assertEqual(poll.id, result.id)

	def test_when_retrieveing_poll_by_unique_id_then_none_is_returned_when_there_is_no_match(self):
		poll = self.sut.getPollByUniqueId(-1)

		self.assertEqual(poll, None)
		
예제 #2
0
class PollFacade():
	def __init__(self):
		self._uniqueIdGenerator = UniqueIdGenerator()
		self._choiceFacade = ChoiceFacade()
		self._pollRepository = PollRepository()

	def create(self, poll, choices):
		poll.uniqueId = self._getUnusedPollUniqueId()
		self._pollRepository.create(poll)
		
		for choice in choices:
			self._choiceFacade.create(choice, poll)

	def _getUnusedPollUniqueId(self):
		for i in range(100):
			candidatePollUniqueId = self._uniqueIdGenerator.createUrlSafeUniqueId()
			existingPoll = self._pollRepository.getPollByUniqueId(candidatePollUniqueId)

			if existingPoll is None:
				break
		
		return candidatePollUniqueId
예제 #3
0
	def create(self, data):
		pollRepo = PollRepository()
		return pollRepo.createPoll(data)
예제 #4
0
	def __init__(self):
		self._uniqueIdGenerator = UniqueIdGenerator()
		self._choiceFacade = ChoiceFacade()
		self._pollRepository = PollRepository()
예제 #5
0
	def setUp(self):
		self.sut = PollRepository()