Skip to content

Commit

Permalink
Merge pull request #35412 from dimagi/nh/tweaks
Browse files Browse the repository at this point in the history
Small fixes on tests
  • Loading branch information
kaapstorm authored Nov 28, 2024
2 parents 4332a2d + 68e39da commit 4f506ae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
27 changes: 14 additions & 13 deletions corehq/motech/repeaters/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from dateutil.parser import isoparse
from freezegun import freeze_time
from nose.tools import assert_in, assert_raises
from nose.tools import assert_in

from corehq.motech.models import ConnectionSettings
from corehq.motech.repeater_helpers import RepeaterResponse
Expand Down Expand Up @@ -229,38 +229,45 @@ def set_next_attempt_at(repeater, when):
repeater.save()


class ResponseMock:
class Unknown:
pass


class IsResponseTests(SimpleTestCase):

def test_has_text(self):
resp = ResponseMock()
resp = Unknown()
resp.text = '<h1>Hello World</h1>'
self.assertFalse(is_response(resp))

def test_has_status_code(self):
resp = ResponseMock()
resp = Unknown()
resp.status_code = 504
self.assertFalse(is_response(resp))

def test_has_reason(self):
resp = ResponseMock()
resp = Unknown()
resp.reason = 'Gateway Timeout'
self.assertFalse(is_response(resp))

def test_has_status_code_and_reason(self):
resp = ResponseMock()
resp = Unknown()
resp.status_code = 504
resp.reason = 'Gateway Timeout'
self.assertTrue(is_response(resp))


class ResponseMock:
status_code = 0
reason = ''
text = ''
url = ''


class FormatResponseTests(SimpleTestCase):

def test_non_response(self):
resp = ResponseMock()
resp = Unknown()
self.assertEqual(format_response(resp), '')

def test_no_text(self):
Expand Down Expand Up @@ -508,12 +515,6 @@ def test_used_connection_setting_cannot_be_deleted(self):
ConnectionSettings.all_objects.filter(id=self.conn.id).delete()


def test_attempt_forward_now_kwargs():
rr = RepeatRecord()
with assert_raises(TypeError):
rr.attempt_forward_now(True)


@patch("corehq.motech.repeaters.tasks.retry_process_repeat_record")
@patch("corehq.motech.repeaters.tasks.process_repeat_record")
class TestAttemptForwardNow(RepeaterTestCase):
Expand Down
13 changes: 5 additions & 8 deletions corehq/motech/repeaters/tests/test_repeater.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ def setUpClass(cls):
def post_xml(cls, xml, domain_name):
return submit_form_locally(xml, domain_name)

@classmethod
def repeat_records(cls, domain_name):
def repeat_records(self, domain=None):
domain = domain or self.domain
# Enqueued repeat records have next_check set 48 hours in the future.
later = datetime.utcnow() + timedelta(hours=48 + 1)
return RepeatRecord.objects.filter(domain=domain_name, next_check__lt=later)
return RepeatRecord.objects.filter(domain=domain, next_check__lt=later)


class RepeaterTest(BaseRepeaterTest):
Expand Down Expand Up @@ -174,9 +174,6 @@ def tearDown(self):
FormProcessorTestUtils.delete_all_cases_forms_ledgers(self.domain)
super(RepeaterTest, self).tearDown()

def repeat_records(self):
return super(RepeaterTest, self).repeat_records(self.domain)

# whatever value specified will be doubled since both case and form repeater are active
def _create_additional_repeat_records(self, count):
for _ in range(count):
Expand Down Expand Up @@ -842,7 +839,7 @@ class NewCaseGenerator(BasePayloadGenerator):
format_label = 'XML'

def get_payload(self, repeat_record, payload_doc):
return self.payload
return {}

with self.assertRaises(DuplicateFormatException):
RegisterGenerator.get_collection(CaseRepeater).add_new_format(NewCaseGenerator)
Expand All @@ -853,7 +850,7 @@ class NewCaseGenerator(BasePayloadGenerator):
format_label = 'XML'

def get_payload(self, repeat_record, payload_doc):
return self.payload
return {}

with self.assertRaises(DuplicateFormatException):
RegisterGenerator.get_collection(CaseRepeater).add_new_format(NewCaseGenerator, is_default=True)
Expand Down

0 comments on commit 4f506ae

Please sign in to comment.