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

rdmorganiser / rdmo / 19672034171

25 Nov 2025 01:58PM UTC coverage: 94.784% (-0.01%) from 94.796%
19672034171

Pull #1427

github

web-flow
Merge 499177e07 into 79917de8d
Pull Request #1427: RDMO 2.4.0 🎆

2109 of 2214 branches covered (95.26%)

22533 of 23773 relevant lines covered (94.78%)

3.79 hits per line

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

84.09
rdmo/core/tests/utils.py
1
import hashlib
4✔
2

3
from django.db.models import Model
4✔
4

5
from rdmo.core.tests.constants import multisite_status_map, status_map_object_permissions
4✔
6

7

8
def get_obj_perms_status_code(instance, username, method, editors=None):
4✔
9
    ''' looks for the object permissions of the instance and returns the status code '''
10

11
    if (isinstance(instance, Model) or hasattr(instance, 'editors')) and hasattr(instance, 'uri'):
4✔
12
        instance_uri = instance.uri
4✔
13
        instance_editors = instance.editors.values_list('domain', flat=True)
4✔
14
    elif isinstance(instance, str):
4✔
15
        instance_uri = instance
4✔
16
        instance_editors = []
4✔
17
    else:
18
        raise TypeError(f'instance {instance} should be a str or a Model (and have an uri)')
×
19

20
    if editors is not None and method == 'delete':
4✔
21
        # override in case of deleted instance
22
        instance_editors = editors
4✔
23

24
    if 'foo-' in instance_uri:
4✔
25
        instance_obj_perms_key = 'foo-element'
4✔
26
        assert_editors = ['foo.com']
4✔
27
    elif 'bar-' in instance_uri:
4✔
28
        instance_obj_perms_key = 'bar-element'
4✔
29
        assert_editors = ['bar.com']
4✔
30
    elif 'example-' in instance_uri:
4✔
31
        instance_obj_perms_key = 'example-element'
×
32
        assert_editors = ['example.com']
×
33
    else:
34
        if instance_editors:
4✔
35
            raise ValueError(f"uri {instance_uri} should contain the domain for {instance_editors}")
×
36
        instance_obj_perms_key = 'all-element'
4✔
37
        assert_editors = ['foo.com', 'bar.com', 'example.com']
4✔
38

39
    if not instance_editors and instance_obj_perms_key != 'all-element':
4✔
40
        if 'import' in method:  # override for import when only uri is passed
4✔
41
            instance_editors = assert_editors
4✔
42
        else:
43
            raise ValueError(f"instance_editors should be specified on {instance_uri}")
×
44
    elif instance_editors:
4✔
45
        assert all(
4✔
46
            i in instance_editors for i in assert_editors
47
        ), f"{assert_editors} should be specified on {instance_uri}"
48

49

50
    if not instance_editors:
4✔
51
        return multisite_status_map[method][username]
4✔
52

53
    try:
4✔
54
        method_instance_obj_perms_map = status_map_object_permissions[method][instance_obj_perms_key]
4✔
55
    except KeyError as e:
×
56
        raise KeyError(
×
57
            f'instance (uri={instance_uri}, editors={instance_editors}) for {method} ({instance_obj_perms_key})'
58
            f' should be defined in status_map_object_permissions'
59
        ) from e
60
    try:
4✔
61
        return method_instance_obj_perms_map[username]
4✔
62
    except KeyError:
4✔
63
        # not all users are defined in the method_instance_perms_map
64
        return multisite_status_map[method][username]
4✔
65

66

67
def compute_checksum(string):
4✔
68
    return hashlib.sha1(string).hexdigest()
4✔
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

© 2026 Coveralls, Inc