未验证 提交 58a71a48 编写于 作者: K Kirill Sizov 提交者: GitHub

Fix REST API tests (#4279)

* Conftest: check values instead of keys

* Rename SQL script for db restoring

* Use SQL dump file instead of custom format

* Use SQL dump file instead of custom format

* Update README

* Conftest: fix scope for restore_db
上级 61787ce7
......@@ -63,7 +63,7 @@ for i, color in enumerate(colormap):
To backup DB and data volume, please use commands below.
```console
docker exec cvat_db pg_dump -c -C -Fc -U root -d cvat > assets/cvat_db.dump
docker exec cvat_db pg_dump -c -Fp -U root -d cvat > assets/cvat_db/cvat_db.sql
docker run --rm --volumes-from cvat ubuntu tar -cjv /home/django/data > assets/cvat_data.tar.bz2
```
......@@ -81,7 +81,7 @@ python utils/dump_objects.py
To restore DB and data volume, please use commands below.
```console
cat assets/cvat_db/cvat_db.dump | docker exec -i cvat_db pg_restore -1 -c -U root -d cvat
cat assets/cvat_db/cvat_db.sql | docker exec -i cvat_db psql -U root -d cvat
cat assets/cvat_data.tar.bz2 | docker run --rm -i --volumes-from cvat ubuntu tar -xj --strip 3 -C /home/django/data
```
......@@ -93,7 +93,7 @@ cat assets/cvat_data.tar.bz2 | docker run --rm -i --volumes-from cvat ubuntu tar
you have json description of all objects together with cvat_db.sql, it will
be possible to recreate them manually.
1. How to upgrade cvat_data.tar.bz2 and cvat_db.dump?
1. How to upgrade cvat_data.tar.bz2 and cvat_db.sql?
After every commit which changes the layout of DB and data directory it is
possible to break these files. But failed tests should be a clear indicator
......
SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'cvat' AND pid <> pg_backend_pid();
DROP DATABASE cvat;
CREATE DATABASE cvat WITH TEMPLATE test_db;
\ No newline at end of file
......@@ -20,15 +20,18 @@ def restore_data_volume():
'--strip 3 -C /home/django/data -xjf /mnt/cvat_data.tar.bz2'
run(command.split(), check=True) #nosec
def restore_cvat_db():
cvat_db_container('psql -U root -d postgres -f /cvat_db/restore_db.sql')
def drop_test_db():
cvat_db_container('pg_restore -c -U root -d cvat /cvat_db/cvat_db.dump')
restore_cvat_db()
cvat_db_container('rm -rf /cvat_db')
cvat_db_container('dropdb test_db')
def create_test_db():
docker_cp(source=osp.join(ASSETS_DIR, 'cvat_db'), target='cvat_db:/')
cvat_db_container('createdb test_db')
cvat_db_container('pg_restore -U root -d test_db /cvat_db/cvat_db.dump')
cvat_db_container('psql -U root -d test_db -f /cvat_db/cvat_db.sql')
@pytest.fixture(scope='session', autouse=True)
def init_test_db():
......@@ -44,8 +47,8 @@ def init_test_db():
drop_test_db()
@pytest.fixture(scope='function', autouse=True)
def restore_cvat_db():
cvat_db_container('psql -U root -d postgres -f /cvat_db/cvat_db.sql')
def restore():
restore_cvat_db()
@pytest.fixture(scope='module')
def users():
......@@ -77,7 +80,7 @@ def users_by_name(users):
def find_users(test_db):
def find(**kwargs):
assert len(kwargs) > 0
assert any(kwargs)
assert any(kwargs.values())
data = test_db
kwargs = dict(filter(lambda a: a[1] is not None, kwargs.items()))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册