Beispiel #1
0
    def test_update_many(self):
        w = self.app
        env = dict(REMOTE_ADDR="192.168.0.1")   # has access without key.

        changes = [
            Change("r1001", "root", "fancy comments",
                   ["/", "/goanna", "/goanna/webapi"], "goanna", "master"),
            Change("r2001", "lsc", "fly fishing is awesome", "/", "pyqa"),
        ]

        # serialise transaction data
        payload = dict(data=Goanna.pack_list_of_changes(changes))

        # post bulk update
        w.post("/update", payload, extra_environ=env, status=ACCESS_OK)

        # query results
        r = w.get("/query/goanna/master", status=ACCESS_OK)
        data = unpack(r.body)
        self.assertTrue(data.get("revision", None) == "r1001")

        r = w.get("/query/pyqa", status=ACCESS_OK)
        data = unpack(r.body)
        self.assertEqual(data.get("revision", None), "r2001")

        w.get("/query/pyqa/master", status=NOT_FOUND)

        # invalid data
        bad_payload = dict(data=Goanna.pack_list_of_changes(changes)[3:])
        w.post("/update", bad_payload, extra_environ=env, status=BAD_REQUEST)
Beispiel #2
0
    def test_standard_update_and_query(self):
        w = self.app
        env = dict(REMOTE_ADDR="192.168.0.1")   # has access without key.

        # query unknown content
        w.get("/query/p0/b0", status=NOT_FOUND)
        w.get("/query/p0/b0?from=123;to=5325", status=NOT_FOUND)

        # post some content
        c = Change("r123", "lsc", "no comments", ["/"], "p1")
        payload = dict(data=Goanna.pack_list_of_changes([c]))
        w.post("/update", payload, extra_environ=env, status=ACCESS_OK)

        # other branch should not exist
        w.get("/query/p1/b0", status=NOT_FOUND)

        # validate content
        r = w.get("/query/p1?brief", status=ACCESS_OK)  # brief version
        R = unpack(r.body)
        self.assertTrue(R["revision"] == c.revision)
        self.assertTrue("files" not in R)

        s = w.get("/query/p1", status=ACCESS_OK)
        S = unpack(s.body)
        self.assertTrue(S["revision"] == c.revision)
        self.assertTrue(S["project"] == c.project)
        self.assertTrue(S["branch"] == c.branch)
        self.assertTrue(S["files"] == c.data["files"])
        self.assertTrue(S["comments"] == c.data["comments"])
Beispiel #3
0
    def test_basic_query(self):
        g = self.goanna

        # query unknown data
        self.assertEqual(g.query_range("p0"), [])
        self.assertEqual(g.query_range("p0", "b0"), [])
        self.assertEqual(g.query_latest("p0"), None)
        self.assertEqual(g.query_latest("p0", "b0"), None)

        # add change
        c = Change("r123", "lsc", "This is a fake commit", [
            "/hello/world/.",
            "/hello/world/test.txt",
            "/hello/kitty/is/too_pink.com",
            "/donny/darko/.now",
            "/he/.",
        ], "project")
        g.post_changes(c)

        # this should not affect unknown projects
        self.assertEqual(g.query_latest("p0"), None)

        # query for latest change
        self.assertEqual(g.query_latest("project")[0], "r123")
        self.assertEqual(g.query_latest("project", None)[0], "r123")
        self.assertEqual(g.query_latest("project", "nobranch"), None)

        self.assertTrue(utils.unpack(g.query_latest("project", details=True)),
                        c.get_data())
        ts0 = g.query_latest("project")[1]

        sleep(0.05)  # sleep a while so we get a different timestamp
        # add multiple changes
        changes = [
            Change("897", "lsc", "commit", ["/", "/a"], "p0", "b0"),
            Change("s91", "djw", "comment", "/", "project"),
            Change("deadbeef", "root", "none", "/world", "p2", "b2"),
        ]
        g.post_changes(changes)
        self.assertEqual(g.query_latest("project", None)[0], "s91")

        ts1 = g.query_latest("project")[1]
        self.assertNotEqual(ts0, ts1)

        self.assertEqual(g.query_range("project", ts_upper=ts0), [])
        self.assertEqual(g.query_range("project", ts_lower=ts1), [])
        self.assertEqual(g.query_range("project", ts_lower=ts0), ["s91"])
        self.assertEqual(g.query_range("project", ts_upper=ts1), ["r123"])
        self.assertEqual(g.query_range("project"), ["r123", "s91"])

        r_list = g.query_range("project", details=True)
        self.assertTrue(utils.unpack(r_list[0]), c.get_data())
        self.assertTrue(utils.unpack(r_list[0]), changes[1].get_data())

        # test packing of list of Change instance
        packed_data = Goanna.pack_list_of_changes(changes)
        changes_2 = Goanna.unpack_list_of_changes(packed_data)
        self.assertEqual(changes, changes_2)
Beispiel #4
0
    def test_pack_unpack(self):
        d = {
            'nested_dict': {
                'contains_list': [1, 2, 3, None, "string", unicode("x")],
                'fourty-two': 42,
            },
            'string': 'with "quotes"',
            'list': [],
        }

        packed = utils.pack(d)
        unpacked = utils.unpack(packed)

        self.assertEqual(d, unpacked)
Beispiel #5
0
    def parse_changes(self, change_data):
        def _get_chdict(c):
            chdict = dict(
                project=c["project"],
                author=c["author"],
                files=c["files"],
                comments=c["comments"],
                revision=c["revision"],
                ts=c["ts"],
            )  # to be stripped out before submission

            # insert optional data
            for key in ("branch", "revlink", "repository", "codebase"):
                if key in c:
                    chdict[key] = c[key]

            if "change_ts" in c:
                chdict["when_timestamp"] = epoch2datetime(c["change_ts"])

            return chdict

        return [_get_chdict(c) for c in unpack(change_data)]
Beispiel #6
0
 def load_query_results(data):
     r = unpack(data)
     self.lastRevTimestamp = r["ts"]
     log.msg("GoannaPoller: initialising at revision %s" % r["revision"])