Пример #1
0
def test_rows_replaced_no_attr(create_db):
    london = et.XML('<replace>'
                    '<name old="Greater London">The Metropolis</name>'
                    '</replace>')

    with db.engine.begin() as connection, \
            pytest.raises(ValueError, match="Each <replace> element requires"):
        _replace_row(connection, models.Region, london)
Пример #2
0
def test_rows_replaced(load_db, caplog):
    london = et.XML('<replace code="L">'
                    '<name old="Greater London">The Metropolis</name>'
                    '</replace>')

    with db.engine.begin() as connection:
        _replace_row(connection, models.Region, london)

    regions = models.Region.query.order_by("code").all()
    assert [(r.code, r.name) for r in regions] == [("GB", "Great Britain"),
                                                   ("L", "The Metropolis")]
Пример #3
0
def test_row_replaced_no_match(load_db, caplog):
    london = et.XML('<replace code="Y">'
                    '<name old="Yorkshire">Greater Yorkshire</name>'
                    '</replace>')

    with db.engine.begin() as connection:
        _replace_row(connection, models.Region, london)

    log = (LOGGER, logging.WARNING,
           "Region: No rows matching {'code': 'Y'} found.")
    assert log in caplog.record_tuples

    regions = models.Region.query.order_by("code").all()
    assert [(r.code, r.name) for r in regions] == [("GB", "Great Britain"),
                                                   ("L", "Greater London")]
Пример #4
0
def test_row_replaced_same_value(load_db, caplog):
    london = et.XML('<replace code="L">'
                    '<name old="London">Greater London</name>'
                    '</replace>')

    with db.engine.begin() as connection:
        _replace_row(connection, models.Region, london)

    log = (LOGGER, logging.WARNING,
           "Region: name 'Greater London' for {'code': 'L'} already matches.")
    assert log in caplog.record_tuples

    regions = models.Region.query.order_by("code").all()
    assert [(r.code, r.name) for r in regions] == [("GB", "Great Britain"),
                                                   ("L", "Greater London")]