コード例 #1
0
ファイル: test_dimension.py プロジェクト: rtogo/pyscd
    def test_modify_type_2_column(self):
        # Update dimension with first file
        import_orders(self.filename, 'tests/data/add 1 row.csv')

        self.h5file = tb.open_file(self.filename, mode='a')
        h5table = self.h5file.root.orders.table
        h5dim = self.h5file.root.dimorders.table

        dim = scd(connection=h5dim,
                  lookupatts=['order', 'line'],
                  type1atts=[],
                  type2atts=['status', 'currency'],
                  asof='2015-10-23')

        for row in h5table.iterrows():
            dim.update(row)
        h5dim.flush()
        self.h5file.close()

        # Update dimension with second file
        import_orders(self.filename, 'tests/data/modify 1 row.csv')

        self.h5file = tb.open_file(self.filename, mode='a')
        h5table = self.h5file.root.orders.table
        h5dim = self.h5file.root.dimorders.table

        dim = scd(connection=h5dim,
                  lookupatts=['order', 'line'],
                  type1atts=[],
                  type2atts=['status', 'currency'],
                  asof='2015-10-23')

        for row in h5table.iterrows():
            dim.update(row)
        h5dim.flush()

        # Check if one row was inserted
        self.assertEqual(len(h5dim), 3)

        # Check first version row
        expected = str((b'1', 10, b'Not Delivered', b'USD',
                        1, 1445558400000000000, 1445558400000000000, 1, False,
                        b'39510ad9dc54f9e05bb3cf9db33ab1a1b0b66114'))
        self.assertEqual(str(h5dim[0]), expected)

        # Check second version row
        expected = str((b'1', 10, b'Completed', b'USD',
                        3, 1445558400000000000, 7258032000000000000, 2, True,
                        b'0d4f629999f2dd1a2b37059f7f5364564a51ad37'))
        self.assertEqual(str(h5dim[2]), expected)

        self.h5file.close()
コード例 #2
0
ファイル: test_dimension.py プロジェクト: rtogo/pyscd
    def test_import_new_data_fill_scd_columns(self):
        import_orders(self.filename, 'tests/data/orders x1.csv')

        self.h5file = tb.open_file(self.filename, mode='a')
        h5table = self.h5file.root.orders.table
        h5dim = self.h5file.root.dimorders.table

        dim = scd(connection=h5dim,
                  lookupatts=['order'],
                  type1atts=[],
                  type2atts=['line', 'status', 'currency'],
                  asof='2015-10-23')

        for row in h5table.iterrows():
            dim.update(row)
        h5dim.flush()

        expected = str((b'1', 10, b'Not Delivered', b'USD',
                        1, 1445558400000000000, 7258032000000000000, 1, True,
                        b'39510ad9dc54f9e05bb3cf9db33ab1a1b0b66114'))

        self.assertEqual(len(h5dim), 1)
        self.assertEqual(str(h5dim[0]), expected)

        self.h5file.close()
コード例 #3
0
ファイル: test_dimension.py プロジェクト: rtogo/pyscd
    def test_modify_type_1_column(self):
        # Update dimension with first file
        import_orders(self.filename, 'tests/data/add 1 row.csv')

        self.h5file = tb.open_file(self.filename, mode='a')
        h5table = self.h5file.root.orders.table
        h5dim = self.h5file.root.dimorders.table

        dim = scd(connection=h5dim,
                  lookupatts=['order', 'line'],
                  type1atts=['status'],
                  type2atts=['currency'],
                  asof='2015-10-23')

        for row in h5table.iterrows():
            dim.update(row)
        h5dim.flush()
        self.h5file.close()

        # Update dimension with second file
        import_orders(self.filename, 'tests/data/modify 1 row.csv')

        self.h5file = tb.open_file(self.filename, mode='a')
        h5table = self.h5file.root.orders.table
        h5dim = self.h5file.root.dimorders.table

        dim = scd(connection=h5dim,
                  lookupatts=['order', 'line'],
                  type1atts=['status'],
                  type2atts=['currency'],
                  asof='2015-10-23')

        for row in h5table.iterrows():
            dim.update(row)
        h5dim.flush()

        expected = str((b'1', 10, b'Completed', b'USD',
                        1, 1445558400000000000, 7258032000000000000, 1, True,
                        b'0d4f629999f2dd1a2b37059f7f5364564a51ad37'))

        self.assertEqual(len(h5dim), 2)
        self.assertEqual(str(h5dim[0]), expected)

        self.h5file.close()
コード例 #4
0
ファイル: test_dimension.py プロジェクト: rtogo/pyscd
    def test_add_new_row(self):
        # Update dimension with first file
        import_orders(self.filename, 'tests/data/orders x1.csv')

        self.h5file = tb.open_file(self.filename, mode='a')
        h5table = self.h5file.root.orders.table
        h5dim = self.h5file.root.dimorders.table

        dim = scd(connection=h5dim,
                  lookupatts=['order', 'line'],
                  type1atts=[],
                  type2atts=['status', 'currency'],
                  asof='2015-10-23')

        for row in h5table.iterrows():
            dim.update(row)
        h5dim.flush()
        self.h5file.close()

        # Update dimension with second file
        import_orders(self.filename, 'tests/data/add 1 row.csv')

        self.h5file = tb.open_file(self.filename, mode='a')
        h5table = self.h5file.root.orders.table
        h5dim = self.h5file.root.dimorders.table

        dim = scd(connection=h5dim,
                  lookupatts=['order', 'line'],
                  type1atts=[],
                  type2atts=['status', 'currency'],
                  asof='2015-10-23')

        for row in h5table.iterrows():
            dim.update(row)
        h5dim.flush()

        expected = str((b'1', 20, b'Completed', b'USD',
                        2, 1445558400000000000, 7258032000000000000, 1, True,
                        b'47580ba821ac3f942c13582f88a73c644241396a'))

        self.assertEqual(len(h5dim), 2)
        self.assertEqual(str(h5dim[1]), expected)

        self.h5file.close()
コード例 #5
0
ファイル: test_dimension.py プロジェクト: rtogo/pyscd
    def test_update_info_updated_type2_rows(self):
        # Update dimension with first file
        import_orders(self.filename, 'tests/data/add 1 row.csv')

        self.h5file = tb.open_file(self.filename, mode='a')
        h5table = self.h5file.root.orders.table
        h5dim = self.h5file.root.dimorders.table

        dim = scd(connection=h5dim,
                  lookupatts=['order', 'line'],
                  type1atts=[],
                  type2atts=['status', 'currency'],
                  asof='2015-10-23')

        for row in h5table.iterrows():
            dim.update(row)
        h5dim.flush()
        self.h5file.close()

        # Update dimension with second file
        import_orders(self.filename, 'tests/data/modify 1 row.csv')

        self.h5file = tb.open_file(self.filename, mode='a')
        h5table = self.h5file.root.orders.table
        h5dim = self.h5file.root.dimorders.table

        dim = scd(connection=h5dim,
                  lookupatts=['order', 'line'],
                  type1atts=[],
                  type2atts=['status', 'currency'],
                  asof='2015-10-23')

        for row in h5table.iterrows():
            dim.update(row)
        h5dim.flush()

        self.assertEqual(dim.new_rows, 0)
        self.assertEqual(dim.updated_type1_rows, 0)
        self.assertEqual(dim.updated_type2_rows, 1)

        self.h5file.close()
コード例 #6
0
ファイル: test_dimension.py プロジェクト: rtogo/pyscd
    def test_import_same_data_several_times_does_nothing(self):
        import_workcenters(self.filename,
                           'tests/data/Centros de trabalho.xlsx',
                           'Centros de Trabalho')

        # Import 1st time
        self.h5file = tb.open_file(self.filename, mode='a')
        h5table = self.h5file.root.workcenters.table
        h5dim = self.h5file.root.dimworkcenters.table

        dim = scd(connection=h5dim,
                  lookupatts=['workcenter'],
                  type1atts=[],
                  type2atts=['description', 'group', 'hours'],
                  asof='2015-10-23')

        for row in h5table.iterrows():
            dim.update(row)
        h5dim.flush()

        self.assertEqual(dim.new_rows, 43)
        self.assertEqual(dim.updated_type1_rows, 0)
        self.assertEqual(dim.updated_type2_rows, 0)

        self.h5file.close()

        # Import 2st time
        self.h5file = tb.open_file(self.filename, mode='a')
        h5table = self.h5file.root.workcenters.table
        h5dim = self.h5file.root.dimworkcenters.table

        dim = scd(connection=h5dim,
                  lookupatts=['workcenter'],
                  type1atts=[],
                  type2atts=['description', 'group', 'hours'],
                  asof='2015-10-23')

        for row in h5table.iterrows():
            dim.update(row)
        h5dim.flush()

        self.assertEqual(dim.new_rows, 0)
        self.assertEqual(dim.updated_type1_rows, 0)
        self.assertEqual(dim.updated_type2_rows, 0)

        self.h5file.close()

        # Import 3st time
        self.h5file = tb.open_file(self.filename, mode='a')
        h5table = self.h5file.root.workcenters.table
        h5dim = self.h5file.root.dimworkcenters.table

        dim = scd(connection=h5dim,
                  lookupatts=['workcenter'],
                  type1atts=[],
                  type2atts=['description', 'group', 'hours'],
                  asof='2015-10-23')

        for row in h5table.iterrows():
            dim.update(row)
        h5dim.flush()

        self.assertEqual(dim.new_rows, 0)
        self.assertEqual(dim.updated_type1_rows, 0)
        self.assertEqual(dim.updated_type2_rows, 0)

        self.h5file.close()