Пример #1
0
def test_backup_and_restore(pg):
    with temp_db(pg) as db_name:
        fp = tempfile.NamedTemporaryFile()
        pg.dump(db_name, fp.name)

        pg.drop(db_name)
        assert not pg.exists(db_name)

        fp.seek(0)
        pg.restore(db_name, fp.name)
        assert pg.exists(db_name)
Пример #2
0
def test_temp_db_failed_create():
    class FakeDB(object):
        def create(self, name):
            pass

        def exists(self, name):
            return False

    with pytest.raises(DatabaseError):
        with temp_db(FakeDB()):
            pass
Пример #3
0
def test_backup_and_restore(pg):
    with temp_db(pg) as db_name:
        fp = tempfile.NamedTemporaryFile()
        pg.dump(db_name, fp.name)

        pg.drop(db_name)
        assert not pg.exists(db_name)

        fp.seek(0)
        pg.restore(db_name, fp.name)
        assert pg.exists(db_name)
Пример #4
0
def test_temp_db():
    class FakeStatefulDB(object):
        _exists = False

        def create(self, name):
            self._exists = True

        def drop(self, name):
            self._exists = False

        def exists(self, name):
            return self._exists

    db = FakeStatefulDB()
    with temp_db(db, 'foo') as name:
        assert name == 'foo'
        assert db.exists(name)
    assert not db.exists(name)

    with temp_db(db) as name:
        assert name.startswith('db')
Пример #5
0
def test_temp_db_failed_drop():
    class FakeDB(object):
        _exists = None

        def create(self, name):
            self._exists = True

        def drop(self, name):
            self._exists = True

        def exists(self, name):
            return self._exists

    with pytest.raises(DatabaseError):
        with temp_db(FakeDB()):
            pass