Skip to content

TestJsonFileHandler

TestJsonFileHandler

TODO: Very basic test case, build out as we find file parsing edge casess TODO: can create test document subfolder within the testing directory

Source code in dod/TestJsonFileHandler.py
 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
class TestJsonFileHandler:
    '''
    TODO: Very basic test case, build out as we find file parsing edge casess
    TODO: can create test document subfolder within the testing directory
    '''

    def test_file_load(self, capsys):
        # create config parser handler
        json_handler = JsonFileHandler(supported_json)
        # load configs and launch web server 
        json_handler.reload_endpoints()
        expected_resp = {"Position": {
                            "X": 0,
                            "Y": 0,
                            "Z": 500
                        },
                        "LastProbe": "",
                        "Humidity": 10,
                        "Temperature": 228,
                        "BathTemp": -99
                        }

        assert json_handler.get_endpoint_data("/DoD/get/Status") == expected_resp

    def test_file_add_endpoint(self, capsys):
        new_file = "tests/blank_supported.json"

        json_handler = JsonFileHandler(new_file)
        json_handler.create_new_supported_file()

        assert json_handler.get_endpoint_data("/DoD/get/Status") == None
        json_handler.reload_endpoints()

        expected_resp = {"Position": {
                            "X": 0,
                            "Y": 0,
                            "Z": 500
                        },
                        "LastProbe": "",
                        "Humidity": 10,
                        "Temperature": 228,
                        "BathTemp": -99
                        }

        json_handler.add_endpoint("/DoD/get/Status", expected_resp)

        assert json_handler.get_endpoint_data("/DoD/get/Status") == expected_resp
        os.remove(new_file)