def test_change_app_config_properly(self, config_rollback, app_config): client, config_sample_path = config_rollback body = app_config response = client.put("/app", json=body) expected_response = get_app_from_config_file(config_sample_path) assert response.status_code == 200 assert response.json() == expected_response
def test_get_app_config(self, config_rollback): client, config_sample_path = config_rollback response = client.get("/app") expected_response = get_app_from_config_file(config_sample_path) assert response.status_code == 200 assert response.json() == expected_response
def test_try_change_app_config_wrong_type_variable_all( self, config_rollback, key_value_dict, correct_type): """ It is important to mention, the fact that if pydantic expects a string, it will try to cast what was sent, so if we send a bool or an integer to a string field, the field will be valid: Example: a = bool or integer -> str(a) Pydantic will accept it and PUT request will work. Same happens when we send bool, and an integer is expected. int(False) -> 0 int(True) -> 1 """ client, config_sample_path = config_rollback body = create_app_config(key_value_dict) response = client.put("/app", json=body) if correct_type == "string": assert response.status_code == 200 expected_response = get_app_from_config_file(config_sample_path) key = list(key_value_dict.keys())[0] value = list(key_value_dict.values())[0] expected_response[key] = str(value) assert response.json() == expected_response elif correct_type == "integer": for key, value in key_value_dict.items(): if isinstance(key_value_dict[key], str): assert response.status_code == 400 assert response.json( )["detail"][0]["type"] == "type_error." + correct_type else: assert response.status_code == 200 expected_response = get_app_from_config_file( config_sample_path) assert response.json() == expected_response elif correct_type == "bool": assert response.status_code == 400 assert response.json( )["detail"][0]["type"] == "type_error." + "bool" else: assert response.status_code == 400
def test_try_change_app_config_empty_json(self, config_rollback): client, config_sample_path = config_rollback body = {} response = client.put("/app", json=body) expected_response = get_app_from_config_file(config_sample_path) default_response = expected_response_default() assert response.status_code == 200 assert response.json() == expected_response assert response.json() == default_response
def test_try_change_app_config_non_existence_key(self, config_rollback): client, config_sample_path = config_rollback # Extra keys are ignored body = { "invalid_1": "example_1", "invalid_2": "example_2", "invalid_3": "example_3" } response = client.put("/app", json=body) expected_response = get_app_from_config_file(config_sample_path) default_response = expected_response_default() assert response.status_code == 200 assert response.json() == expected_response assert response.json() == default_response