Beispiel #1
0
def test_parse_file(mocker):
    from pgtoolkit.hba import parse, HBAComment

    m = mocker.mock_open()
    try:
        mocker.patch('builtins.open', m)
    except Exception:
        mocker.patch('__builtin__.open', m)
    pgpass = parse('filename')
    pgpass.lines.append(HBAComment('# Something'))

    assert m.called
    pgpass.save()
    handle = m()
    handle.write.assert_called_with('# Something\n')

    # Also works for other string types
    m.reset_mock()
    pgpass = parse(u'filename')
    pgpass.lines.append(HBAComment('# Something'))
    assert m.called
Beispiel #2
0
def test_parse_file(mocker):
    from pgtoolkit.hba import HBAComment, parse

    m = mocker.mock_open()
    try:
        mocker.patch("builtins.open", m)
    except Exception:
        mocker.patch("__builtin__.open", m)
    pgpass = parse("filename")
    pgpass.lines.append(HBAComment("# Something"))

    assert m.called
    pgpass.save()
    handle = m()
    handle.write.assert_called_with("# Something\n")

    # Also works for other string types
    m.reset_mock()
    pgpass = parse("filename")
    pgpass.lines.append(HBAComment("# Something"))
    assert m.called
Beispiel #3
0
def test_hba_create():
    from pgtoolkit.hba import HBA, HBAComment, HBARecord

    hba = HBA([
        HBAComment('# a comment'),
        HBARecord(
            conntype='local', database='all', user='******', method='trust',
        ),
    ])
    assert 2 == len(hba.lines)

    r = hba.lines[1]
    assert ['all'] == r.databases

    # Should be a list
    with pytest.raises(ValueError):
        HBA('blah')
Beispiel #4
0
def test_hba_create():
    from pgtoolkit.hba import HBA, HBAComment, HBARecord

    hba = HBA([
        HBAComment("# a comment"),
        HBARecord(
            conntype="local",
            database="all",
            user="******",
            method="trust",
        ),
    ])
    assert 2 == len(hba.lines)

    r = hba.lines[1]
    assert ["all"] == r.databases

    # Should be a list
    with pytest.raises(ValueError):
        HBA("blah")
Beispiel #5
0
def test_comment():
    from pgtoolkit.hba import HBAComment

    comment = HBAComment('# toto')
    assert 'toto' in repr(comment)
    assert '# toto' == str(comment)
Beispiel #6
0
def test_comment():
    from pgtoolkit.hba import HBAComment

    comment = HBAComment("# toto")
    assert "toto" in repr(comment)
    assert "# toto" == str(comment)