From f574abfd5d275fe2b8713cdbad5d306ded5a90a1 Mon Sep 17 00:00:00 2001 From: Jeet Jain Date: Tue, 11 Apr 2023 12:49:10 +0530 Subject: [PATCH 1/3] added unit tests --- tests/test_cricnotifier.py | 70 ++++++++++++++++++++++++++++++++++++++ tests/test_scoreboard.py | 6 ---- 2 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 tests/test_cricnotifier.py delete mode 100644 tests/test_scoreboard.py diff --git a/tests/test_cricnotifier.py b/tests/test_cricnotifier.py new file mode 100644 index 0000000..ebbf55f --- /dev/null +++ b/tests/test_cricnotifier.py @@ -0,0 +1,70 @@ +import os +import json +import pytest +from unittest import mock +from typer.testing import CliRunner +from cric_notifier import Store, Notification, Match, Scoreboard + + +@pytest.fixture(scope='module') +def runner(): + return CliRunner() + + +class TestStore: + def test_put(self, tmpdir): + store = Store() + data = {"id": 1} + result = store.put(json.dumps(data)) + assert result == 0 + assert os.path.exists(store.store + "cric.json") + + def test_get(self, tmpdir): + store = Store() + data = {"id": 1} + store.put(json.dumps(data)) + result = store.get() + assert result == data + + +class TestNotification: + def test_send(self, capsys): + notification = Notification() + notification.send("Test Notification", "This is a test notification", 1) + captured = capsys.readouterr() + assert "Notification service failed!" not in captured.out + + +class TestMatch: + def test_list(self): + match = Match() + result = match.list(None) + assert isinstance(result, list) + + +class TestScoreboard: + @mock.patch('builtins.input', return_value='1') + def test_init_id_with_id(self, mock_input): + scoreboard = Scoreboard(None) + result = scoreboard.init_id(None) + assert result == 0 + + @mock.patch('builtins.input', return_value=None) + def test_init_id_without_id(self, mock_input): + store = Store() + data = {"id": 1} + store.put(json.dumps(data)) + scoreboard = Scoreboard(None) + result = scoreboard.init_id(None) + assert result == 0 + + def test_info(self, capsys): + scoreboard = Scoreboard(0) + scoreboard.info() + captured = capsys.readouterr() + assert "Description" in captured.out + + def test_score(self): + scoreboard = Scoreboard(0) + result = scoreboard.score() + assert isinstance(result, tuple) diff --git a/tests/test_scoreboard.py b/tests/test_scoreboard.py deleted file mode 100644 index 224d3af..0000000 --- a/tests/test_scoreboard.py +++ /dev/null @@ -1,6 +0,0 @@ -import pytest - - -def test_getMatchID(): - matchID = "656" - assert isinstance(matchID, str) From 9f70a4f81e7e2245c0b6437fbe23ce05ad6485a8 Mon Sep 17 00:00:00 2001 From: Jeet Jain Date: Tue, 11 Apr 2023 12:54:14 +0530 Subject: [PATCH 2/3] updated module name --- tests/test_cricnotifier.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_cricnotifier.py b/tests/test_cricnotifier.py index ebbf55f..fb77bd6 100644 --- a/tests/test_cricnotifier.py +++ b/tests/test_cricnotifier.py @@ -3,7 +3,7 @@ import pytest from unittest import mock from typer.testing import CliRunner -from cric_notifier import Store, Notification, Match, Scoreboard +from cricnotifier import Store, Notification, Match, Scoreboard @pytest.fixture(scope='module') From ec459c297adf1dd73f94f4584ef69343e8056d4e Mon Sep 17 00:00:00 2001 From: Jeet Jain Date: Tue, 11 Apr 2023 13:04:15 +0530 Subject: [PATCH 3/3] updated module name --- tests/test_cricnotifier.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_cricnotifier.py b/tests/test_cricnotifier.py index fb77bd6..4678487 100644 --- a/tests/test_cricnotifier.py +++ b/tests/test_cricnotifier.py @@ -3,7 +3,7 @@ import pytest from unittest import mock from typer.testing import CliRunner -from cricnotifier import Store, Notification, Match, Scoreboard +from cricnotifier.main import Store, Notification, Match, Scoreboard @pytest.fixture(scope='module')