|
| 1 | +import pytest |
| 2 | +from commands import command_add, command_del, command_info, command_query, DB, _init_db |
| 3 | + |
| 4 | + |
| 5 | +@pytest.fixture |
| 6 | +def roberto(): |
| 7 | + return [ |
| 8 | + 123, |
| 9 | + 'Roberto', |
| 10 | + 'Nascimento', |
| 11 | + '01/01/1960', |
| 12 | + '+55-21-0190-0190' |
| 13 | + ] |
| 14 | + |
| 15 | + |
| 16 | +@pytest.fixture |
| 17 | +def rosangela(): |
| 18 | + return [ |
| 19 | + 456, |
| 20 | + 'Rosangela', |
| 21 | + 'Nascimento', |
| 22 | + '01/01/1960', |
| 23 | + '+55-21-0190-0190' |
| 24 | + ] |
| 25 | + |
| 26 | + |
| 27 | +def test_command_add(roberto): |
| 28 | + _init_db() |
| 29 | + assert command_add(*roberto) == '' |
| 30 | + |
| 31 | + |
| 32 | +def test_command_add_values(roberto): |
| 33 | + _init_db() |
| 34 | + roberto[0] = 124 |
| 35 | + command_add(*roberto) |
| 36 | + assert len(DB) == 1 |
| 37 | + |
| 38 | + |
| 39 | +def test_command_add_id(roberto): |
| 40 | + _init_db() |
| 41 | + roberto[0] = 125 |
| 42 | + command_add(*roberto) |
| 43 | + assert 125 in DB |
| 44 | + |
| 45 | + |
| 46 | +def test_command_add_same(roberto): |
| 47 | + _init_db() |
| 48 | + assert command_add(*roberto) == '' |
| 49 | + assert command_add(*roberto) == 'ID 123 ja cadastrado.' |
| 50 | + |
| 51 | + |
| 52 | +def test_command_del(roberto): |
| 53 | + _init_db() |
| 54 | + command_add(*roberto) |
| 55 | + assert command_del(123) == '' |
| 56 | + |
| 57 | + |
| 58 | +def test_command_del_not_found_id(): |
| 59 | + _init_db() |
| 60 | + assert command_del(123) == 'ID 123 nao existente.' |
| 61 | + |
| 62 | + |
| 63 | +def test_command_del_2(roberto): |
| 64 | + _init_db() |
| 65 | + command_add(*roberto) |
| 66 | + assert command_del(123) == '' |
| 67 | + assert command_del(123) == 'ID 123 nao existente.' |
| 68 | + |
| 69 | + |
| 70 | +def test_command_info(roberto): |
| 71 | + _init_db() |
| 72 | + command_add(*roberto) |
| 73 | + assert command_info(roberto[0]) == 'Roberto Nascimento 01/01/1960 +55-21-0190-0190' |
| 74 | + |
| 75 | + |
| 76 | +def test_command_info_not_found(): |
| 77 | + _init_db() |
| 78 | + assert command_info(1) == 'ID 1 nao existente.' |
| 79 | + |
| 80 | + |
| 81 | +def test_command_query(roberto): |
| 82 | + _init_db() |
| 83 | + command_add(*roberto) |
| 84 | + assert command_query('fn:Roberto') == '123' |
| 85 | + |
| 86 | + |
| 87 | +def test_command_query_multiple(roberto, rosangela): |
| 88 | + _init_db() |
| 89 | + command_add(*roberto) |
| 90 | + command_add(*rosangela) |
| 91 | + assert command_query('ln:Nascimento') == '123 456' |
| 92 | + |
| 93 | + |
| 94 | +def test_command_query_multiple_unordered(roberto, rosangela): |
| 95 | + _init_db() |
| 96 | + command_add(*rosangela) |
| 97 | + command_add(*roberto) |
| 98 | + assert command_query('ln:Nascimento') == '123 456' |
0 commit comments