Beispiel #1
0
    def test_fetch_one_too_many(self):
        from collective.bookmarks.storage import Bookmarks
        from repoze.catalog.query import Eq
        from souper.soup import Record

        import uuid

        bookmarks = Bookmarks()
        data = {"owner": "kim stanley", "uid": uuid.uuid4(), "group": ""}
        record1 = Record()
        record1.attrs["owner"] = data["owner"]
        record1.attrs["uid"] = data["uid"]
        record1.attrs["group"] = data["group"]
        record2 = Record()
        record2.attrs["owner"] = data["owner"]
        record2.attrs["uid"] = data["uid"]
        record2.attrs["group"] = data["group"]
        bookmarks._soup.add(record1)
        bookmarks._soup.add(record2)

        with self.assertRaises(ValueError):
            bookmarks._fetch_one(
                Eq("owner", data["owner"])
                & Eq("uid", data["uid"])
                & Eq("group", data["group"]))
Beispiel #2
0
    def test_update_existing(self):
        from collective.bookmarks.storage import Bookmarks
        from repoze.catalog.query import Eq

        import uuid

        bookmarks = Bookmarks()
        data = {
            "owner": "kim stanley",
            "uid": uuid.uuid4(),
            "group": "",
            "payload": {}
        }
        bookmarks.add(data["owner"], data["uid"], data["group"],
                      data["payload"])
        new_payload = {"foo": "bar"}
        result = bookmarks.update(data["owner"], data["uid"], data["group"],
                                  new_payload)
        self.assertIsNotNone(result)

        record = bookmarks._fetch_one(
            Eq("owner", data["owner"])
            & Eq("uid", data["uid"])
            & Eq("group", data["group"]))
        self.assertEqual(record.attrs["payload"], new_payload)
Beispiel #3
0
    def test_add_first(self):
        from collective.bookmarks.storage import Bookmarks
        from repoze.catalog.query import Eq

        import math
        import time
        import uuid

        bookmarks = Bookmarks()
        data = {
            "owner": "kim stanley",
            "uid": uuid.uuid4(),
            "group": "",
            "payload": {},
            "created": math.floor(time.time()),
        }
        result = bookmarks.add(data["owner"], data["uid"], data["group"],
                               data["payload"])
        self.assertIsNotNone(result)

        record = bookmarks._fetch_one(
            Eq("owner", data["owner"])
            & Eq("uid", data["uid"])
            & Eq("group", data["group"]))
        self.assertIn("created", record.attrs)
        record.attrs["created"] = data["created"]
        self.assertEqual(data, bookmarks._dictify(record))
Beispiel #4
0
    def test_fetch_one_non_existing(self):
        from collective.bookmarks.storage import Bookmarks
        from repoze.catalog.query import Eq

        import uuid

        bookmarks = Bookmarks()
        result = bookmarks._fetch_one(
            Eq("owner", "harry") & Eq("uid", uuid.uuid4())
            & Eq("group", "cool stuff"))
        self.assertIs(result, None)
Beispiel #5
0
    def test_fetch_one_existing(self):
        from collective.bookmarks.storage import Bookmarks
        from repoze.catalog.query import Eq
        from souper.soup import Record

        import uuid

        bookmarks = Bookmarks()
        data = {"owner": "kim stanley", "uid": uuid.uuid4(), "group": ""}
        record = Record()
        record.attrs["owner"] = data["owner"]
        record.attrs["uid"] = data["uid"]
        record.attrs["group"] = data["group"]
        bookmarks._soup.add(record)

        result = bookmarks._fetch_one(
            Eq("owner", data["owner"])
            & Eq("uid", data["uid"])
            & Eq("group", data["group"]))
        self.assertIs(result, record)
Beispiel #6
0
    def test_delete_existing(self):
        from collective.bookmarks.storage import Bookmarks
        from repoze.catalog.query import Eq

        import uuid

        bookmarks = Bookmarks()
        data = {
            "owner": "kim stanley",
            "uid": uuid.uuid4(),
            "group": "",
            "payload": {}
        }
        bookmarks.add(data["owner"], data["uid"], data["group"],
                      data["payload"])
        result = bookmarks.delete(data["owner"], data["uid"], data["group"])
        self.assertIs(result, True)

        record = bookmarks._fetch_one(
            Eq("owner", data["owner"])
            & Eq("uid", data["uid"])
            & Eq("group", data["group"]))
        self.assertIsNone(record)