Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/views.py
Show All 10 Lines | |||||
from typing import Dict | from typing import Dict | ||||
from rest_framework.decorators import api_view | from rest_framework.decorators import api_view | ||||
from rest_framework.response import Response | from rest_framework.response import Response | ||||
from swh.model import from_disk | from swh.model import from_disk | ||||
from swh.model.hashutil import hash_to_hex | from swh.model.hashutil import hash_to_hex | ||||
from swh.model.model import Content | from swh.model.model import Content | ||||
from swh.model.from_disk import DiskBackedContent | |||||
from swh.web.common.highlightjs import get_hljs_language_from_filename | from swh.web.common.highlightjs import get_hljs_language_from_filename | ||||
from swh.web.tests.data import get_tests_data | from swh.web.tests.data import get_tests_data | ||||
_content_code_data_exts = {} # type: Dict[str, Dict[str, str]] | _content_code_data_exts = {} # type: Dict[str, Dict[str, str]] | ||||
_content_code_data_filenames = {} # type: Dict[str, Dict[str, str]] | _content_code_data_filenames = {} # type: Dict[str, Dict[str, str]] | ||||
_content_other_data_exts = {} # type: Dict[str, Dict[str, str]] | _content_other_data_exts = {} # type: Dict[str, Dict[str, str]] | ||||
Show All 12 Lines | def _init_content_tests_data(data_path, data_dict, ext_key): | ||||
""" | """ | ||||
test_contents_dir = os.path.join(os.path.dirname(__file__), data_path).encode( | test_contents_dir = os.path.join(os.path.dirname(__file__), data_path).encode( | ||||
"utf-8" | "utf-8" | ||||
) | ) | ||||
directory = from_disk.Directory.from_disk(path=test_contents_dir) | directory = from_disk.Directory.from_disk(path=test_contents_dir) | ||||
contents = [] | contents = [] | ||||
for name, obj in directory.items(): | for name, obj in directory.items(): | ||||
if isinstance(obj, from_disk.Content): | if obj.object_type in [Content.object_type, DiskBackedContent.object_type]: | ||||
anlambert: I would rather use `Content.object_type` here instead of hard-coding the string value.
Also I… | |||||
Done Inline ActionsIt comes from DiskBackedContent, changed introduced in D3152. ardumont: It comes from `DiskBackedContent`, changed introduced in D3152.
| |||||
Done Inline Actions
I did not grasp what you meant, sorry. ardumont: > I would rather use Content.object_type here instead of hard-coding the string value.
I did… | |||||
Not Done Inline Actionsfrom swh.model.model import Content, DiskBackedContent if obj.object_type in (Content.object_type, DiskBackedContent.object_type): anlambert: ```lang=python
from swh.model.model import Content, DiskBackedContent
if obj.object_type in… | |||||
Done Inline Actionsah ok. Here we go then ;) ardumont: ah ok. Here we go then ;)
| |||||
Not Done Inline ActionsOk, DiskBackedContent is in swh.model.from_disk, that's why I missed it anlambert: Ok, `DiskBackedContent` is in `swh.model.from_disk`, that's why I missed it | |||||
c = obj.to_model().with_data().to_dict() | c = obj.to_model().with_data().to_dict() | ||||
c["status"] = "visible" | c["status"] = "visible" | ||||
sha1 = hash_to_hex(c["sha1"]) | sha1 = hash_to_hex(c["sha1"]) | ||||
if ext_key: | if ext_key: | ||||
key = name.decode("utf-8").split(".")[-1] | key = name.decode("utf-8").split(".")[-1] | ||||
filename = "test." + key | filename = "test." + key | ||||
else: | else: | ||||
filename = name.decode("utf-8").split("/")[-1] | filename = name.decode("utf-8").split("/")[-1] | ||||
▲ Show 20 Lines • Show All 115 Lines • Show Last 20 Lines |
I would rather use Content.object_type here instead of hard-coding the string value.
Also I can not find a model object with the "content_file" type. Where does it come from ?