class UniqueIdGeneratorTestCase(TestCase): sut = None; def setUp(self): self.sut = UniqueIdGenerator() def test_when_generating_unique_id_then_length_is_10(self): uniqueId = self.sut.createUrlSafeUniqueId() self.assertEqual(10, len(uniqueId)) def test_when_generating_unique_id_then_does_not_contain_illegal_characters(self): illegalChar = ['+', '-', '_', '\\', '/', '='] uniqueId = self.sut.createUrlSafeUniqueId() for c in illegalChar: self.assertNotIn(c, uniqueId) def test_when_generating_unique_id_then_length_is_22(self): uniqueId = self.sut.createUniqueId() self.assertEqual(22, len(uniqueId))
class ChoiceFacade: _uniqueIdGenerator = None _choiceRepository = None def __init__(self): self._uniqueIdGenerator = UniqueIdGenerator() self._choiceRepository = ChoiceRepository() def create(self, choice, poll): choice.uniqueId = self._getUnusedChoiceUuid() choice.poll = poll self._choiceRepository.create(choice) def _getUnusedChoiceUuid(self): for i in range(100): candidateUuid = self._uniqueIdGenerator.createUniqueId() existingChoice = self._choiceRepository.getChoiceByUniqueId(candidateUuid) if existingChoice is None: break return candidateUuid
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
def setUp(self): self.sut = UniqueIdGenerator()
def __init__(self): self._uniqueIdGenerator = UniqueIdGenerator() self._choiceRepository = ChoiceRepository()
def __init__(self): self._uniqueIdGenerator = UniqueIdGenerator() self._choiceFacade = ChoiceFacade() self._pollRepository = PollRepository()