def to_entity(self) -> entity.Choice: return entity.Choice( id=self.id, name=self.name, text=self.text, votes=self.votes )
def test_vote(self, sent): c = entities.Choice( id=uuid4(), name=sent.name, text=sent.text, votes=0 ) assert c.votes == 0 c.vote() assert c.votes == 1
def test_from_entity(self, sent): ent = entity.Choice(id=uuid4(), name=sent.name, text=sent.text, votes=sent.votes) choice = models.Choice.from_entity(ent) assert isinstance(choice, models.Choice) assert choice.id == ent.id assert choice.name == ent.name assert choice.text == ent.text assert choice.votes == ent.votes
def test_copy_from_entity(self, sent): uid = uuid4() ent = entity.Choice(id=uuid4(), name=sent.name, text=sent.text, votes=sent.votes) choice = models.Choice(id=uid, name='NAME', text='TEXT', votes=99) choice.copy_from_entity(ent) assert choice.id is not ent.id assert choice.name == ent.name assert choice.text == ent.text assert choice.votes == ent.votes
def test_dict(self, sent): ch = entities.Choice( id=sent.id, name=sent.name, text=sent.text, votes=sent.votes ) resp = ch.dict() assert resp == { 'id': sent.id, 'name': sent.name, 'text': sent.text, 'votes': sent.votes }
def test_get_choice_by_id(self, mocker, sent): choice_id = uuid4() q = entities.Question( id=uuid4(), name=sent.name, text=sent.text, choices=[ entities.Choice( id=choice_id, name=sent.choice_name, text=sent.choice_text, votes=1 ) ] ) choice = q.get_choice_by_id(choice_id) assert choice.id == choice_id
def __init__(self): super().__init__() self.choices_lookup = {str(ch['id']): ch for ch in repo_data.CHOICES} self.data = { q['id']: entity.Question(id=UUID(q.get('id')), name=q.get('name'), text=q.get('text'), choices=[ entity.Choice( id=choice_dict.get('id'), name=choice_dict.get('name'), text=choice_dict.get('text'), votes=choice_dict.get('votes', 0), ) for choice in q.get('choices', []) if (choice_dict := self.choices_lookup.get( str(choice.get('id')))) ]) for q in repo_data.QUESTIONS }