-
Notifications
You must be signed in to change notification settings - Fork 5
/
test_api_parser.py
executable file
·66 lines (57 loc) · 2.63 KB
/
test_api_parser.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
57
58
59
60
61
62
63
64
65
66
from webapp.apps.users.models import Project
from webapp.apps.comp.model_parameters import ModelParameters
from webapp.apps.comp.ioutils import get_ioutils
from webapp.apps.comp.models import Inputs
from webapp.apps.comp.tests.parser import LocalAPIParser
def test_api_parser(db, get_inputs, valid_meta_params):
class MockMp(ModelParameters):
def get_inputs(self, meta_parameters=None):
return get_inputs
project = Project.objects.get(title="Used-for-testing")
ioutils = get_ioutils(project, ModelParameters=MockMp, Parser=LocalAPIParser)
ioutils.model_parameters.init_meta_parameters = valid_meta_params
clean_inputs = {
"majorsection1": {"intparam": 3, "boolparam": True},
"majorsection2": {"mj2param": 4},
}
parser = LocalAPIParser(
project, ioutils.model_parameters, clean_inputs, **valid_meta_params
)
res = parser.parse_parameters()
adjustment = res["adjustment"]
errors_warnings = res["errors_warnings"]
assert adjustment == {
"majorsection1": {"intparam": 3, "boolparam": True},
"majorsection2": {"mj2param": 4},
}
exp_errors_warnings = {"errors": {}, "warnings": {}}
assert errors_warnings["majorsection1"] == exp_errors_warnings
assert errors_warnings["majorsection2"] == exp_errors_warnings
assert errors_warnings["API"] == exp_errors_warnings
assert errors_warnings["GUI"] == exp_errors_warnings
def test_api_parser_extra_section(db, get_inputs, valid_meta_params):
class MockMp(ModelParameters):
def get_inputs(self, meta_parameters=None):
return get_inputs
project = Project.objects.get(title="Used-for-testing")
ioutils = get_ioutils(project, ModelParameters=MockMp, Parser=LocalAPIParser)
ioutils.model_parameters.init_meta_parameters = valid_meta_params
clean_inputs = {
"majorsection1-mispelled": {"intparam": 3, "boolparam": True},
"majorsection2": {"mj2param": 4},
}
parser = LocalAPIParser(
project, ioutils.model_parameters, clean_inputs, **valid_meta_params
)
res = parser.parse_parameters()
adjustment = res["adjustment"]
errors_warnings = res["errors_warnings"]
assert adjustment == {"majorsection1": {}, "majorsection2": {"mj2param": 4}}
exp_errors_warnings = {"errors": {}, "warnings": {}}
assert errors_warnings["majorsection1"] == exp_errors_warnings
assert errors_warnings["majorsection2"] == exp_errors_warnings
assert errors_warnings["API"] == {
"errors": {"extra_keys": ["Has extra sections: majorsection1-mispelled"]},
"warnings": {},
}
assert errors_warnings["GUI"] == exp_errors_warnings