Ejemplo n.º 1
0
def test_poll_repository_vote():
    repo = PollRepository()

    options = ['op1', 'op2']

    repo.add_poll("Name", options)

    assert repo.get_poll(1) == dict(id=1,
                                    name="Name",
                                    options=[{'value': "op1",
                                              'votes': 0},
                                              {'value': "op2",
                                              'votes': 0}])

    repo.vote(1, 1)

    assert repo.get_poll(1)['options'][0]['votes'] == 1
    assert repo.get_poll(1)['options'][1]['votes'] == 0

    repo.vote(1, 1)

    assert repo.get_poll(1)['options'][0]['votes'] == 2
    assert repo.get_poll(1)['options'][1]['votes'] == 0

    repo.vote(1, 2)

    assert repo.get_poll(1)['options'][0]['votes'] == 2
    assert repo.get_poll(1)['options'][1]['votes'] == 1

    with pytest.raises(Exception):
        repo.vote(1, 3)
Ejemplo n.º 2
0
def test_poll_repository_vote():
    repo = PollRepository()

    options = ['op1', 'op2']

    repo.add_poll("Name", options)

    assert repo.get_poll(1) == dict(id=1,
                                    name="Name",
                                    options=[{
                                        'value': "op1",
                                        'votes': 0
                                    }, {
                                        'value': "op2",
                                        'votes': 0
                                    }])

    repo.vote(1, 1)

    assert repo.get_poll(1)['options'][0]['votes'] == 1
    assert repo.get_poll(1)['options'][1]['votes'] == 0

    repo.vote(1, 1)

    assert repo.get_poll(1)['options'][0]['votes'] == 2
    assert repo.get_poll(1)['options'][1]['votes'] == 0

    repo.vote(1, 2)

    assert repo.get_poll(1)['options'][0]['votes'] == 2
    assert repo.get_poll(1)['options'][1]['votes'] == 1

    with pytest.raises(Exception):
        repo.vote(1, 3)
Ejemplo n.º 3
0
def test_poll_repository_get():
    repo = PollRepository()

    repo.add_poll("Name", [])

    assert repo.get_poll(1) == dict(id=1,
                                    name="Name",
                                    options=[])

    repo.add_poll("Name2", ["option1"])

    assert repo.polls[1] == dict(id=2,
                                 name="Name2",
                                 options=[{'value': "option1",
                                           'votes': 0}])
Ejemplo n.º 4
0
def test_poll_repository_get():
    repo = PollRepository()

    repo.add_poll("Name", [])

    assert repo.get_poll(1) == dict(id=1, name="Name", options=[])

    repo.add_poll("Name2", ["option1"])

    assert repo.polls[1] == dict(id=2,
                                 name="Name2",
                                 options=[{
                                     'value': "option1",
                                     'votes': 0
                                 }])