diff --git a/corehq/motech/repeaters/tests/test_models.py b/corehq/motech/repeaters/tests/test_models.py index b130ff6f5967..5f2b019434c4 100644 --- a/corehq/motech/repeaters/tests/test_models.py +++ b/corehq/motech/repeaters/tests/test_models.py @@ -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 @@ -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 = '

Hello World

' 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): @@ -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): diff --git a/corehq/motech/repeaters/tests/test_repeater.py b/corehq/motech/repeaters/tests/test_repeater.py index bead9f544515..23da2263c810 100644 --- a/corehq/motech/repeaters/tests/test_repeater.py +++ b/corehq/motech/repeaters/tests/test_repeater.py @@ -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): @@ -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): @@ -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) @@ -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)