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)
def test_poll(self): ###### First poll - state initialised using latest revision self.intercept_url_load("[]", pack(dict(revision="r123", ts="12345.11"))) d = self.changesource.poll() def check(_): self.assertEqual(len(self.changes_added), 0) self.assertEqual(self.requested_url, [ "http://localhost:8080/query/goanna?brief", "http://localhost:8080/query/goanna?from=12345.11" ]) d.addCallback(check) yield d ####### Subsequent poll with no updates self.intercept_url_load("[]", pack(dict(revision="r123", ts=12345.11))) d = self.changesource.poll() def check(_): self.assertEqual(len(self.changes_added), 0) self.assertEqual(self.requested_url, [ "http://localhost:8080/query/goanna?from=12345.11" ]) d.addCallback(check) yield d ####### Subsequent poll with single update self.changes_added = [] # reset self.intercept_url_load(pack([ dict(revision="r123", project="goanna", author="lsc", files=["/README.md"], comments="no comments", ts=22222.22) ])) d = self.changesource.poll() def check(_): self.assertEqual(len(self.changes_added), 1) self.assertEqual(self.changes_added[0]["revision"], "r123") self.assertEqual(self.requested_url, [ "http://localhost:8080/query/goanna?from=12345.11" ]) d.addCallback(check) yield d ####### Subsequent poll with multiple update self.changes_added = [] # reset self.intercept_url_load(pack([ dict(revision="r124", project="goanna", author="djw", files=["/hello/word"], comments="rawr", ts="22223.33"), dict(revision="r125", project="goanna", author="cg", files=["/a", "/b"], comments="eeeek", ts="22224.44") ])) d = self.changesource.poll() def check(_): self.assertEqual(len(self.changes_added), 2) self.assertEqual(self.changes_added[0]["revision"], "r124") self.assertEqual(self.changes_added[1]["revision"], "r125") self.assertEqual(self.requested_url, [ "http://localhost:8080/query/goanna?from=22222.22" ]) d.addCallback(check) yield d