Esempio n. 1
0
 def test_happy_case_insert_more_than_one_event(self):
     """Insert more than one event on database using batch_write"""
     another_event = next(self.event_generator)
     events_batch = [(TEST_SCHEMA_SCID, [another_event, self.event])]
     eventlogging.store_sql_events(self.meta, events_batch)
     table = self.meta.tables['TestSchema_123']
     # is the table on the db  and does it have the right data?
     s = sqlalchemy.sql.select([table])
     results = self.engine.execute(s)
     # the number of records in table must be the list size
     rows = results.fetchall()
     self.assertEqual(len(rows), 2)
Esempio n. 2
0
 def test_happy_case_insert_more_than_one_event(self):
     """Insert more than one event on database using batch_write"""
     another_event = next(self.event_generator)
     event_list = [another_event, self.event]
     eventlogging.store_sql_events(
         self.meta, TEST_SCHEMA_SCID, event_list)
     table = self.meta.tables['TestSchema_123']
     # is the table on the db  and does it have the right data?
     s = sqlalchemy.sql.select([table])
     results = self.engine.execute(s)
     # the number of records in table must be the list size
     rows = results.fetchall()
     self.assertEqual(len(rows), 2)
Esempio n. 3
0
 def test_insert_events_with_different_set_of_optional_fields(self):
     """Events belonging to the same schema with a different
     set of optional fields are inserted correctly"""
     another_event = next(self.event_generator)
     # ensure both events get inserted?
     event_list = [another_event, self.event]
     eventlogging.store_sql_events(self.meta, TEST_SCHEMA_SCID, event_list)
     table = self.meta.tables['TestSchema_123']
     # is the table on the db  and does it have the right data?
     s = sqlalchemy.sql.select([table])
     results = self.engine.execute(s)
     # the number of records in table must be the list size
     rows = results.fetchall()
     self.assertEqual(len(rows), 2)
Esempio n. 4
0
 def test_lazy_table_creation(self):
     """If an attempt is made to store an event for which no table
     exists, the schema is automatically retrieved and a suitable
     table generated."""
     events_batch = [(TEST_SCHEMA_SCID, [self.event])]
     eventlogging.store_sql_events(self.meta, events_batch)
     self.assertIn('TestSchema_123', self.meta.tables)
     table = self.meta.tables['TestSchema_123']
     # is the table on the db  and does it have the right data?
     s = sqlalchemy.sql.select([table])
     results = self.engine.execute(s)
     row = results.fetchone()
     # see columns with print table.c
     self.assertEqual(row['clientIp'], self.event['clientIp'])
Esempio n. 5
0
 def test_insert_events_with_different_set_of_optional_fields(self):
     """Events belonging to the same schema with a different
     set of optional fields are inserted correctly"""
     another_event = next(self.event_generator)
     # ensure both events get inserted?
     events_batch = [(TEST_SCHEMA_SCID, [another_event, self.event])]
     eventlogging.store_sql_events(self.meta, events_batch)
     table = self.meta.tables['TestSchema_123']
     # is the table on the db  and does it have the right data?
     s = sqlalchemy.sql.select([table])
     results = self.engine.execute(s)
     # the number of records in table must be the list size
     rows = results.fetchall()
     self.assertEqual(len(rows), 2)
Esempio n. 6
0
 def test_lazy_table_creation_with_meta(self):
     """If an attempt is made to store an event with meta (not encapsulated)
     for which no table exists, the schema is automatically retrieved and a
     suitable table generated."""
     eventlogging.store_sql_events(
         self.meta, TEST_META_SCHEMA_SCID, [self.event_with_meta])
     table_name = TABLE_NAME_FORMAT % TEST_META_SCHEMA_SCID
     self.assertIn(table_name, self.meta.tables)
     table = self.meta.tables[table_name]
     # is the table on the db  and does it have the right data?
     s = sqlalchemy.sql.select([table])
     results = self.engine.execute(s)
     row = results.fetchone()
     # see columns with print table.c
     self.assertEqual(row['meta_id'], self.event_with_meta.id())
Esempio n. 7
0
 def test_lazy_table_creation_with_meta(self):
     """If an attempt is made to store an event with meta (not encapsulated)
     for which no table exists, the schema is automatically retrieved and a
     suitable table generated."""
     eventlogging.store_sql_events(self.meta, TEST_META_SCHEMA_SCID,
                                   [self.event_with_meta])
     table_name = event_to_table_name(self.event_with_meta)
     self.assertIn(table_name, self.meta.tables)
     table = self.meta.tables[table_name]
     # is the table on the db  and does it have the right data?
     s = sqlalchemy.sql.select([table])
     results = self.engine.execute(s)
     row = results.fetchone()
     # see columns with print table.c
     self.assertEqual(row['meta_id'], self.event_with_meta.id())
Esempio n. 8
0
    def test_insertion_of_multiple_events_with_a_duplicate(self):
        """"If an insert with multiple events includes
        a duplicate and replace=True we have to
        insert the other items.
        """
        # insert event
        eventlogging.jrm.store_sql_events(
            self.meta, TEST_SCHEMA_SCID, [self.event])
        # now try to insert list of events in which this event is included
        another_event = next(self.event_generator)
        event_list = [another_event, self.event]
        eventlogging.store_sql_events(
            self.meta, TEST_SCHEMA_SCID, event_list, replace=True)

        # we should still have to insert the other record though
        table = self.meta.tables['TestSchema_123']
        s = sqlalchemy.sql.select([table])
        results = self.engine.execute(s)
        rows = results.fetchall()
        self.assertEqual(len(rows), 2)
Esempio n. 9
0
    def test_insertion_of_multiple_events_with_a_duplicate(self):
        """"If an insert with multiple events includes
        a duplicate and replace=True we have to
        insert the other items.
        """
        # insert event
        events_batch = [(TEST_SCHEMA_SCID, [self.event])]
        eventlogging.jrm.store_sql_events(self.meta, events_batch)
        # now try to insert list of events in which this event is included
        another_event = next(self.event_generator)
        event_list = [another_event, self.event]
        events_batch = [(TEST_SCHEMA_SCID, event_list)]
        eventlogging.store_sql_events(self.meta, events_batch, replace=True)

        # we should still have to insert the other record though
        table = self.meta.tables['TestSchema_123']
        s = sqlalchemy.sql.select([table])
        results = self.engine.execute(s)
        rows = results.fetchall()
        self.assertEqual(len(rows), 2)
Esempio n. 10
0
    def test_reflection(self):
        """Tables which exist in the database but not in the MetaData cache are
        correctly reflected."""
        eventlogging.store_sql_events(
            self.meta, TEST_SCHEMA_SCID, [self.event])

        # Tell Python to forget everything it knows about this database
        # by purging ``MetaData``. The actual data in the database is
        # not altered by this operation.
        del self.meta
        self.meta = sqlalchemy.MetaData(bind=self.engine)

        # Although ``TestSchema_123`` exists in the database, SQLAlchemy
        # is not yet aware of its existence:
        self.assertNotIn('TestSchema_123', self.meta.tables)

        # The ``checkfirst`` arg to :func:`sqlalchemy.Table.create`
        # will ensure that we don't attempt to CREATE TABLE on the
        # already-existing table:
        eventlogging.store_sql_events(
            self.meta, TEST_SCHEMA_SCID, [self.event], True)
        self.assertIn('TestSchema_123', self.meta.tables)
Esempio n. 11
0
    def test_reflection(self):
        """Tables which exist in the database but not in the MetaData cache are
        correctly reflected."""
        events_batch = [(TEST_SCHEMA_SCID, [self.event])]
        eventlogging.store_sql_events(self.meta, events_batch)

        # Tell Python to forget everything it knows about this database
        # by purging ``MetaData``. The actual data in the database is
        # not altered by this operation.
        del self.meta
        self.meta = sqlalchemy.MetaData(bind=self.engine)

        # Although ``TestSchema_123`` exists in the database, SQLAlchemy
        # is not yet aware of its existence:
        self.assertNotIn('TestSchema_123', self.meta.tables)

        # The ``checkfirst`` arg to :func:`sqlalchemy.Table.create`
        # will ensure that we don't attempt to CREATE TABLE on the
        # already-existing table:
        events_batch = [(TEST_SCHEMA_SCID, [self.event])]
        eventlogging.store_sql_events(self.meta, events_batch, True)
        self.assertIn('TestSchema_123', self.meta.tables)
Esempio n. 12
0
 def test_event_list_is_empty(self):
     """An empty event queue is handled well
     No exception is raised"""
     event_list = []
     eventlogging.store_sql_events(self.meta, TEST_SCHEMA_SCID, event_list)
Esempio n. 13
0
 def test_event_queue_is_empty(self):
     """An empty event queue is handled well
     No exception is raised"""
     event_list = []
     eventlogging.store_sql_events(self.meta, event_list)