Skip to content

Commit

Permalink
Mocked time function in some tests and removed the UTC TZ
Browse files Browse the repository at this point in the history
  • Loading branch information
EmanElsaban committed Aug 30, 2024
1 parent db06b8d commit d75df79
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 14 additions & 0 deletions tests/cli/test_cmds_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -2162,8 +2162,10 @@ def test_successful_return_value(self, mock_kubernetes_status):
)
@patch("paasta_tools.cli.cmds.status.desired_state_human", autospec=True)
@patch("paasta_tools.cli.cmds.status.bouncing_status_human", autospec=True)
@patch("paasta_tools.cli.cmds.status.datetime", autospec=True)
def test_output(
self,
mock_datetime,
mock_bouncing_status,
mock_desired_state,
mock_kubernetes_app_deploy_status_human,
Expand All @@ -2173,6 +2175,8 @@ def test_output(
mock_kubernetes_status,
):
mock_bouncing_status.return_value = "Bouncing (crossover)"
specific_datetime = datetime.datetime(2019, 7, 12, 13, 31)
mock_datetime.fromtimestamp.return_value = specific_datetime
mock_desired_state.return_value = "Started"
mock_kubernetes_app_deploy_status_human.return_value = "Running"
mock_naturaltime.return_value = "a month ago"
Expand Down Expand Up @@ -2869,11 +2873,16 @@ def mock_kubernetes_replicaset(self):
config_sha=None,
)

@patch("paasta_tools.cli.cmds.status.datetime", autospec=True)
def test_format_kubernetes_pod_table(
self,
mock_datetime,
mock_naturaltime,
mock_kubernetes_pod,
):
mock_date = MagicMock()
mock_date.strftime.return_value = "2019-08-12T15:23"
mock_datetime.fromtimestamp.return_value = mock_date
output = format_kubernetes_pod_table([mock_kubernetes_pod], verbose=0)
pod_table_dict = _formatted_table_to_dict(output)
assert pod_table_dict == {
Expand All @@ -2883,11 +2892,16 @@ def test_format_kubernetes_pod_table(
"Health": PaastaColors.green("Healthy"),
}

@patch("paasta_tools.cli.cmds.status.datetime", autospec=True)
def test_format_kubernetes_replicaset_table(
self,
mock_datetime,
mock_naturaltime,
mock_kubernetes_replicaset,
):
mock_date = MagicMock()
mock_date.strftime.return_value = "2019-08-12T15:23"
mock_datetime.fromtimestamp.return_value = mock_date
output = format_kubernetes_replicaset_table([mock_kubernetes_replicaset])
replicaset_table_dict = _formatted_table_to_dict(output)
assert replicaset_table_dict == {
Expand Down
2 changes: 0 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ requires =
[testenv]
basepython = python3.8
passenv = SSH_AUTH_SOCK PAASTA_ENV DOCKER_HOST CI
setenv =
TZ = UTC
deps =
--only-binary=grpcio
--requirement={toxinidir}/requirements.txt
Expand Down

0 comments on commit d75df79

Please sign in to comment.