diff --git a/tests/api_client_test.py b/tests/api_client_test.py index 61c74cc939039dda668e30d35e39d9f1d5274b16..70d0ba8ec92b078eb0fe5ed1fcff1d67a9866573 100644 --- a/tests/api_client_test.py +++ b/tests/api_client_test.py @@ -11,7 +11,9 @@ def test_get_client(mock_clients): app = create_app() with patch( "builtins.open", mock_open(read_data=json.dumps(mock_clients)) - ) as mock_file_open, app.test_client() as app_test_client: + ) as mock_file_open, patch( + "os.path.getmtime", return_value=3 + ) as mock_getmtime, app.test_client() as app_test_client: response = app_test_client.get("/client") assert response.status_code == 200 assert len(response.json.keys()) == 2 @@ -23,7 +25,9 @@ def test_get_client_1(mock_clients): app = create_app() with patch( "builtins.open", mock_open(read_data=json.dumps(mock_clients)) - ) as mock_file_open, app.test_client() as app_test_client: + ) as mock_file_open, patch( + "os.path.getmtime", return_value=3 + ) as mock_getmtime, app.test_client() as app_test_client: response = app_test_client.get("/client/client-1") assert response.status_code == 200 assert "client_id" in response.json @@ -37,7 +41,9 @@ def test_post_client(mock_clients, mock_new_client): app = create_app() with patch( "builtins.open", mock_open(read_data=json.dumps(mock_clients)) - ) as mock_file_open, app.test_client() as app_test_client: + ) as mock_file_open, patch( + "os.path.getmtime", return_value=3 + ) as mock_getmtime, app.test_client() as app_test_client: response = app_test_client.post("/client", json=mock_new_client) assert response.status_code == 201 assert "client_id" in response.json @@ -51,7 +57,9 @@ def test_put_client_1(mock_clients): app = create_app() with patch( "builtins.open", mock_open(read_data=json.dumps(mock_clients)) - ) as mock_file_open, app.test_client() as app_test_client: + ) as mock_file_open, patch( + "os.path.getmtime", return_value=3 + ) as mock_getmtime, app.test_client() as app_test_client: response = app_test_client.get("/client/client-1") client_1 = response.json print(client_1) @@ -71,6 +79,8 @@ def test_delete_client_1(mock_clients): app = create_app() with patch( "builtins.open", mock_open(read_data=json.dumps(mock_clients)) - ) as mock_file_open, app.test_client() as app_test_client: + ) as mock_file_open, patch( + "os.path.getmtime", return_value=3 + ) as mock_getmtime, app.test_client() as app_test_client: response = app_test_client.delete("/client/client-1") assert response.status_code == 204 diff --git a/tests/models/client_model_test.py b/tests/models/client_model_test.py index 4748509cd7b5ae0698242ef65da074e181f4871f..bc01f933e08c348468042c7bb5cc000f87d993a3 100644 --- a/tests/models/client_model_test.py +++ b/tests/models/client_model_test.py @@ -11,7 +11,7 @@ def test_init_with_clients(mock_clients): # File is read on __init__ with patch( "builtins.open", mock_open(read_data=json.dumps(mock_clients)) - ) as mock_file_open: + ) as mock_file_open, patch("os.path.getmtime", return_value=3) as mock_getmtime: clients_file = ClientModel() assert len(clients_file.clients.keys()) == 2 assert "client-1" in clients_file.clients.keys() @@ -19,7 +19,9 @@ def test_init_with_clients(mock_clients): def test_init_no_clients_file(): # Handles FileNotFound on __init__ - with patch("builtins.open", side_effect=FileNotFoundError()) as mock_file_open: + with patch( + "builtins.open", side_effect=FileNotFoundError() + ) as mock_file_open, patch("os.path.getmtime", return_value=3) as mock_getmtime: clients_file = ClientModel() assert len(clients_file.clients.keys()) == 0 assert "client-1" not in clients_file.clients.keys() @@ -52,7 +54,7 @@ def test_get_modified(mock_clients): def test_find_existing(mock_clients): with patch( "builtins.open", mock_open(read_data=json.dumps(mock_clients)) - ) as mock_file_open: + ) as mock_file_open, patch("os.path.getmtime", return_value=3) as mock_getmtime: clients_file = ClientModel() client = clients_file.find("client-1") assert client is not None @@ -63,7 +65,7 @@ def test_find_existing(mock_clients): def test_find_nonexisting(mock_clients): with patch( "builtins.open", mock_open(read_data=json.dumps(mock_clients)) - ) as mock_file_open: + ) as mock_file_open, patch("os.path.getmtime", return_value=3) as mock_getmtime: clients_file = ClientModel() client = clients_file.find("client-3") assert client is None @@ -73,7 +75,7 @@ def test_find_nonexisting(mock_clients): def test_add(mock_clients, mock_new_client): with patch( "builtins.open", mock_open(read_data=json.dumps(mock_clients)) - ) as mock_file_open: + ) as mock_file_open, patch("os.path.getmtime", return_value=3) as mock_getmtime: clients_file = ClientModel() client = clients_file.add(mock_new_client) assert client["client_id"] in clients_file.clients @@ -84,7 +86,7 @@ def test_add(mock_clients, mock_new_client): def test_remove(mock_clients): with patch( "builtins.open", mock_open(read_data=json.dumps(mock_clients)) - ) as mock_file_open: + ) as mock_file_open, patch("os.path.getmtime", return_value=3) as mock_getmtime: clients_file = ClientModel() client = clients_file.find("client-2") clients_file.remove(client) @@ -96,7 +98,7 @@ def test_remove(mock_clients): def test_update(mock_clients): with patch( "builtins.open", mock_open(read_data=json.dumps(mock_clients)) - ) as mock_file_open: + ) as mock_file_open, patch("os.path.getmtime", return_value=3) as mock_getmtime: clients_file = ClientModel() client = clients_file.find("client-1") assert client["subscription"] == "soar.#" @@ -111,7 +113,7 @@ def test_update(mock_clients): def test_save(mock_clients): with patch( "builtins.open", mock_open(read_data=json.dumps(mock_clients)) - ) as mock_file_open: + ) as mock_file_open, patch("os.path.getmtime", return_value=3) as mock_getmtime: clients_file = ClientModel() mock_file_open.assert_any_call("./data/clients.json", "r") clients_file.save() @@ -123,7 +125,7 @@ def test_save(mock_clients): def test_secret(mock_clients): with patch( "builtins.open", mock_open(read_data=json.dumps(mock_clients)) - ) as mock_file_open: + ) as mock_file_open, patch("os.path.getmtime", return_value=3) as mock_getmtime: secret_pattern = "^[A-Za-z0-9]+$" clients_file = ClientModel() secret = clients_file.secret()