def test_download(self): classname = "AgentUnittest" + os.urandom(8).encode("hex") cache = Cache() with APITestServer( "/jobtypes/%s/versions/1" % classname, headers={"Content-Type": "application/json"}, code=OK, response=json.dumps({"data": "This is a job type"}) ): response = yield cache._download_jobtype(classname, 1) self.assertEqual(response.code, OK) data = response.json() self.assertEqual(data.get("data"), "This is a job type")
def test_cache(self): cache = Cache() classname = "Test%s" % os.urandom(8).encode("hex") version = 1 code = os.urandom(8).encode("hex") cache_key = "Key%s" % classname filepath = cache._cache_filepath(cache_key, classname, version) jobtype = {"classname": classname, "code": code, "version": version} def written(data): self.assertEqual(data[0]["classname"], classname) if data[1] is not None: self.assertEqual(data[1], filepath) self.assertTrue(isfile(filepath)) cached = cache._cache_jobtype(cache_key, jobtype) cached.addCallback(written) return cached
def test_filename(self): cache = Cache() self.assertEqual( cache._cache_filepath("foobar", "someclass", 1), str(join( Cache.CACHE_DIRECTORY, "foobar_someclass_v1.py")))