Skip to content

Commit

Permalink
fix: github actions: python tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Roger committed Feb 17, 2024
1 parent ce17d5c commit 057b2a0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
1 change: 0 additions & 1 deletion .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ jobs:
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Run Tests
working-directory: ./
run: |
python -m unittest tests/*/test_*.py
Expand Down
10 changes: 5 additions & 5 deletions tests/container/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_container_not_valid(self):
container = Container("Foo")
self.assertFalse(container.exists(), "Container not exist! Expected: 'False'")

@patch("subprocess.check_output", return_value=open("fixtures/docker_inspect_volume_only.output").read())
@patch("subprocess.check_output", return_value=open("tests/fixtures/docker_inspect_volume_only.output").read())
def test_determine_volumes(self, mock_check_output):
container = Container("Foo")
container.determine_volume()
Expand All @@ -27,7 +27,7 @@ def test_determine_volumes(self, mock_check_output):
self.assertFalse(container.has_docker_bindings, "Unexpected container bindings found!")
self.assertEqual(container.docker_bindings, [], "Unexpected container bindings found!")

@patch("subprocess.check_output", return_value=open("fixtures/docker_inspect_multiple_volumes.output").read())
@patch("subprocess.check_output", return_value=open("tests/fixtures/docker_inspect_multiple_volumes.output").read())
def test_determine_multiple_volumes(self, mock_check_output):
container = Container("Foo")
container.determine_volume()
Expand All @@ -38,7 +38,7 @@ def test_determine_multiple_volumes(self, mock_check_output):
self.assertEqual(container.docker_bindings, ["/opt/foo/bar", "/var/log"],
"Binding destinations not correct!")

@patch("subprocess.check_output", return_value=open("fixtures/docker_inspect_invalid_output.output").read())
@patch("subprocess.check_output", return_value=open("tests/fixtures/docker_inspect_invalid_output.output").read())
def test_determine_invalid_output(self, mock_check_output):
container = Container("Foo")
with self.assertRaises(json.JSONDecodeError) as err:
Expand All @@ -60,7 +60,7 @@ def test_is_container_started_by_compose(self, mock_inspect_container):
container = Container("foo")

# Mocking the return value
with open("fixtures/docker_inspect_with_compose.json") as file:
with open("tests/fixtures/docker_inspect_with_compose.json") as file:
mock_inspect_container.return_value = json.load(file)

self.assertEqual((True, "/docker/foo/docker-compose.yml"), container._is_container_started_by_compose())
Expand All @@ -70,7 +70,7 @@ def test_is_container_started_by_compose_false(self, mock_inspect_container):
container = Container("foo")

# Mocking the return value
with open("fixtures/docker_inspect_without_compose.json") as file:
with open("tests/fixtures/docker_inspect_without_compose.json") as file:
mock_inspect_container.return_value = json.load(file)

self.assertEqual((False, None), container._is_container_started_by_compose())
8 changes: 4 additions & 4 deletions tests/util/test_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,27 @@ def tearDown(self):
pass

def test_validate_env_settings(self):
load_dotenv("fixtures/env_files/.env_ok")
load_dotenv("tests/fixtures/env_files/.env_ok")
self.assertIsNone(EnvSettings().validate(), "Validate correct env settings failed")

def test_validate_env_settings_chat_error(self):
load_dotenv("fixtures/env_files/.env_chat_error")
load_dotenv("tests/fixtures/env_files/.env_chat_error")
with self.assertRaises(ValueError) as err:
EnvSettings().validate()

self.assertEqual("CHAT_ALERTING enabled but CHAT_SERVICE not correct. Check .env config.", str(err.exception),
"Chat settings error not raised")

def test_validate_env_settings_slack_error(self):
load_dotenv("fixtures/env_files/.env_chat_slack_error")
load_dotenv("tests/fixtures/env_files/.env_chat_slack_error")
with self.assertRaises(ValueError) as err:
EnvSettings().validate()

self.assertEqual("CHAT_SERVICE=SLACK but SLACK_CHANNEL_ID / SLACK_AUTH_TOKEN missing. Check .env config.",
str(err.exception), "Slack settings error not raised")

def test_validate_env_settings_mqtt_error(self):
load_dotenv("fixtures/env_files/.env_mqtt_error")
load_dotenv("tests/fixtures/env_files/.env_mqtt_error")
with self.assertRaises(ValueError) as err:
EnvSettings().validate()

Expand Down

0 comments on commit 057b2a0

Please sign in to comment.