Esempio n. 1
0
def get_data():
    filename: str = "test_1.json"
    try:
        result: dict = open_json(filename)
    except Exception as e:
        # print(e)
        logger.error(e)
Esempio n. 2
0
 def test_open_json_no_file(self):
     file_named = "no_file_name.json"
     # result = open_json(file_named)
     m = mock.Mock()
     m.side_effect = Exception(open_json(file_named))
     try:
         m()
     except Exception:
         assert True
Esempio n. 3
0
def dir_list():
    directory: str = "json"
    try:
        directory_list: list = get_data_directory_list(directory)
    except Exception as e:
        print(e)

    try:
        for i in directory_list:
            result: dict = open_json(i)
            count = 0
            for n in result:
                x = n["name"]
                print(x)
                count += 1
            print(count)
    except Exception as e:
        logger.error(e)
Esempio n. 4
0
def call_api():
    """ call test-api to fetch fake users.  """
    # TODO: Consider changing to encode/httpx when stable https://github.com/encode/httpx

    try:
        # test-api is built with FastAPI (https://fastapi.tiangolo.com), which is built on top of Starlette
        r = requests.get(
            "https://test-api.devsetgo.com/api/v1/users/list?qty=500",
            timeout=2)
        logger.info(
            f"API Call Status Code: {r.status_code} from test-api.devsetgo.com"
        )
        resp = r.json()
        obj = resp["users"]

        logger.info(f"serving test-api response {obj}")
        return obj
    except Exception as e:
        logger.error(f"error: API was non-responsive: {e}")
        obj = open_json("sample_people.json")
        logger.info(f"serving sample.json due to API non-response")
        return obj
Esempio n. 5
0
 def test_open_json(self):
     file_named = "test_1.json"
     result = open_json(file_named)
     assert len(result) > 1
     assert isinstance(result, (list, dict))
 def test_open_json_exception_slash_linux(self):
     file_named = "//this_is_not_right_json"
     with pytest.raises(Exception):
         assert open_json(file_named)
 def test_open_json_exception_not_str(self):
     file_named = ["a", "list"]
     with pytest.raises(Exception):
         assert open_json(file_named)
 def test_open_json_no_file(self):
     file_named = "no_file_name.json"
     with pytest.raises(Exception):
         assert open_json(file_named)
 def test_open_json_exception_slash_win(self):
     file_named = "\this_is_not_right_json"
     with pytest.raises(Exception):
         result = open_json(file_named)
         assert result is None
Esempio n. 10
0
 def test_open_json_exception_not_str(self):
     file_named = ["a", "list"]
     with pytest.raises(Exception):
         result = open_json(file_named)
         assert result is None
Esempio n. 11
0
 def test_open_json_no_file(self):
     file_named = "no_file_name.json"
     with pytest.raises(Exception):
         result = open_json(file_named)
         assert result is None