|
import pytest |
|
|
|
|
|
class Test_parse_one_row: |
|
@pytest.fixture |
|
def target(self): |
|
from saying_migrate import parse_one_row |
|
|
|
return parse_one_row |
|
|
|
def test_ok(self, target): |
|
data = 'user001: "text001"' |
|
expected = '"text001"' |
|
result = target(data) |
|
assert result == expected |
|
|
|
def test_empty_data(self, target): |
|
data = "" |
|
|
|
with pytest.raises(AttributeError) as excinfo: |
|
target(data) |
|
assert excinfo.value == "Empty Text" |
|
|
|
def test_invalid_data(self, target): |
|
data = "invalid_data" |
|
|
|
with pytest.raises(AttributeError) as excinfo: |
|
target(data) |
|
assert excinfo.value == "Invalid Text: invalid_data" |
|
|
|
|
|
class Test_parse_saying_list: |
|
@pytest.fixture |
|
def target(self): |
|
from saying_migrate import parse_saying_list |
|
|
|
return parse_saying_list |
|
|
|
@pytest.mark.parametrize( |
|
"data, expected", [(["text001", "text002"], ["", ""]), (["text001", ""], [""])] |
|
) |
|
def test_ok(self, target, mocker, data, expected): |
|
mocker.patch("saying_migrate.parse_one_row", return_value="") |
|
result = target(data) |
|
assert result == expected |
|
|
|
|
|
class Test_generate_register_text_command: |
|
@pytest.fixture |
|
def target(self): |
|
from saying_migrate import generate_register_text_command |
|
|
|
return generate_register_text_command |
|
|
|
def test_ok(self, target): |
|
to_saying = "user001" |
|
text = "text001" |
|
expected = "!user001 text001" |
|
result = target(to_saying, text) |
|
assert result == expected |
|
|
|
|
|
class Test_generate_remove_text_command: |
|
@pytest.fixture |
|
def target(self): |
|
from saying_migrate import generate_remove_text_command |
|
|
|
return generate_remove_text_command |
|
|
|
def test_ok(self, target): |
|
from_saying = "user001" |
|
text = "text001" |
|
expected = "!user001_delete text001" |
|
result = target(from_saying, text) |
|
assert result == expected |
|
|
|
|
|
class Test_generate_migrate_commands: |
|
@pytest.fixture |
|
def target(self): |
|
from saying_migrate import generate_migrate_commands |
|
|
|
return generate_migrate_commands |
|
|
|
def test_ok(self, target, mocker): |
|
from_saying = "user001" |
|
to_saying = "user002" |
|
texts = ["text001", "text002"] |
|
expected = ["register", "remove", "register", "remove"] |
|
|
|
mocker.patch( |
|
"saying_migrate.parse_saying_list", return_value=["parsed001", "parsed002"] |
|
) |
|
mocker.patch( |
|
"saying_migrate.generate_register_text_command", return_value="register" |
|
) |
|
mocker.patch( |
|
"saying_migrate.generate_remove_text_command", return_value="remove" |
|
) |
|
|
|
result = list(target(from_saying, to_saying, texts)) |
|
assert result == expected |