Ejemplo n.º 1
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))
Ejemplo n.º 2
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))