Skip to content

Commit

Permalink
Add a test that will always run first to test the auto-sync that happ…
Browse files Browse the repository at this point in the history
…ens on module import
  • Loading branch information
shaneharter committed May 23, 2024
1 parent 6334a34 commit c337e7a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
29 changes: 29 additions & 0 deletions cronitor/tests/test_00.py
Original file line number Diff line number Diff line change
@@ -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
11 changes: 1 addition & 10 deletions cronitor/tests/test_pings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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__')
Expand All @@ -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
Expand Down

0 comments on commit c337e7a

Please sign in to comment.