diff --git a/cronitor/tests/test_00.py b/cronitor/tests/test_00.py new file mode 100644 index 0000000..2001a3b --- /dev/null +++ b/cronitor/tests/test_00.py @@ -0,0 +1,29 @@ +import yaml +import cronitor +import unittest +from unittest.mock import call, patch, ANY +import time +import cronitor + +FAKE_API_KEY = 'cb54ac4fd16142469f2d84fc1bbebd84XXXDEADXXX' +YAML_PATH = './cronitor/tests/cronitor.yaml' + +cronitor.api_key = FAKE_API_KEY +cronitor.timeout = 10 + +class SyncTests(unittest.TestCase): + + def setUp(self): + return super().setUp() + + def test_00_monitor_attributes_are_put(self): + # This test will run first, test that attributes are synced correctly, and then undo the global mock + + with patch('cronitor.Monitor.put') as mock_put: + time.sleep(2) + calls = [call([{'key': 'ping-decorator-test', 'name': 'Ping Decorator Test'}])] + mock_put.assert_has_calls(calls) + + @cronitor.job('ping-decorator-test', attributes={'name': 'Ping Decorator Test'}) + def function_call_with_attributes(self): + return diff --git a/cronitor/tests/test_pings.py b/cronitor/tests/test_pings.py index 3aaf6b8..f53e996 100644 --- a/cronitor/tests/test_pings.py +++ b/cronitor/tests/test_pings.py @@ -2,15 +2,13 @@ import unittest from unittest.mock import patch, ANY, call from unittest.mock import MagicMock - import cronitor +import pytest # a reserved monitorkey for running integration tests against cronitor.link FAKE_KEY = 'd3x0c1' FAKE_API_KEY = 'ping-api-key' -cronitor.Monitor.put = patch('cronitor.Monitor.put') - class MonitorPingTests(unittest.TestCase): def setUp(self): @@ -85,9 +83,6 @@ def test_ping_wraps_function_raises_exception(self, mocked_ping): self.assertRaises(Exception, lambda: self.error_function_call()) mocked_ping.assert_has_calls(calls) - def test_monitor_attributes_are_put(self): - calls = [call([{'key': 'ping-decorator-test', 'name': 'Ping Decorator Test'}])] - cronitor.Monitor.put.assert_has_calls(calls) @patch('cronitor.Monitor.ping') @patch('cronitor.Monitor.__init__') @@ -100,10 +95,6 @@ def test_ping_with_non_default_env(self, mocked_monitor, mocked_ping): def function_call(self): return - @cronitor.job('ping-decorator-test', attributes={'name': 'Ping Decorator Test'}) - def function_call_with_attributes(self): - return - @cronitor.job('ping-decorator-test') def error_function_call(self): raise Exception