def test_event_get_sorted_desc_by_event_type_filter(self): fake_event_type = 'test_event' sort_dir = 'desc' sort_key = 'time' db_api.event_create(_get_fake_event_values( id='1', event_type=fake_event_type )) db_api.event_create(_get_fake_event_values( id='2', event_type=fake_event_type )) filtered_events = db_api.event_get_all_sorted_by_filters( sort_key=sort_key, sort_dir=sort_dir, filters={'event_type': fake_event_type} ) self.assertEqual(2, len(filtered_events)) self.assertEqual(fake_event_type, filtered_events[0].event_type) # testing sort self.assertTrue(is_result_sorted_correctly(filtered_events, sort_key=sort_key, sort_dir=sort_dir))
def test_event_destroy(self): self.assertFalse(db_api.event_get('1')) db_api.event_create(_get_fake_event_values(id='1')) self.assertTrue(db_api.event_get('1')) db_api.event_destroy('1') self.assertFalse(db_api.event_get('1'))
def test_event_get_sorted_desc_by_status_filter(self): fake_status = 'test_status' sort_dir = 'desc' sort_key = 'time' db_api.event_create(_get_fake_event_values( id='1', status=fake_status )) db_api.event_create(_get_fake_event_values( id='2' )) filtered_events = db_api.event_get_all_sorted_by_filters( sort_key=sort_key, sort_dir=sort_dir, filters={'status': fake_status} ) self.assertEqual(1, len(filtered_events)) self.assertEqual(fake_status, filtered_events[0].status) # testing sort self.assertTrue(is_result_sorted_correctly(filtered_events, sort_key=sort_key, sort_dir=sort_dir))
def test_event_get_sorted_asc_by_event_type_filter(self): fake_event_type = 'test_event' sort_dir = 'asc' sort_key = 'time' db_api.event_create( _get_fake_event_values(id='1', event_type=fake_event_type, time=datetime.datetime.utcnow())) db_api.event_create( _get_fake_event_values(id='2', event_type=fake_event_type, time=datetime.datetime.utcnow())) filtered_events = db_api.event_get_all_sorted_by_filters( sort_key=sort_key, sort_dir=sort_dir, filters={'event_type': fake_event_type}) self.assertEqual(2, len(filtered_events)) self.assertEqual(fake_event_type, filtered_events[0].event_type) # testing sort self.assertTrue( is_result_sorted_correctly(filtered_events, sort_key=sort_key, sort_dir=sort_dir))
def test_event_get_sorted_desc_by_lease_id_filter(self): fake_lease_id = '1234' sort_dir = 'desc' sort_key = 'time' db_api.event_create(_get_fake_event_values( id='1', lease_id=fake_lease_id )) db_api.event_create(_get_fake_event_values( id='2' )) filtered_events = db_api.event_get_all_sorted_by_filters( sort_key=sort_key, sort_dir=sort_dir, filters={'lease_id': fake_lease_id} ) self.assertEqual(1, len(filtered_events)) self.assertEqual(fake_lease_id, filtered_events[0].lease_id) # testing sort self.assertTrue(is_result_sorted_correctly(filtered_events, sort_key=sort_key, sort_dir=sort_dir))
def test_event_destroy(self): self.assertFalse(db_api.event_get('1')) db_api.event_create(_get_fake_event_values( id='1')) self.assertTrue(db_api.event_get('1')) db_api.event_destroy('1') self.assertFalse(db_api.event_get('1'))
def test_event_create(self): fake_event_type = 'test_event' test_event = db_api.event_create(_get_fake_event_values( event_type=fake_event_type)) self.assertTrue(test_event) self.assertEqual(fake_event_type, test_event.event_type)
def test_event_create(self): fake_event_type = 'test_event' test_event = db_api.event_create( _get_fake_event_values(event_type=fake_event_type)) self.assertTrue(test_event) self.assertEqual(fake_event_type, test_event.event_type)
def test_create_duplicated_event(self): self.assertFalse(db_api.event_get('1')) fake_values = _get_fake_event_values(id='1') test_event = db_api.event_create(fake_values) self.assertTrue(test_event) self.assertRaises(db_exceptions.ClimateDBDuplicateEntry, db_api.event_create, fake_values)
def test_event_update(self): self.assertFalse(db_api.event_get('1')) test_event = db_api.event_create(_get_fake_event_values(id='1')) self.assertTrue(test_event) test_event = db_api.event_update(test_event.id, {'status': 'changed'}) self.assertEqual('changed', test_event.status)
def test_event_get_sorted_desc_by_status_filter(self): fake_status = 'test_status' sort_dir = 'desc' sort_key = 'time' db_api.event_create(_get_fake_event_values(id='1', status=fake_status)) db_api.event_create(_get_fake_event_values(id='2')) filtered_events = db_api.event_get_all_sorted_by_filters( sort_key=sort_key, sort_dir=sort_dir, filters={'status': fake_status}) self.assertEqual(1, len(filtered_events)) self.assertEqual(fake_status, filtered_events[0].status) # testing sort self.assertTrue( is_result_sorted_correctly(filtered_events, sort_key=sort_key, sort_dir=sort_dir))
def test_event_get_sorted_desc_by_lease_id_filter(self): fake_lease_id = '1234' sort_dir = 'desc' sort_key = 'time' db_api.event_create( _get_fake_event_values(id='1', lease_id=fake_lease_id)) db_api.event_create(_get_fake_event_values(id='2')) filtered_events = db_api.event_get_all_sorted_by_filters( sort_key=sort_key, sort_dir=sort_dir, filters={'lease_id': fake_lease_id}) self.assertEqual(1, len(filtered_events)) self.assertEqual(fake_lease_id, filtered_events[0].lease_id) # testing sort self.assertTrue( is_result_sorted_correctly(filtered_events, sort_key=sort_key, sort_dir=sort_dir))
def test_event_get_first_sorted_by_status_filter(self): fake_status = 'test_status' db_api.event_create(_get_fake_event_values(id='1')) db_api.event_create(_get_fake_event_values(id='2', status=fake_status)) db_api.event_create(_get_fake_event_values(id='3', status=fake_status)) filtered_events = db_api.event_get_first_sorted_by_filters( sort_key='time', sort_dir='asc', filters={'status': fake_status}) self.assertEqual(fake_status, filtered_events.status) self.assertEqual('2', filtered_events.id)
def test_event_get_first_sorted_by_lease_id_filter(self): fake_lease_id = '1234' db_api.event_create(_get_fake_event_values(id='1')) db_api.event_create( _get_fake_event_values(id='2', lease_id=fake_lease_id)) db_api.event_create( _get_fake_event_values(id='3', lease_id=fake_lease_id)) filtered_events = db_api.event_get_first_sorted_by_filters( sort_key='time', sort_dir='asc', filters={'lease_id': fake_lease_id}) self.assertEqual(fake_lease_id, filtered_events.lease_id) self.assertEqual('2', filtered_events.id)
def test_event_get_first_sorted_by_event_type_filter(self): fake_event_type = 'test_event' db_api.event_create(_get_fake_event_values(id='1')) db_api.event_create( _get_fake_event_values(id='2', event_type=fake_event_type)) db_api.event_create( _get_fake_event_values(id='3', event_type=fake_event_type)) filtered_events = db_api.event_get_first_sorted_by_filters( sort_key='time', sort_dir='asc', filters={'event_type': fake_event_type}) self.assertEqual(fake_event_type, filtered_events.event_type) self.assertEqual('2', filtered_events.id)
def test_event_get_first_sorted_by_lease_id_filter(self): fake_lease_id = '1234' db_api.event_create(_get_fake_event_values( id='1' )) db_api.event_create(_get_fake_event_values( id='2', lease_id=fake_lease_id )) db_api.event_create(_get_fake_event_values( id='3', lease_id=fake_lease_id )) filtered_events = db_api.event_get_first_sorted_by_filters( sort_key='time', sort_dir='asc', filters={'lease_id': fake_lease_id} ) self.assertEqual(fake_lease_id, filtered_events.lease_id) self.assertEqual('2', filtered_events.id)
def test_event_get_first_sorted_by_status_filter(self): fake_status = 'test_status' db_api.event_create(_get_fake_event_values( id='1' )) db_api.event_create(_get_fake_event_values( id='2', status=fake_status )) db_api.event_create(_get_fake_event_values( id='3', status=fake_status )) filtered_events = db_api.event_get_first_sorted_by_filters( sort_key='time', sort_dir='asc', filters={'status': fake_status} ) self.assertEqual(fake_status, filtered_events.status) self.assertEqual('2', filtered_events.id)
def test_event_get_first_sorted_by_event_type_filter(self): fake_event_type = 'test_event' db_api.event_create(_get_fake_event_values( id='1' )) db_api.event_create(_get_fake_event_values( id='2', event_type=fake_event_type )) db_api.event_create(_get_fake_event_values( id='3', event_type=fake_event_type )) filtered_events = db_api.event_get_first_sorted_by_filters( sort_key='time', sort_dir='asc', filters={'event_type': fake_event_type} ) self.assertEqual(fake_event_type, filtered_events.event_type) self.assertEqual('2', filtered_events.id)