|
1 | 1 | from diglab_utils.test_utils import (test_directory, initialize_test_dir) |
2 | | -from elab_bridge.server_interface import (download_experiment, upload_template, upload_experiment) |
| 2 | +from elab_bridge.server_interface import (download_experiment, upload_template, upload_experiment, |
| 3 | + delete_template, delete_experiment) |
3 | 4 |
|
4 | 5 | SERVER_CONFIG_YAML = (test_directory / 'testfiles_elab' / 'TestProject' / 'project.json').resolve() |
5 | 6 |
|
6 | 7 |
|
7 | 8 | def test_upload_template(initialize_test_dir): |
8 | 9 | template_file = test_directory / 'testfiles_elab' / 'template.json' |
9 | | - template = upload_template(server_config_json=SERVER_CONFIG_YAML, |
10 | | - template_file=template_file, |
11 | | - template_title='Testproject') |
| 10 | + template, template_id = upload_template(server_config_json=SERVER_CONFIG_YAML, |
| 11 | + template_file=template_file, |
| 12 | + template_title='Testproject') |
12 | 13 |
|
13 | 14 | assert 'elabftw' in template |
14 | 15 | assert 'extra_fields' in template |
15 | 16 |
|
| 17 | + # cleanup |
| 18 | + delete_template(server_config_json=SERVER_CONFIG_YAML, template_id=template_id) |
| 19 | + |
16 | 20 |
|
17 | 21 | def test_upload_experiment(initialize_test_dir): |
18 | 22 | template_file = test_directory / 'testfiles_elab' / 'experiment.json' |
19 | 23 |
|
20 | | - experiment = upload_experiment(server_config_json=SERVER_CONFIG_YAML, |
21 | | - experiment_file=template_file, |
22 | | - experiment_title='TestExperiment') |
| 24 | + experiment, experiment_id = upload_experiment(server_config_json=SERVER_CONFIG_YAML, |
| 25 | + experiment_file=template_file, |
| 26 | + experiment_title='TestExperiment') |
23 | 27 |
|
24 | 28 | assert 'extra_fields' in experiment |
25 | 29 |
|
| 30 | + # cleanup |
| 31 | + delete_experiment(server_config_json=SERVER_CONFIG_YAML, experiment_id=experiment_id) |
| 32 | + |
26 | 33 |
|
27 | 34 | def test_download_experiment(initialize_test_dir): |
28 | 35 | json_file = test_directory / 'testfiles_elab' / 'downloaded_experiment.json' |
| 36 | + upload_experiment_file = test_directory / 'testfiles_elab' / 'experiment.json' |
| 37 | + upload, experiment_id = upload_experiment(server_config_json=SERVER_CONFIG_YAML, |
| 38 | + experiment_file=upload_experiment_file, |
| 39 | + experiment_title='UploadExperiment') |
| 40 | + |
29 | 41 | experiment = download_experiment(save_to=json_file, |
30 | 42 | server_config_json=SERVER_CONFIG_YAML, |
31 | | - experiment_id=232, |
| 43 | + experiment_id=experiment_id, |
32 | 44 | format='json') |
33 | 45 |
|
| 46 | + assert len(upload) == len(experiment) |
| 47 | + assert upload == experiment |
| 48 | + |
34 | 49 | assert json_file.exists() |
35 | 50 | assert 'extra_fields' in experiment |
36 | 51 |
|
37 | 52 | # cleanup |
| 53 | + delete_experiment(server_config_json=SERVER_CONFIG_YAML, experiment_id=experiment_id) |
38 | 54 | json_file.unlink() |
0 commit comments