def test_single_insert(self, empty_warehouse, store): """ Insert a single Dimension instance. There shoudn't be any problems. """ Warehouse.use(empty_warehouse) Store.build() Store.insert(store) assert self._fetch_store_row_count() == 1
def test_insert(empty_warehouse): """ Inserts a fact with MAX_ITERATIONS ^ 2 rows. """ enable_logging() Warehouse.use(empty_warehouse) Store.build() stores = _get_instances('store') Store.insert(*stores) Product.build() products = _get_instances('product') Product.insert(*products) Sales.build() sales = _get_instances('sales') start_time = datetime.datetime.now() print 'Starting bulk insert of fact at ', start_time try: Sales.insert(*sales) except OperationalError: pytest.fail('The connection broke.') end_time = datetime.datetime.now() print 'Ending bulk insert of fact at ', end_time delta = end_time - start_time print 'Time taken = ', delta
def _generate_store(): instances = [] for store_id in xrange(1, MAX_ITERATIONS): obj = Store() obj['store_id'] = store_id obj['manager'] = 'Mr Smith %i' % store_id instances.append(obj) return instances
def test_duplicate_insert(self, empty_warehouse, store, modified_store): """ Insert a Dimension twice. The row shouldn't be duplicated. """ Warehouse.use(empty_warehouse) Store.build() Store.insert(store) Store.insert(store) assert self._fetch_store_row_count() == 1
def test_modified_insert(self, empty_warehouse, store, modified_store): """ Insert a Dimension, followed by a modified version. """ Warehouse.use(empty_warehouse) Store.build() Store.insert(store) Store.insert(modified_store) assert self._fetch_store_row_count() == 2
def test_null_values(self, empty_warehouse, store, null_store): """ If the second instance contains a NULL column, then we expect a new row to be created. """ Warehouse.use(empty_warehouse) Store.build() Store.insert(store) Store.insert(null_store) assert self._fetch_store_row_count() == 2
def test_null_values(self, empty_warehouse, null_store): """ Test that inserting NULL values into Columns doesn't break the unique keys i.e. if we keep on inserting the same row, where one column is NULL, it won't keep on making copies of that row. """ Warehouse.use(empty_warehouse) Store.build() Store.insert(null_store) Store.insert(null_store) assert self._fetch_store_row_count() == 1
def store(): obj = Store() obj['store_id'] = 1 obj['manager'] = 'Mr Smith' return obj
def null_store(): obj = Store() obj['store_id'] = 1 obj['manager'] = None return obj
def modified_store(): obj = Store() obj['store_id'] = 1 obj['manager'] = 'Mrs Smith' return obj
def test_can_drop_dimension(empty_warehouse): Warehouse.use(empty_warehouse) Store.create_table() Store.drop_table() assert not Store.table_exists
def test_cannot_create_dimension_twice(empty_warehouse): Warehouse.use(empty_warehouse) assert Store.create_table() assert not Store.create_table()
def test_can_create_dimension(empty_warehouse): Warehouse.use(empty_warehouse) assert Store.create_table() assert Store.table_exists