def handle(self, command):
     rangevote = RangeVoteFactory.create_rangevote({
         "id":
         command.uuid,
         "choices":
         command.choices,
         "votes":
         command.votes,
         "question":
         command.question
     })
     self.repository.update(command.uuid, rangevote)
Exemple #2
0
    def test_repository_update(self):
        rangevote_id = uuid.uuid4()
        rangevote = RangeVoteFactory.create_rangevote({
            "id": rangevote_id,
            "choices": ["a", "b"],
            "votes": [{"opinions": {"a": 1, "b": 2}, "elector": "G"}, {"opinions": {"a": 0, "b": 0}, "elector": "C"}],
            'question': 'Q'
        })
        self.repository.save(rangevote)

        updated_rangevote = RangeVoteFactory.create_rangevote({
            "id": rangevote_id,
            "choices": ["a", "b"],
            "votes": [{"opinions": {"a": 1, "b": 2}, "elector": "G"}],
            'question': 'Q?'
        })
        self.repository.update(rangevote_id, updated_rangevote)

        element = self.repository.get(rangevote_id)
        self.assertEqual(updated_rangevote.question, element.question)
        self.assertEqual(len(updated_rangevote.votes), len(element.votes))
Exemple #3
0
    def test_repository_get(self):
        rangevote_id = uuid.uuid4()
        rangevote = RangeVoteFactory.create_rangevote({
            "id": rangevote_id,
            "choices": ["a", "b"],
            "votes": [{"opinions": {"a": 1, "b": 2}, "elector": "G"}, {"opinions": {"a": 0, "b": 0}, "elector": "C"}],
            'question': 'Q'
        })
        self.repository.save(rangevote)

        element = self.repository.get(rangevote_id)

        self.assertTrue(isinstance(element, rangevoting.RangeVote))
        self.assertEqual(rangevote.question, element.question)
        self.assertEqual(rangevote.choices, element.choices)
        self.assertEqual(rangevote.votes[0].elector, element.votes[0].elector)
        self.assertDictEqual(rangevote.votes[0].opinions, element.votes[0].opinions)
    def test_rangevote_factory(self):
        rangevote_dict = {
            "id":
            "f1c9f71e-a6f0-46bf-8cf3-d9b8f01c0005",
            "choices": ["Chinoise", "Italienne", "Française"],
            "votes": [{
                "opinions": {
                    "Chinoise": 1,
                    "Française": 2,
                    "Italienne": 1
                },
                "elector": "Guillaume"
            }, {
                "opinions": {
                    "Chinoise": 0,
                    "Française": 0,
                    "Italienne": 0
                },
                "elector": "Carine"
            }],
            "question":
            "Quel type de cusine préférez vous ?"
        }

        rangevote = RangeVoteFactory.create_rangevote(rangevote_dict)

        self.assertEqual('f1c9f71e-a6f0-46bf-8cf3-d9b8f01c0005',
                         rangevote.uuid)
        self.assertEqual('Quel type de cusine préférez vous ?',
                         rangevote.question)
        self.assertEqual(["Chinoise", "Italienne", "Française"],
                         rangevote.choices)
        self.assertEqual('Guillaume', rangevote.votes[0].elector)
        self.assertEqual("Carine", rangevote.votes[1].elector)
        self.assertEqual({
            "Chinoise": 1,
            "Française": 2,
            "Italienne": 1
        }, rangevote.votes[0].opinions)
        self.assertEqual({
            "Chinoise": 0,
            "Française": 0,
            "Italienne": 0
        }, rangevote.votes[1].opinions)
    def test_rangevote_factory(self):
        rangevote_dict = {
            "id": "f1c9f71e-a6f0-46bf-8cf3-d9b8f01c0005",
            "choices": [
                "Chinoise",
                "Italienne",
                "Française"
            ],
            "votes": [
                {
                    "opinions": {
                        "Chinoise": 1,
                        "Française": 2,
                        "Italienne": 1
                    },
                    "elector": "Guillaume"
                },
                {
                    "opinions": {
                        "Chinoise": 0,
                        "Française": 0,
                        "Italienne": 0
                    },
                    "elector": "Carine"
                }
            ],
            "question": "Quel type de cusine préférez vous ?"
        }

        rangevote = RangeVoteFactory.create_rangevote(rangevote_dict)

        self.assertEqual('f1c9f71e-a6f0-46bf-8cf3-d9b8f01c0005', rangevote.uuid)
        self.assertEqual('Quel type de cusine préférez vous ?', rangevote.question)
        self.assertEqual(["Chinoise", "Italienne", "Française"], rangevote.choices)
        self.assertEqual('Guillaume', rangevote.votes[0].elector)
        self.assertEqual("Carine", rangevote.votes[1].elector)
        self.assertEqual({"Chinoise": 1, "Française": 2, "Italienne": 1}, rangevote.votes[0].opinions)
        self.assertEqual({"Chinoise": 0, "Française": 0, "Italienne": 0}, rangevote.votes[1].opinions)
 def handle(self, command):
     rangevote = RangeVoteFactory.create_rangevote({
         "id": command.uuid, "choices": command.choices, "votes": command.votes, "question": command.question
     })
     self.repository.update(command.uuid, rangevote)