コード例 #1
0
    def test_update(self) -> None:
        original_values = {}
        for i in range(10):
            k = os.urandom(10).hex()
            v1 = {"value": os.urandom(10).hex()}
            original_values[k] = v1
        entries = [WalletDataRow(*t) for t in original_values.items()]
        with SynchronousWriter() as writer:
            self.store.create(entries,
                              completion_callback=writer.get_callback())
            assert writer.succeeded()

        new_values = original_values.copy()
        for k in original_values.keys():
            new_values[k] = {"value": os.urandom(10).hex()}
        entries = [WalletDataRow(*t) for t in new_values.items()]
        with SynchronousWriter() as writer:
            self.store.update(entries,
                              completion_callback=writer.get_callback())
            assert writer.succeeded()

        rows = self.store.read()
        assert len(rows) == len(new_values)
        for row in rows:
            assert row in entries
コード例 #2
0
    def test_upsert(self) -> None:
        with SynchronousWriter() as writer:
            self.store.upsert([ WalletDataRow("A", "B") ],
                completion_callback=writer.get_callback())
            assert writer.succeeded()
        assert self.store.get_value("A") == "B"

        with SynchronousWriter() as writer:
            self.store.upsert([ WalletDataRow("A", "C") ],
                completion_callback=writer.get_callback())
            assert writer.succeeded()

        assert self.store.get_value("A") == "C"
        values = self.store.read([ "A" ])
        assert len(values) == 1
コード例 #3
0
 def test_get(self):
     k = os.urandom(10).hex()
     v = os.urandom(10).hex()
     with SynchronousWriter() as writer:
         self.store.create([ WalletDataRow(k, v) ], completion_callback=writer.get_callback())
         assert writer.succeeded()
     byte_data = self.store.get_value(k)
     assert byte_data is not None
     assert byte_data == v
コード例 #4
0
    def test_create(self):
        kvs = [ WalletDataRow(os.urandom(10).hex(), [os.urandom(10).hex()]) for i in range(10) ]

        self.store.timestamp = 1
        with SynchronousWriter() as writer:
            self.store.create(kvs, completion_callback=writer.get_callback())
            assert writer.succeeded()

        kvs2 = self.store.read([ k for (k, v) in kvs ])
        assert len(kvs) == len(kvs2)
        for t in kvs:
            assert t in kvs2
コード例 #5
0
    def test_add(self):
        k = os.urandom(10).hex()
        v = [os.urandom(10).hex()]

        self.store.timestamp = 1
        with SynchronousWriter() as writer:
            self.store.create([ WalletDataRow(k, v) ], completion_callback=writer.get_callback())
            assert writer.succeeded()

        row = self.store.get_row(k)
        assert row is not None
        assert isinstance(row, WalletDataRow)
        assert row.key == k # key
        assert row.value == v # ByteData
コード例 #6
0
    def test_delete(self):
        k = os.urandom(10).hex()
        v = [ os.urandom(10).hex() ]

        self.store.timestamp = 1
        with SynchronousWriter() as writer:
            self.store.create([ WalletDataRow(k, v) ], completion_callback=writer.get_callback())
            assert writer.succeeded()

        self.store.timestamp = 2
        with SynchronousWriter() as writer:
            self.store.delete(k, completion_callback=writer.get_callback())
            assert writer.succeeded()

        row = self.store.get_row(k)
        assert row is None