Exemplo n.º 1
0
    def test_marker(self):
        """test using a marker with a directory tree"""
        keys = [
            u"aaa/b/cccc/1", 
            u"aaa/b/ccccccccc/1", 
            u"aaa/b/ccccccccc/2", 
            u"aaa/b/ccccccccc/3", 
            u"aaa/b/dddd/1", 
            u"aaa/b/dddd/2", 
            u"aaa/e/ccccccccc/1", 
            u"fff/e/ccccccccc/1", 
        ]
        cutoff = len(keys) / 2
        _load_test_data(self._connection, keys)

        result1 = listmatch(self._connection, _collection_id, max_keys=cutoff)
        self.assertTrue("keys" in result1, result1)
        self.assertTrue(len(result1["keys"]) <= cutoff, result1)
        self.assertTrue(result1["truncated"], result1)

        result2 = listmatch(
            self._connection, _collection_id, marker=result1["keys"][-1]
        )
        self.assertTrue("keys" in result2, result2)
        self.assertFalse(result2["truncated"], result2)

        self.assertEqual(
            len(result1["keys"]) + len(result2["keys"]), 
            len(keys),
            (result1, result2, )
        )
Exemplo n.º 2
0
    def test_delimiter(self):
        """test using a delimiter with a directory tree"""
        keys = [
            u"aaa",
            u"aaa/b/cccc/1", 
            u"aaa/b/ccccccccc/1", 
            u"aaa/b/ccccccccc/2", 
            u"aaa/b/ccccccccc/3", 
            u"aaa/b/dddd/1", 
            u"aaa/b/dddd/2", 
            u"aaa/e/ccccccccc/1", 
            u"fff/e/ccccccccc/1", 
        ]
        _load_test_data(self._connection, keys)

        result = listmatch(self._connection, _collection_id, delimiter=u"/")
        self.assertFalse("keys" in result, result)
        self.assertTrue("prefixes" in result, result)
        result_set = set(result["prefixes"])
        self.assertEqual(result_set, set([u"aaa/", u"fff/"]))

        result = listmatch(
            self._connection, _collection_id, prefix=u"aaa/", delimiter=u"/"
        )
        self.assertFalse("keys" in result, result)
        self.assertTrue("prefixes" in result, result)
        result_set = set(result["prefixes"])
        self.assertEqual(result_set, set([u"b/", u"e/"]), result_set)
Exemplo n.º 3
0
 def test_empty_collection(self):
     """test querying an empty collection"""
     _clear_test_data(self._connection)
     result = listmatch(self._connection, _collection_id, "")
     self.assertTrue("keys" in result, result)
     self.assertEqual(len(result["keys"]), 0, result)
     self.assertFalse(result["truncated"], result)
Exemplo n.º 4
0
    def test_tree(self):
        """test storing and retrieving a directory tree"""
        keys = [
            u"aaa/b/cccc/1", 
            u"aaa/b/ccccccccc/1", 
            u"aaa/b/ccccccccc/2", 
            u"aaa/b/ccccccccc/3", 
            u"aaa/b/dddd/1", 
            u"aaa/b/dddd/2", 
            u"aaa/e/ccccccccc/1", 
            u"fff/e/ccccccccc/1", 
        ]
        _load_test_data(self._connection, keys)

        test_prefix = u"aaa/"
        result = listmatch(
            self._connection, _collection_id, prefix=test_prefix
        )
        self.assertTrue("keys" in result, result)
        self.assertEqual(len(result["keys"]), 7, result)
        self.assertFalse(result["truncated"], result)
        for key in result["keys"]:
            self.assertTrue(key.startswith(test_prefix))

        result = listmatch(self._connection, _collection_id, prefix=u"aaa/b")
        self.assertTrue("keys" in result, result)
        self.assertEqual(len(result["keys"]), 6, result)
        self.assertFalse(result["truncated"], result)

        result = listmatch(
            self._connection, _collection_id, prefix=u"aaa/b/ccccccccc/"
        )
        self.assertTrue("keys" in result, result)
        self.assertEqual(len(result["keys"]), 3, result)
        self.assertFalse(result["truncated"], result)

        result = listmatch(
            self._connection, _collection_id, prefix=u"aaa/b/dddd"
        )
        self.assertTrue("keys" in result, result)
        self.assertEqual(len(result["keys"]), 2)
        self.assertFalse(result["truncated"], result)

        result = listmatch(self._connection, _collection_id, prefix=u"aaa/e")
        self.assertTrue("keys" in result, result)
        self.assertEqual(len(result["keys"]), 1)
        self.assertFalse(result["truncated"], result)
Exemplo n.º 5
0
 def test_exact_match(self):
     """test getting a single key"""
     keys = [u"aaa", u"bbb", u"ccc", ]
     _load_test_data(self._connection, keys)
     result = listmatch(self._connection, _collection_id, prefix=keys[0])
     self.assertTrue("keys" in result, result)
     self.assertEqual(len(result["keys"]), 1, result)
     self.assertFalse(result["truncated"], result)
     self.assertEqual(result["keys"][0], keys[0])
Exemplo n.º 6
0
 def test_max_keys(self):
     """test cutting off the query at max_keys"""
     keys = [u"test-key1", u"test_key2", u"test_key3", ]
     _load_test_data(self._connection, keys)
     result = listmatch(
         self._connection, _collection_id, max_keys=len(keys)-1
     ) 
     self.assertTrue("keys" in result, result)
     self.assertEqual(len(result["keys"]), len(keys)-1, result)
     self.assertTrue(result["truncated"], result)
Exemplo n.º 7
0
 def test_tombstone(self):
     """
     test finding the most recent of multiple rows when it is a tombstone
     """
     test_key = u"test_key"
     data_time = create_timestamp()
     tombstone_time = data_time + timedelta(hours=1)
     self._connection.execute("begin")
     self._connection.execute(_insert_test_row_with_timestamp_and_tombstone, 
                        [_collection_id, test_key, data_time, 42, False])
     self._connection.execute(_insert_test_row_with_timestamp_and_tombstone, 
                        [_collection_id, test_key, tombstone_time, 0, True])
     self._connection.commit()
     result = listmatch(self._connection, _collection_id)
     self.assertTrue("keys" in result, result)
     self.assertEqual(len(result["keys"]), 0)
     self.assertFalse(result["truncated"], result)