예제 #1
0
 def to_entity(self) -> entity.Question:
     return entity.Question(
         id=self.id,
         name=self.name,
         text=self.text,
         choices=[ch.to_entity() for ch in self.choices.all()]
     )
예제 #2
0
def polls_add():
    post = request.form
    question: entity.Question = entity.Question(  # Need adapter for it
        id=UUID(post.get('id')),
        name=post.get('name'),
        text=post.get('text'),
    )
    uc = use_cases.PollAddUseCase(repo_instances.poll_repo)
    uc.execute(question)

    return jsonify(question)
예제 #3
0
    def test_from_entity(self, sent):
        ent = entity.Question(id=uuid4(),
                              name=sent.name,
                              text=sent.text,
                              choices=[])
        question = models.Question.from_entity(ent)

        assert isinstance(question, models.Question)
        assert question.id == ent.id
        assert question.name == ent.name
        assert question.text == ent.text
예제 #4
0
    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
예제 #5
0
    def test_dict(self, mocker, sent):
        m_choice = mocker.Mock()
        m_choice.dict.return_value = sent.choice
        q = entities.Question(
            id=sent.id,
            name=sent.name,
            text=sent.text,
            choices=[m_choice],
        )

        resp = q.dict()

        assert resp == {
            'id': sent.id,
            'name': sent.name,
            'text': sent.text,
            'choices': [sent.choice]
        }
예제 #6
0
    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
        }