class LocationRepeaterTest(TestCase, DomainSubscriptionMixin): @classmethod def setUpClass(cls): super().setUpClass() cls.domain = 'loc-repeat' cls.domain_obj = create_domain(name=cls.domain) # DATA_FORWARDING is on PRO and above cls.setup_subscription(cls.domain, SoftwarePlanEdition.PRO) def setUp(self): super().setUp() self.repeater = LocationRepeater( domain=self.domain, url='super-cool-url', ) self.repeater.save() self.location_type = LocationType.objects.create( domain=self.domain, name="city", ) @classmethod def tearDownClass(cls): cls.teardown_subscriptions() cls.domain_obj.delete() clear_plan_version_cache() super().tearDownClass() def tearDown(self): super().tearDown() delete_all_repeat_records() delete_all_repeaters() def repeat_records(self): # Enqueued repeat records have next_check set 48 hours in the future. later = datetime.utcnow() + timedelta(hours=48 + 1) return RepeatRecord.all(domain=self.domain, due_before=later) def make_location(self, name): location = SQLLocation.objects.create( domain=self.domain, name=name, site_code=name, location_type=self.location_type, ) self.addCleanup(location.delete) return location def test_trigger(self): self.assertEqual(0, len(self.repeat_records().all())) location = self.make_location('kings_landing') records = self.repeat_records().all() self.assertEqual(1, len(records)) record = records[0] self.assertEqual( json.loads(record.get_payload()), { '_id': location.location_id, 'doc_type': 'Location', 'domain': self.domain, 'external_id': None, 'is_archived': False, 'last_modified': location.last_modified.isoformat(), 'latitude': None, 'lineage': [], 'location_id': location.location_id, 'location_type': 'city', 'location_type_code': 'city', 'longitude': None, 'metadata': {}, 'name': location.name, 'parent_location_id': None, 'site_code': location.site_code, })
class LocationRepeaterTest(TestCase): domain = 'location-repeater' def setUp(self): super(LocationRepeaterTest, self).setUp() self.domain_obj = create_domain(self.domain) self.repeater = LocationRepeater( domain=self.domain, url='super-cool-url', ) self.repeater.save() self.location_type = LocationType.objects.create( domain=self.domain, name="city", ) def tearDown(self): super(LocationRepeaterTest, self).tearDown() delete_all_repeat_records() delete_all_repeaters() self.domain_obj.delete() def repeat_records(self): return RepeatRecord.all(domain=self.domain, due_before=datetime.utcnow()) def make_location(self, name): location = SQLLocation.objects.create( domain=self.domain, name=name, site_code=name, location_type=self.location_type, ) self.addCleanup(location.delete) return location def test_trigger(self): self.assertEqual(0, len(self.repeat_records().all())) location = self.make_location('kings_landing') records = self.repeat_records().all() self.assertEqual(1, len(records)) record = records[0] self.assertEqual( json.loads(record.get_payload()), { '_id': location.location_id, 'doc_type': 'Location', 'domain': self.domain, 'external_id': None, 'is_archived': False, 'last_modified': location.last_modified.isoformat(), 'latitude': None, 'lineage': [], 'location_id': location.location_id, 'location_type': 'city', 'location_type_code': 'city', 'longitude': None, 'metadata': {}, 'name': location.name, 'parent_location_id': None, 'site_code': location.site_code, })
class LocationRepeaterTest(TestCase): domain = 'location-repeater' def setUp(self): super(LocationRepeaterTest, self).setUp() self.domain_obj = create_domain(self.domain) self.repeater = LocationRepeater( domain=self.domain, url='super-cool-url', ) self.repeater.save() self.location_type = LocationType.objects.create( domain=self.domain, name="city", ) def tearDown(self): super(LocationRepeaterTest, self).tearDown() delete_all_repeat_records() delete_all_repeaters() self.domain_obj.delete() def repeat_records(self): # Enqueued repeat records have next_check set 48 hours in the future. later = datetime.utcnow() + timedelta(hours=48 + 1) return RepeatRecord.all(domain=self.domain, due_before=later) def make_location(self, name): location = SQLLocation.objects.create( domain=self.domain, name=name, site_code=name, location_type=self.location_type, ) self.addCleanup(location.delete) return location def test_trigger(self): self.assertEqual(0, len(self.repeat_records().all())) location = self.make_location('kings_landing') records = self.repeat_records().all() self.assertEqual(1, len(records)) record = records[0] self.assertEqual( json.loads(record.get_payload()), { '_id': location.location_id, 'doc_type': 'Location', 'domain': self.domain, 'external_id': None, 'is_archived': False, 'last_modified': location.last_modified.isoformat(), 'latitude': None, 'lineage': [], 'location_id': location.location_id, 'location_type': 'city', 'location_type_code': 'city', 'longitude': None, 'metadata': {}, 'name': location.name, 'parent_location_id': None, 'site_code': location.site_code, } )