Skip to content

Commit

Permalink
Removed get_commit_id() function
Browse files Browse the repository at this point in the history
  • Loading branch information
SarahJohnsonONS committed Aug 16, 2024
1 parent 3527fe9 commit 6650ed9
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 28 deletions.
2 changes: 1 addition & 1 deletion dpytools/http/dataset/base_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ def post_json(self, json_data: Dict) -> Response:
)
return response
except RequestException as e:
logger.error("Failed to send POST request", exc_info=e)
logger.error("Failed to send POST request", error=e)
raise
2 changes: 1 addition & 1 deletion dpytools/http/dataset/dataset_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def upload_json(self, file_path: Union[Path, str]) -> None:
json_data = json.load(file)
self.post_json(json_data)
except RequestException as e:
logger.error(f"Failed to upload JSON data: {e}")
logger.error(f"Failed to upload JSON data: {e}", e)
raise

def post_new_job(self, payload=None) -> None:
Expand Down
2 changes: 1 addition & 1 deletion dpytools/http/upload/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from math import ceil
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import Optional, Union
from typing import Optional


def _generate_upload_params(file_path: Path, mimetype: str, chunk_size: int) -> dict:
Expand Down
3 changes: 1 addition & 2 deletions dpytools/logging/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import structlog

from dpytools.logging.utility import create_error_dict, get_commit_ID, level_to_severity
from dpytools.logging.utility import create_error_dict, level_to_severity


class DpLogger:
Expand Down Expand Up @@ -59,7 +59,6 @@ def _log(
):
data_dict = data if data is not None else {}
data_dict["level"] = logging.getLevelName(level)
data_dict["commit_ID"] = get_commit_ID()

# match dp logging structue
# https://github.com/ONSdigital/dp-standards/blob/main/LOGGING_STANDARDS.md
Expand Down
8 changes: 0 additions & 8 deletions dpytools/logging/utility.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import subprocess
import sys
import traceback
from typing import Dict, List
Expand Down Expand Up @@ -51,10 +50,3 @@ def create_error_dict(error: Exception) -> List[Dict]:

# Listify in keeping with expected DP logging structures
return [error_dict]

def get_commit_ID():
try:
commit_id=subprocess.check_output(["git", "log", "-1", "--format=%H"]).strip().decode("utf-8")
return commit_id
except subprocess.CalledProcessError as err:
raise err
7 changes: 4 additions & 3 deletions dpytools/stores/directory/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
class LocalDirectoryStore(BaseWritableSingleDirectoryStore):
"""
A class representing a directory store that is available locally.
Provides access to several functions related to retrieving, saving,
Provides access to several functions related to retrieving, saving,
getting information and performing regex pattern matching on files
in a given directory that has a path.
"""

def __init__(self, local_dir: Union[str, Path]):
# Takes a path or a string representing a path as input

Expand Down Expand Up @@ -115,8 +116,8 @@ def save_lone_file_matching(

def get_lone_matching_json_as_dict(self, pattern: str) -> dict:
"""
Asserts the directory has one file matching the pattern,
then loads its contents into a json object and returns it
Asserts the directory has one file matching the pattern,
then loads its contents into a json object and returns it
as a dictionary.
"""
# Assert 1 file matches
Expand Down
2 changes: 1 addition & 1 deletion tests/config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_config_loader(monkeypatch):
# Assigning environment variable values for config dictionary values
monkeypatch.setenv("SOME_STRING_ENV_VAR", "Some string value")
monkeypatch.setenv("SOME_URL_ENV_VAR", "https://test.com/some-url")
monkeypatch.setenv("SOME_INT_ENV_VAR", 6)
monkeypatch.setenv("SOME_INT_ENV_VAR", "6")

config_dictionary = {
"SOME_STRING_ENV_VAR": {
Expand Down
10 changes: 8 additions & 2 deletions tests/email/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ def test_ses_client_initialisation_invalid_sender_email():
with pytest.raises(ValueError) as e:
SesClient("invalid_email", "us-west-2")

assert "Invalid sender email: An email address must have an @-sign." in str(e.value)
assert (
"Invalid sender email: The email address is not valid. It must have exactly one @-sign."
in str(e.value)
)


@mock_aws
Expand All @@ -60,7 +63,10 @@ def test_ses_client_send_invalid_recipient(mock_ses_client):
with pytest.raises(ValueError) as e:
mock_ses_client.send("invalid_email", "subject", "body")

assert "Invalid recipient email: An email address must have an @-sign." in str(e.value)
assert (
"Invalid recipient email: The email address is not valid. It must have exactly one @-sign."
in str(e.value)
)


@mock_aws
Expand Down
2 changes: 1 addition & 1 deletion tests/http/dataset/test_dataset_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from unittest.mock import MagicMock, mock_open, patch

import pytest
from requests import HTTPError, RequestException, Response
from requests import Response

from dpytools.http.dataset.base_api import BaseAPIClient
from dpytools.http.dataset.dataset_api_client import DatasetAPIClient
Expand Down
12 changes: 4 additions & 8 deletions tests/http/test_token_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_set_user_tokens():
"Authorization": "test_auth_token",
"ID": "test_id_token",
}
with patch.object(TokenAuth, "post", return_value=mock_response) as mock_post:
with patch.object(TokenAuth, "post", return_value=mock_response):
token_auth = TokenAuth()
token_auth.set_user_tokens()
assert token_auth.auth_token == "test_auth_token"
Expand Down Expand Up @@ -69,7 +69,7 @@ def test_get_auth_header_with_user_token():
"Authorization": "test_auth_token",
"ID": "test_id_token",
}
with patch.object(TokenAuth, "post", return_value=mock_response) as mock_post:
with patch.object(TokenAuth, "post", return_value=mock_response):
token_auth = TokenAuth()
token_auth.set_user_tokens()
header = token_auth.get_auth_header()
Expand Down Expand Up @@ -109,13 +109,9 @@ def test_refresh_user_token_failure():
os.environ["IDENTITY_API_URL"] = "http://test_url"
mock_response = MagicMock()
mock_response.status_code = 400
with patch.object(
TokenAuth, "put", return_value=mock_response
) as mock_put, patch.object(
with patch.object(TokenAuth, "put", return_value=mock_response), patch.object(
TokenAuth, "post", return_value=mock_response
), patch.object(
TokenAuth, "set_user_tokens"
):
), patch.object(TokenAuth, "set_user_tokens"):
token_auth = TokenAuth()
# Manually set the necessary attributes
token_auth.refresh_token = "test_refresh_token"
Expand Down

0 comments on commit 6650ed9

Please sign in to comment.