Пример #1
0
    def test_upsert_from_values(self) -> None:
        with self.db_adapter:
            test_metadata = ExampleMetadata(
                test_str="test",
                test_int=123,
                test_float=0.123,
                test_bool=True,
                test_timestamp=datetime.now(),
            )
            test1 = ExampleStore(
                a=["a", "b", "c"],
                b=[1, 2, 3],
                c=[True, False, True],
                metadata=test_metadata,
            )
            self.db_adapter.create_group(ExampleStore.data_token.data_group)
            self.db_adapter.create_group_table(ExampleStore.data_token,
                                               ExampleStore)
            self.db_adapter.create_index(ExampleStore.data_token,
                                         ExampleStore.a_index)
            self.db_adapter.insert(ExampleStore.data_token, test1)

            actual_metadata = self.db_adapter.get_group_table_metadata(
                ExampleStore.data_token, ExampleMetadata)
            assert_that(actual_metadata, equal_to(test_metadata))

            raw1 = self.db_adapter.query(ExampleStore.data_token)
            queried1 = ExampleStore.from_rows(raw1)
            assert_that(queried1.equals(test1), equal_to(True))

            test2_metadata = ExampleMetadata(
                test_str="test2",
                test_int=234,
                test_float=1.234,
                test_bool=False,
                test_timestamp=datetime.now(),
            )
            test2 = ExampleStore(a=["b", "e"],
                                 b=[4, 5],
                                 c=[True, False],
                                 metadata=test2_metadata)
            self.db_adapter.upsert(ExampleStore.data_token, test2,
                                   [ExampleStore.a])

            actual_metadata = self.db_adapter.get_group_table_metadata(
                ExampleStore.data_token, ExampleMetadata)
            assert_that(actual_metadata, equal_to(test2_metadata))

            raw1 = self.db_adapter.query(ExampleStore.data_token)
            queried2 = ExampleStore.from_rows(raw1)
            test2 = ExampleStore(a=["a", "b", "c", "e"],
                                 b=[1, 4, 3, 5],
                                 c=[True, True, True, False])
            assert_that(queried2.equals(test2), equal_to(True))
Пример #2
0
    def test_upsert_from_link(self) -> None:
        with self.db_adapter:
            test1 = ExampleStore(a=["a", "b", "c"],
                                 b=[1, 2, 3],
                                 c=[True, False, True])
            self.db_adapter.create_group(ExampleStore.data_token.data_group)
            self.db_adapter.create_group_table(ExampleStore.data_token,
                                               ExampleStore)
            self.db_adapter.create_index(ExampleStore.data_token,
                                         ExampleStore.a_index)
            self.db_adapter.insert(ExampleStore.data_token, test1)

            token2 = DataToken("test2", RAW_GROUP)
            test2 = ExampleStore(a=["b", "e"], b=[4, 5], c=[True, False])
            self.db_adapter.create_group_table(token2, ExampleStore)
            self.db_adapter.create_index(token2, ExampleStore.a_index)
            self.db_adapter.insert(token2, test2)

            linked_store = ExampleStore.from_backend(MockBackend(
                token2, test2.columns),
                                                     validate=False)
            self.db_adapter.upsert(ExampleStore.data_token, linked_store,
                                   [ExampleStore.a])

            raw1 = self.db_adapter.query(ExampleStore.data_token)
            queried2 = ExampleStore.from_rows(raw1)
            test2 = ExampleStore(a=["a", "b", "c", "e"],
                                 b=[1, 4, 3, 5],
                                 c=[True, True, True, False])
            assert_that(queried2.equals(test2), equal_to(True))
Пример #3
0
    def test_delete(self) -> None:
        with self.db_adapter:
            test1 = ExampleStore(a=["a", "b", "c"],
                                 b=[1, 2, 3],
                                 c=[True, False, True])
            self.db_adapter.create_group(ExampleStore.data_token.data_group)
            self.db_adapter.create_group_table(ExampleStore.data_token,
                                               ExampleStore)
            self.db_adapter.insert(ExampleStore.data_token, test1)

            raw1 = self.db_adapter.query(ExampleStore.data_token)
            queried1 = ExampleStore.from_rows(raw1)
            assert_that(queried1.equals(test1), equal_to(True))

            self.db_adapter.delete(ExampleStore.data_token,
                                   ExampleStore.b == 2)
            raw2 = self.db_adapter.query(ExampleStore.data_token)
            queried2 = ExampleStore.from_rows(raw2)
            test2 = ExampleStore(a=["a", "c"], b=[1, 3], c=[True, True])
            assert_that(queried2.equals(test2), equal_to(True))
Пример #4
0
    def test_insert_from_values(self) -> None:
        with self.db_adapter:
            test1 = ExampleStore(a=["a", "b", "c"],
                                 b=[1, 2, 3],
                                 c=[True, False, True])
            self.db_adapter.create_group(ExampleStore.data_token.data_group)
            self.db_adapter.create_group_table(ExampleStore.data_token,
                                               ExampleStore)
            self.db_adapter.insert(ExampleStore.data_token, test1)

            raw1 = self.db_adapter.query(ExampleStore.data_token)
            queried1 = ExampleStore.from_rows(raw1)
            assert_that(queried1.equals(test1), equal_to(True))

            test_metadata = ExampleMetadata(
                test_str="test",
                test_int=123,
                test_float=0.123,
                test_bool=True,
                test_timestamp=datetime.now(),
            )
            test2 = ExampleStore(a=["d"],
                                 b=[4],
                                 c=[False],
                                 metadata=test_metadata)
            self.db_adapter.insert(ExampleStore.data_token, test2)

            actual_metadata = self.db_adapter.get_group_table_metadata(
                ExampleStore.data_token, ExampleMetadata)
            assert_that(actual_metadata, equal_to(test_metadata))

            test3 = ExampleStore.concat([test1, test2], ignore_index=True)
            raw2 = self.db_adapter.query(ExampleStore.data_token)
            queried2 = ExampleStore.from_rows(raw2)

            assert_that(queried2.equals(test3), equal_to(True))
Пример #5
0
    def test_insert_from_link(self) -> None:
        with self.db_adapter:
            test1 = ExampleStore(a=["a", "b", "c"],
                                 b=[1, 2, 3],
                                 c=[True, False, True])
            self.db_adapter.create_group(ExampleStore.data_token.data_group)
            self.db_adapter.create_group_table(ExampleStore.data_token,
                                               ExampleStore)
            self.db_adapter.insert(ExampleStore.data_token, test1)

            token2 = DataToken("test2", RAW_GROUP)
            self.db_adapter.create_group_table(token2, ExampleStore)

            linked_store = ExampleStore.from_backend(MockBackend(
                ExampleStore.data_token, test1.columns),
                                                     validate=False)
            self.db_adapter.insert(token2, linked_store)

            raw1 = self.db_adapter.query(token2)
            queried1 = ExampleStore.from_rows(raw1)
            assert_that(test1.equals(queried1), equal_to(True))