本文整理汇总了Python中pulp.server.db.model.consumer.ConsumerHistoryEvent类的典型用法代码示例。如果您正苦于以下问题:Python ConsumerHistoryEvent类的具体用法?Python ConsumerHistoryEvent怎么用?Python ConsumerHistoryEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConsumerHistoryEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: record_event
def record_event(self, consumer_id, event_type, event_details=None):
"""
@ivar consumer_id: identifies the consumer
@type id: str
@param type: event type
@type type: str
@param details: event details
@type details: dict
@raises MissingResource: if the given consumer does not exist
@raises InvalidValue: if any of the fields is unacceptable
"""
# Check that consumer exists for all except registration event
existing_consumer = Consumer.get_collection().find_one({'id': consumer_id})
if not existing_consumer and event_type != TYPE_CONSUMER_UNREGISTERED:
raise MissingResource(consumer=consumer_id)
invalid_values = []
if event_type not in TYPES:
invalid_values.append('event_type')
if event_details is not None and not isinstance(event_details, dict):
invalid_values.append('event_details')
if invalid_values:
raise InvalidValue(invalid_values)
event = ConsumerHistoryEvent(consumer_id, self._originator(), event_type, event_details)
ConsumerHistoryEvent.get_collection().save(event)
示例2: tearDown
def tearDown(self):
super(BindManagerTests, self).tearDown()
Consumer.get_collection().remove()
model.Repository.objects.delete()
model.Distributor.objects.delete()
Bind.get_collection().remove()
ConsumerHistoryEvent.get_collection().remove()
mock_plugins.reset()
示例3: setUp
def setUp(self):
super(BindManagerTests, self).setUp()
Consumer.get_collection().remove()
model.Distributor.objects.delete()
Bind.get_collection().remove()
ConsumerHistoryEvent.get_collection().remove()
plugin_api._create_manager()
mock_plugins.install()
示例4: tearDown
def tearDown(self):
super(BindManagerTests, self).tearDown()
Consumer.get_collection().remove()
Repo.get_collection().remove()
RepoDistributor.get_collection().remove()
Bind.get_collection().remove()
ConsumerHistoryEvent.get_collection().remove()
mock_plugins.reset()
示例5: test_add_remove_duration
def test_add_remove_duration(self):
collection = ConsumerHistoryEvent.get_collection()
self.reaper.add_collection(collection, months=1)
self.assertTrue(collection in self.reaper.collections)
self.assertTrue(isinstance(self.reaper.collections[collection], Duration))
self.reaper.remove_collection(collection)
self.assertFalse(collection in self.reaper.collections)
示例6: test_add_remove
def test_add_remove(self):
collection = ConsumerHistoryEvent.get_collection()
self.reaper.add_collection(collection, days=1)
self.assertTrue(collection in self.reaper.collections)
self.assertTrue(isinstance(self.reaper.collections[collection], timedelta))
self.reaper.remove_collection(collection)
self.assertFalse(collection in self.reaper.collections)
示例7: test_bind_consumer_history
def test_bind_consumer_history(self, mock_repo_qs):
self.populate()
manager = factory.consumer_bind_manager()
manager.bind(self.CONSUMER_ID, self.REPO_ID, self.DISTRIBUTOR_ID, self.NOTIFY_AGENT, self.BINDING_CONFIG)
# Verify
collection = ConsumerHistoryEvent.get_collection()
history = collection.find_one(self.QUERY1)
self.assertTrue(history is not None)
self.assertEqual(history["consumer_id"], self.CONSUMER_ID)
self.assertEqual(history["type"], "repo_bound")
self.assertEqual(history["originator"], "SYSTEM")
self.assertEqual(history["details"], self.DETAILS)
示例8: test_remove_expired_entries
def test_remove_expired_entries(self, getfloat):
chec = ConsumerHistoryEvent.get_collection()
event = ConsumerHistoryEvent('consumer', 'originator', 'consumer_registered', {})
chec.insert(event)
self.assertTrue(chec.find({'_id': event['_id']}).count() == 1)
# Let's mock getfloat to pretend that the user said they want to reap things from the
# future, which should make the event we just created look old enough to delete
getfloat.return_value = -1.0
reaper.reap_expired_documents()
# The event should no longer exist
self.assertTrue(chec.find({'_id': event['_id']}).count() == 0)
示例9: test_leave_unexpired_entries
def test_leave_unexpired_entries(self, getfloat):
chec = ConsumerHistoryEvent.get_collection()
event = ConsumerHistoryEvent('consumer', 'originator', 'consumer_registered', {})
chec.insert(event)
self.assertTrue(chec.find({'_id': event['_id']}).count() == 1)
# Let's mock getfloat to pretend that the user said they want to reap things that are a day
# old. This means that the event should not get reaped.
getfloat.return_value = 1.0
reaper.reap_expired_documents()
# The event should still exist
self.assertTrue(chec.find({'_id': event['_id']}).count() == 1)
示例10: test_unbind_consumer_history
def test_unbind_consumer_history(self, mock_repo_qs):
self.populate()
manager = factory.consumer_bind_manager()
manager.bind(self.CONSUMER_ID, self.REPO_ID, self.DISTRIBUTOR_ID,
self.NOTIFY_AGENT, self.BINDING_CONFIG)
# Test
manager.unbind(self.CONSUMER_ID, self.REPO_ID, self.DISTRIBUTOR_ID)
# Verify
collection = ConsumerHistoryEvent.get_collection()
history = collection.find_one(self.QUERY2)
self.assertTrue(history is not None)
self.assertEqual(history['consumer_id'], self.CONSUMER_ID)
self.assertEqual(history['type'], 'repo_unbound')
self.assertEqual(history['originator'], 'SYSTEM')
self.assertEqual(history['details'], self.DETAILS)
示例11: test_update_with_consumer_history
def test_update_with_consumer_history(self):
# Setup
self.populate()
manager = factory.consumer_profile_manager()
manager.update(self.CONSUMER_ID, self.TYPE_1, self.PROFILE_1)
# Test
manager.update(self.CONSUMER_ID, self.TYPE_1, self.PROFILE_2)
# Verify
collection = ConsumerHistoryEvent.get_collection()
history = collection.find_one({'consumer_id': self.CONSUMER_ID,
'type': 'unit_profile_changed',
'details': {'profile_content_type': self.TYPE_1}})
self.assertTrue(history is not None)
self.assertEqual(history['consumer_id'], self.CONSUMER_ID)
self.assertEqual(history['type'], 'unit_profile_changed')
self.assertEqual(history['originator'], 'SYSTEM')
self.assertEqual(history['details'], {'profile_content_type': self.TYPE_1})
示例12: test_remove_single_consumer_history
def test_remove_single_consumer_history(self):
group_id = 'test_group'
self.manager.create_consumer_group(group_id)
group = self.collection.find_one({'id': group_id})
consumer = self._create_consumer('test_consumer')
self.assertFalse(consumer['id'] in group['consumer_ids'])
criteria = Criteria(filters={'id': consumer['id']}, fields=['id'])
self.manager.unassociate(group_id, criteria)
collection = ConsumerHistoryEvent.get_collection()
history = collection.find_one({'consumer_id': 'test_consumer', 'type': 'removed_from_group',
'details': {'group_id': group_id}})
self.assertTrue(history is not None)
self.assertEqual(history['consumer_id'], 'test_consumer')
self.assertEqual(history['type'], 'removed_from_group')
self.assertEqual(history['originator'], 'SYSTEM')
self.assertEqual(history['details'], {'group_id': group_id})
示例13: clean
def clean(self):
base.PulpServerTests.clean(self)
Consumer.get_collection().remove()
ConsumerHistoryEvent.get_collection().remove()
示例14: clean
def clean(self):
super(ScheduledUnitUninstallTests, self).clean()
Consumer.get_collection().remove(safe=True)
ConsumerHistoryEvent.get_collection().remove(safe=True)
示例15: setUp
def setUp(self):
super(ReaperReapingTests, self).setUp()
self.collection = ConsumerHistoryEvent.get_collection()