-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_load_batch.py
56 lines (39 loc) · 2.02 KB
/
test_load_batch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from NIPTool.commands.load.batch import batch
from NIPTool.server import create_app
from NIPTool.commands.base import cli
from NIPTool.adapter.plugin import NiptAdapter
app = create_app(test=True)
def test_batch_valid_file(database, valid_csv):
app.db = database
app.adapter = NiptAdapter(database.client, db_name=database.name)
# GIVEN a valid csv file with three samples
# WHEN loading the batch file with correct foramted input string
runner = app.test_cli_runner()
result = runner.invoke(cli, ["load", "batch", "-b", valid_csv])
# THEN assert the new apptags should be added to the colleciton
assert app.adapter.sample_collection.estimated_document_count() == 3
assert app.adapter.batch_collection.estimated_document_count() == 1
def test_batch_invalid_file(database, invalid_csv):
app.db = database
app.adapter = NiptAdapter(database.client, db_name=database.name)
# GIVEN a invalid csv file
# WHEN loading the batch file with correct foramted input string
runner = app.test_cli_runner()
result = runner.invoke(cli, ["load", "batch", "-b", invalid_csv])
# THEN assert nothing added to sample or batch collections
# THEN assert Badly formated csv! Can not load. Exiting.
assert app.adapter.sample_collection.estimated_document_count() == 0
assert app.adapter.batch_collection.estimated_document_count() == 0
assert result.exit_code == 1
def test_batch_no_file(database):
app.db = database
app.adapter = NiptAdapter(database.client, db_name=database.name)
# GIVEN a invalid csv file
# WHEN loading the batch file with correct foramted input string
runner = app.test_cli_runner()
result = runner.invoke(cli, ["load", "batch", "-b", "wrong/path"])
# THEN assert nothing added to sample or batch collections
# THEN assert Badly formated csv! Can not load. Exiting.
assert app.adapter.sample_collection.estimated_document_count() == 0
assert app.adapter.batch_collection.estimated_document_count() == 0
assert result.exit_code == 1