def test_end_time_should_return_deleted_at_when_deleted_at_is_smaller(self): end_time = notification_payload.end_time( '2013-09-02 16:08:46', '2013-09-02 23:59:59.999999') self.assertEqual(end_time, "2013-09-02 16:08:46")
def test_convert_to_cuf_format(self): self.maxDiff = None exists_message = { "event_type": "image.exists", "timestamp": "2013-09-02 16:09:16.247932", "message_id": "18b59543-2e99-4208-ba53-22726c02bd67", "priority": "INFO", "publisher_id": "ubuntu", "payload": { "images": [{ "status": "active", "name": "image1", "created_at": "2013-09-02 16:08:10", "properties": { "image_type": "snapshot", "instance_uuid": "inst_uuid1" }, "deleted_at": None, "id": "image1", "size": 12345 }, { "status": "deleted", "name": "image2", "created_at": "2013-09-02 16:05:17", "properties": { "image_type": "snapshot", "instance_uuid": "inst_uuid2" }, "deleted_at": "2013-09-02 16:08:46", "id": "image2", "size": 67890 }], "owner": "owner1", "audit_period_ending": "2013-09-02 23:59:59.999999", "audit_period_beginning": "2013-09-02 00:00:00" } } self.mox.StubOutWithMock(uuid, 'uuid4') uuid.uuid4().AndReturn('uuid1') uuid.uuid4().AndReturn('uuid2') self.mox.StubOutWithMock(notification_payload, 'start_time') self.mox.StubOutWithMock(notification_payload, 'end_time') notification_payload.start_time( '2013-09-02 16:08:10', '2013-09-02 00:00:00').AndReturn('2013-09-02 00:00:00') notification_payload.end_time( None, '2013-09-02 23:59:59.999999').AndReturn('2013-09-02 23:59:59.999999') notification_payload.start_time( '2013-09-02 16:05:17', '2013-09-02 00:00:00').AndReturn('2013-09-02 16:05:17') notification_payload.end_time( '2013-09-02 16:08:46', '2013-09-02 23:59:59.999999').AndReturn('2013-09-02 23:59:59.999999') self.mox.ReplayAll() expected_cuf_xml = {'payload': ("""<events><event endTime="2013-09-02 23:59:59.999999" """ """startTime="2013-09-02 00:00:00" region="DFW" dataCenter="DFW1" """ """type="USAGE" id="uuid1" resourceId="image1" tenantId="owner1" """ """version="1"> <glance:product storage="12345" serverId="inst_uuid1" """ """serviceCode="Glance" serverName="" resourceType="snapshot" """ """version="1"/></event><event endTime="2013-09-02 23:59:59.999999" """ """startTime="2013-09-02 16:05:17" region="DFW" dataCenter="DFW1" """ """type="USAGE" id="uuid2" resourceId="image2" tenantId="owner1" """ """version="1"> <glance:product storage="67890" serverId="inst_uuid2" """ """serviceCode="Glance" serverName="" resourceType="snapshot" """ """version="1"/></event></events>""")} notification = GlanceNotification(exists_message) verified_message = notification.\ convert_to_verified_message_in_cuf_format( {'region': 'DFW', 'data_center': 'DFW1'}) self.assertEquals(verified_message, expected_cuf_xml) self.mox.VerifyAll()
def test_end_time_should_return_audit_period_beginning_when_deleted_at_is_none(self): end_time = notification_payload.end_time( "", '2013-09-02 23:59:59.999999') self.assertEqual(end_time, "2013-09-02 23:59:59.999999")
def test_convert_to_cuf_format(self): self.maxDiff = None event_type = 'image.exists.verified.cuf' exists_message = { "event_type": "image.exists", "timestamp": "2013-09-02 16:09:16.247932", "message_id": "18b59543-2e99-4208-ba53-22726c02bd67", "priority": "INFO", "publisher_id": "ubuntu", "payload": { "images": [{ "status": "active", "name": "image1", "created_at": "2013-09-02 16:08:10", "properties": { "image_type": "snapshot", "instance_uuid": "inst_uuid1" }, "deleted_at": None, "id": "image1", "size": 12345 }, { "status": "deleted", "name": "image2", "created_at": "2013-09-02 16:05:17", "properties": { "image_type": "snapshot", "instance_uuid": "inst_uuid2" }, "deleted_at": "2013-09-02 16:08:46", "id": "image2", "size": 67890 }], "owner": "owner1", "audit_period_ending": "2013-09-02 23:59:59.999999", "audit_period_beginning": "2013-09-02 00:00:00" } } self.mox.StubOutWithMock(uuid, 'uuid4') uuid.uuid4().AndReturn('uuid1') uuid.uuid4().AndReturn('uuid2') self.mox.StubOutWithMock(notification_payload, 'start_time') self.mox.StubOutWithMock(notification_payload, 'end_time') notification_payload.start_time('2013-09-02 16:08:10', '2013-09-02 00:00:00').AndReturn( datetime.datetime(2013, 9, 2)) notification_payload.end_time(None, '2013-09-02 23:59:59.999999').AndReturn( datetime.datetime( 2013, 9, 2, 23, 59, 59, 999999)) notification_payload.start_time('2013-09-02 16:05:17', '2013-09-02 00:00:00').AndReturn( datetime.datetime( 2013, 9, 2, 16, 5, 17)) notification_payload.end_time('2013-09-02 16:08:46', '2013-09-02 23:59:59.999999').AndReturn( datetime.datetime( 2013, 9, 2, 23, 59, 59, 999999)) self.mox.ReplayAll() expected_cuf_xml = { 'payload': ("""<events><event endTime="2013-09-02T23:59:59Z" """ """startTime="2013-09-02T00:00:00Z" region="DFW" dataCenter="DFW1" """ """type="USAGE" id="uuid1" resourceId="image1" tenantId="owner1" """ """version="1"> <glance:product storage="12345" serverId="inst_uuid1" """ """serviceCode="Glance" serverName="" resourceType="snapshot" """ """version="1"/></event><event endTime="2013-09-02T23:59:59Z" """ """startTime="2013-09-02T16:05:17Z" region="DFW" dataCenter="DFW1" """ """type="USAGE" id="uuid2" resourceId="image2" tenantId="owner1" """ """version="1"> <glance:product storage="67890" serverId="inst_uuid2" """ """serviceCode="Glance" serverName="" resourceType="snapshot" """ """version="1"/></event></events>""") } notification = GlanceNotification(exists_message, event_type=event_type, region='DFW', data_center='DFW1') verified_message = notification.\ convert_to_verified_message_in_cuf_format() self.assertEquals(verified_message, expected_cuf_xml) self.mox.VerifyAll()
def test_end_time_should_return_audit_period_beginning_when_deleted_at_is_none( self): end_time = notification_payload.end_time("", '2013-09-02 23:59:59.999999') self.assertEqual(str(end_time), "2013-09-02 23:59:59.999999")
def test_end_time_should_return_deleted_at_when_deleted_at_is_smaller( self): end_time = notification_payload.end_time('2013-09-02 16:08:46', '2013-09-02 23:59:59.999999') self.assertEqual(str(end_time), "2013-09-02 16:08:46")