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

saritasa-nest / django-import-export-extensions / 11511363580

25 Oct 2024 03:30AM UTC coverage: 95.711% (+5.0%) from 90.687%
11511363580

Pull #58

github

web-flow
Merge 77a3934c8 into 6e02e184c
Pull Request #58: Add tests for import admin actions

16 of 16 new or added lines in 3 files covered. (100.0%)

2 existing lines in 2 files now uncovered.

1406 of 1469 relevant lines covered (95.71%)

11.49 hits per line

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

66.67
/import_export_extensions/admin/model_admins/mixins.py
1

2
from django.contrib.contenttypes.models import ContentType
12✔
3
from django.core.handlers.wsgi import WSGIRequest
12✔
4
from django.utils.module_loading import import_string
12✔
5
from django.utils.translation import gettext_lazy as _
12✔
6

7
from ... import models
12✔
8

9

10
class BaseImportExportJobAdminMixin:
12✔
11
    """Mixin provides common methods for ImportJob and ExportJob admins."""
12

13
    def has_add_permission(
12✔
14
        self,
15
        request: WSGIRequest,
16
        *args,
17
        **kwargs,
18
    ) -> bool:
19
        """Import/Export Jobs should not be created using this interface."""
20
        return False
12✔
21

22
    def has_delete_permission(
12✔
23
        self,
24
        request: WSGIRequest,
25
        *args,
26
        **kwargs,
27
    ) -> bool:
28
        """Import/Export Jobs should not be deleted using this interface.
29

30
        Instead, admins must cancel jobs.
31

32
        """
33
        return False
12✔
34

35
    def _model(self, obj: models.ImportJob) -> str:
12✔
36
        """Add `model` field of import/export job."""
37
        try:
12✔
38
            resource_class = import_string(obj.resource_path)
12✔
39
            model = resource_class.Meta.model._meta.verbose_name_plural
12✔
40
        # In case resource has no Meta or model we need to catch AttributeError
41
        except (ImportError, AttributeError):
×
42
            model = _("Unknown")
×
43
        return model
12✔
44

45
    def get_from_content_type(
12✔
46
        self,
47
        obj: models.ImportJob | models.ExportJob,
48
    ) -> ContentType | None:
49
        """Shortcut to get object from content_type."""
50
        content_type = obj.resource_kwargs.get("content_type")
×
51
        obj_id = obj.resource_kwargs.get("object_id")
×
52

53
        if content_type and obj_id:
×
54
            content_type = ContentType.objects.get(id=content_type)
×
55
            return content_type.model_class().objects.filter(id=obj_id).first()
×
56
        return None
×
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