Skip to content
Snippets Groups Projects
Commit 510f7dc3 authored by Antoine R. Dumont's avatar Antoine R. Dumont
Browse files

Use the expected data type for storage's api

Need to send the sha*s as bytes
parent dcf82bde
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ import requests
import json
from swh.web.ui.main import app
from swh.core.json import SWHJSONEncoder
if 'conf' in app.config:
......@@ -70,7 +71,8 @@ def create_request(method, api_url, data=None):
query = {'method': method,
'url': api_url}
if data:
query.update({'data': json.dumps(data) if data else '',
json_data = json.dumps(data, cls=SWHJSONEncoder) if data else ''
query.update({'data': json_data,
'headers': {'Content-Type': MIMETYPE}})
return query
......@@ -5,6 +5,7 @@
from swh.web.ui.back import http, api_query
from swh.core import hashutil
import json
......@@ -33,5 +34,5 @@ def search(base_url, hashes):
#return []
#return [{'title': 'some title', 'text': 'some text'}]
q = api_query.api_storage_content_present({'content': [hashes]})
q = api_query.api_storage_content_present({'content': hashes})
return http.execute(base_url, q, result_fn=deal_with_result)
......@@ -6,6 +6,8 @@
import re
from swh.core import hashutil
def parse(query):
"""Parse a formalized get query.
......@@ -31,8 +33,8 @@ def group_by_checksums(hashes):
hashes_m = {}
for h in hashes:
if re.search(sha256_regexp, h):
hashes_m.update({'sha256': h})
hashes_m.update({'sha256': hashutil.hex_to_hash(h)})
elif re.search(sha1_regexp, h):
hashes_m.update({'sha1': h})
hashes_m.update({'sha1': hashutil.hex_to_hash(h)})
return hashes_m
......@@ -8,7 +8,7 @@ import unittest
from nose.tools import istest
from swh.web.ui import query
from swh.core import hashutil
class QueryTestCase(unittest.TestCase):
@istest
......@@ -38,5 +38,5 @@ class QueryTestCase(unittest.TestCase):
# for i in res:
# print(i)
self.assertEquals(res['sha1'], input_sha1)
self.assertEquals(res['sha256'], input_sha256)
self.assertEquals(res['sha1'], hashutil.hex_to_hash(input_sha1))
self.assertEquals(res['sha256'], hashutil.hex_to_hash(input_sha256))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment