def test_publish_message_resource_modified(self): kafka_mock = Mock() KafkaProducerSingleton.get_instance = lambda: kafka_mock resource = ResourceFactory() dataset = DatasetFactory(resources=[resource]) expected_signals = (Dataset.on_resource_updated, ) resource.description = 'New description' with assert_emit(*expected_signals): dataset.update_resource(resource) producer = KafkaProducerSingleton.get_instance() message_type = f'resource.{KafkaMessageType.MODIFIED.value}' expected_value = { 'service': 'udata', 'data': serialize_resource_for_event(resource), 'meta': { 'message_type': message_type, 'dataset_id': str(dataset.id) } } topic = f"{current_app.config['UDATA_INSTANCE_NAME']}.{message_type}" producer.send.assert_called_with(topic, value=expected_value, key=str(resource.id).encode("utf-8"))
def test_update_resource(self): user = UserFactory() resource = ResourceFactory() dataset = DatasetFactory(owner=user, resources=[resource]) expected_signals = post_save, Dataset.after_save, Dataset.on_update resource.description = 'New description' with assert_emit(*expected_signals): dataset.update_resource(resource) self.assertEqual(len(dataset.resources), 1) self.assertEqual(dataset.resources[0].id, resource.id) self.assertEqual(dataset.resources[0].description, 'New description')
def test_update_resource(self): user = UserFactory() resource = ResourceFactory() dataset = DatasetFactory(owner=user, resources=[resource]) expected_signals = (Dataset.on_resource_updated, ) resource.description = 'New description' with assert_emit(*expected_signals): dataset.update_resource(resource) assert len(dataset.resources) == 1 assert dataset.resources[0].id == resource.id assert dataset.resources[0].description == 'New description'
def test_update_resource(self): user = UserFactory() resource = ResourceFactory() dataset = DatasetFactory(owner=user, resources=[resource]) expected_signals = post_save, Dataset.after_save, Dataset.on_update resource.description = 'New description' with assert_emit(*expected_signals): dataset.update_resource(resource) assert len(dataset.resources) == 1 assert dataset.resources[0].id == resource.id assert dataset.resources[0].description == 'New description'