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
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
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')
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")
def test_comment(): from pgtoolkit.hba import HBAComment comment = HBAComment('# toto') assert 'toto' in repr(comment) assert '# toto' == str(comment)
def test_comment(): from pgtoolkit.hba import HBAComment comment = HBAComment("# toto") assert "toto" in repr(comment) assert "# toto" == str(comment)