def compare_jblob(jblob1, jblob2): if jblob1 == jblob2: return True blob1 = utils.jblob2bytes(jblob1) blob2 = utils.jblob2bytes(jblob2) if blob1 == blob2: return True jjblob1 = utils.bytes2jblob(blob1) jjblob2 = utils.bytes2jblob(blob2) return jjblob1 == jjblob2
def test_bytes2jblob_json(): vec = json.dumps(jsonvec).encode("utf8") res = utils.bytes2jblob(vec, fmthint="json") assert res == {"format": "json", "blob": jsonvec} vec_b64 = base64.b64encode(vec).decode("utf8") res = utils.bytes2jblob(vec) assert res == {"format": "base64", "blob": vec_b64} vec = b'{ "abc": 456, "broken json }' vec_b64 = base64.b64encode(vec).decode("utf8") res = utils.bytes2jblob(vec, fmthint="json") assert res == {"format": "base64", "blob": vec_b64}
def test_configs_get_empty(curieapi_empty): r = curieapi_empty.configs.get("master") assert r.status_code == 200 res = r.body print(res) assert res["documents"] == {x:[] for x in DOCUMENTS_PATH } assert res["blobs"] == {k:bytes2jblob(v) for k,v in BLOBS_BOOTSTRAP.items()}
def test_bytes2jblob_json(): vec = b'A' * 500 res = utils.bytes2jblob(vec) assert res == { "format": "bz2+base64", "blob": "QlpoOTFBWSZTWYtV77YAAACEAKAAIAggACEmQZioDi7kinChIRar32w=" } res2 = utils.jblob2bytes(res) assert res2 == vec
def _get_blob(self, blobname, version=None): bpath = utils.BLOBS_PATH[blobname] gitblob = self.get_tree(version) / bpath hint = "json" if bpath.endswith(".json") else None return utils.bytes2jblob(gitblob.data_stream.read(), fmthint=hint)
def update(config:str, blob:BlobsEnum, fname:str=typer.Argument(None)): f = open(fname, "rb") if fname else sys.stdin.buffer jb = utils.bytes2jblob(f.read()) output(state.api.blobs.update(config, blob.value, body=jb).body)