• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rero / sonar / 17425918180

03 Sep 2025 07:11AM UTC coverage: 95.796% (-0.6%) from 96.378%
17425918180

push

github

PascalRepond
translations: extract messages

Co-Authored-by: Pascal Repond <pascal.repond@rero.ch>

7816 of 8159 relevant lines covered (95.8%)

0.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.0
/sonar/modules/documents/serializers/dc.py
1
# Swiss Open Access Repository
2
# Copyright (C) 2022 RERO
3
#
4
# This program is free software: you can redistribute it and/or modify
5
# it under the terms of the GNU Affero General Public License as published by
6
# the Free Software Foundation, version 3 of the License.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU Affero General Public License for more details.
12
#
13
# You should have received a copy of the GNU Affero General Public License
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15

16
"""Dublin Core REST serializer."""
17

18
from invenio_records_rest.serializers.dc import (
1✔
19
    DublinCoreSerializer as BaseDublinCoreSerializer,
20
)
21
from lxml import etree
1✔
22

23
from .oai_dc import SonarDublinCoreXMLSerializer
1✔
24

25

26
class DublinCoreSerializer(BaseDublinCoreSerializer, SonarDublinCoreXMLSerializer):
1✔
27
    """Dublin Core REST serializer."""
28

29
    def serialize_object(self, obj):
1✔
30
        """Serialize a single object according to the response ctx."""
31

32
    def serialize(self, pid, record, links_factory=None):
1✔
33
        """Serialize a single record and persistent identifier.
34

35
        :param pid: Persistent identifier instance.
36
        :param record: Record instance.
37
        :param links_factory: Factory function for record links.
38
        """
39
        root = self.serialize_dict_to_etree(self.transform_record(pid, record, links_factory))
×
40
        return etree.tostring(root, pretty_print=True, encoding="UTF-8")
×
41

42
    def serialize_search(self, pid_fetcher, search_result, links=None, item_links_factory=None):
1✔
43
        """Serialize a search result.
44

45
        :param pid_fetcher: Persistent identifier fetcher.
46
        :param search_result: The search engine result.
47
        :param links: Dictionary of links to add to response.
48
        """
49
        root = etree.Element("collection", total=str(search_result["hits"]["total"]["value"]))
×
50
        for hit in search_result["hits"]["hits"]:
×
51
            child = self.serialize_dict_to_etree(
×
52
                self.transform_search_hit(
53
                    pid_fetcher(hit["_id"], hit["_source"]),
54
                    hit,
55
                    links_factory=item_links_factory,
56
                )
57
            )
58
            root.append(child)
×
59
        return etree.tostring(root, pretty_print=True, encoding="UTF-8")
×
60

61
    def dump(self, obj, context=None):
1✔
62
        """Serialize object with schema.
63

64
        Mandatory to override this method, as invenio-records-rest does not
65
        use the right way to dump objects (compatible with marshmallow 3.9).
66
        """
67
        return self.schema_class(context=context).dump(obj)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc