Skip to content

Commit 64f9335

Browse files
committed
refactor(toggl): remove extra helper functions
1 parent fbbd784 commit 64f9335

File tree

2 files changed

+10
-46
lines changed

2 files changed

+10
-46
lines changed

compiler_admin/services/toggl.py

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,6 @@ def detailed_time_entries(self, start_date: datetime, end_date: datetime, **kwar
130130
return response
131131

132132

133-
def _harvest_client_name():
134-
"""Gets the value of the HARVEST_CLIENT_NAME env var."""
135-
return os.environ.get("HARVEST_CLIENT_NAME")
136-
137-
138133
def _get_info(obj: dict, key: str, env_key: str):
139134
"""Read key from obj, populating obj once from a file path at env_key."""
140135
if obj == {}:
@@ -145,19 +140,6 @@ def _get_info(obj: dict, key: str, env_key: str):
145140
return obj.get(key)
146141

147142

148-
def _toggl_api_token():
149-
"""Gets the value of the TOGGL_API_TOKEN env var."""
150-
return os.environ.get("TOGGL_API_TOKEN")
151-
152-
153-
def _toggl_client_id():
154-
"""Gets the value of the TOGGL_CLIENT_ID env var."""
155-
client_id = os.environ.get("TOGGL_CLIENT_ID")
156-
if client_id:
157-
return int(client_id)
158-
return None
159-
160-
161143
def _toggl_project_info(project: str):
162144
"""Return the cached project for the given project key."""
163145
return _get_info(PROJECT_INFO, project, "TOGGL_PROJECT_INFO")
@@ -168,11 +150,6 @@ def _toggl_user_info(email: str):
168150
return _get_info(USER_INFO, email, "TOGGL_USER_INFO")
169151

170152

171-
def _toggl_workspace():
172-
"""Gets the value of the TOGGL_WORKSPACE_ID env var."""
173-
return os.environ.get("TOGGL_WORKSPACE_ID")
174-
175-
176153
def _get_first_name(email: str) -> str:
177154
"""Get cached first name or derive from email."""
178155
user = _toggl_user_info(email)
@@ -228,7 +205,7 @@ def convert_to_harvest(
228205
None. Either prints the resulting CSV data or writes to output_path.
229206
"""
230207
if client_name is None:
231-
client_name = _harvest_client_name()
208+
client_name = os.environ.get("HARVEST_CLIENT_NAME")
232209

233210
# read CSV file, parsing dates and times
234211
source = files.read_csv(source_path, usecols=INPUT_COLUMNS, parse_dates=["Start date"], cache_dates=True)
@@ -279,11 +256,14 @@ def download_time_entries(
279256
Returns:
280257
None. Either prints the resulting CSV data or writes to output_path.
281258
"""
282-
if ("client_ids" not in kwargs or not kwargs["client_ids"]) and isinstance(_toggl_client_id(), int):
283-
kwargs["client_ids"] = [_toggl_client_id()]
284-
285-
token = _toggl_api_token()
286-
workspace = _toggl_workspace()
259+
env_client_id = os.environ.get("TOGGL_CLIENT_ID")
260+
if env_client_id:
261+
env_client_id = int(env_client_id)
262+
if ("client_ids" not in kwargs or not kwargs["client_ids"]) and isinstance(env_client_id, int):
263+
kwargs["client_ids"] = [env_client_id]
264+
265+
token = os.environ.get("TOGGL_API_TOKEN")
266+
workspace = os.environ.get("TOGGL_WORKSPACE_ID")
287267
toggl = Toggl(token, workspace)
288268

289269
response = toggl.detailed_time_entries(start_date, end_date, **kwargs)

tests/services/test_toggl.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
PROJECT_INFO,
1818
USER_INFO,
1919
Toggl,
20-
_harvest_client_name,
2120
_get_info,
2221
_toggl_project_info,
2322
_toggl_user_info,
@@ -46,11 +45,6 @@ def spy_files(mocker):
4645
return mocker.patch.object(compiler_admin.services.toggl, "files", wraps=files)
4746

4847

49-
@pytest.fixture
50-
def mock_harvest_client_name(mocker):
51-
return mocker.patch(f"{MODULE}._harvest_client_name")
52-
53-
5448
@pytest.fixture
5549
def mock_get_info(mocker):
5650
return mocker.patch(f"{MODULE}._get_info")
@@ -169,14 +163,6 @@ def test_toggl_detailed_time_entries_dynamic_timeout(mock_requests, toggl):
169163
assert mock_requests.post.call_args.kwargs["timeout"] == 30
170164

171165

172-
def test_harvest_client_name(monkeypatch):
173-
assert _harvest_client_name() == "Test_Client"
174-
175-
monkeypatch.setenv("HARVEST_CLIENT_NAME", "New Test Client")
176-
177-
assert _harvest_client_name() == "New Test Client"
178-
179-
180166
def test_get_info(monkeypatch):
181167
with NamedTemporaryFile("w") as temp:
182168
monkeypatch.setenv("INFO_FILE", temp.name)
@@ -286,13 +272,11 @@ def test_str_timedelta():
286272
assert result.total_seconds() == (1 * 60 * 60) + (30 * 60) + 15
287273

288274

289-
def test_convert_to_harvest_mocked(toggl_file, spy_files, mock_harvest_client_name, mock_google_user_info):
275+
def test_convert_to_harvest_mocked(toggl_file, spy_files, mock_google_user_info):
290276
mock_google_user_info.return_value = {}
291277

292278
convert_to_harvest(toggl_file, client_name=None)
293279

294-
mock_harvest_client_name.assert_called_once()
295-
296280
spy_files.read_csv.assert_called_once()
297281
call_args = spy_files.read_csv.call_args
298282
assert (toggl_file,) in call_args

0 commit comments

Comments
 (0)