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