Skip to content

Commit 1c5ad83

Browse files
authored
Merge pull request #2572 Django 4 upgrade
2 parents dfab6c9 + 7f47f20 commit 1c5ad83

File tree

75 files changed

+2437
-2088
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+2437
-2088
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.3.0
3+
rev: v4.5.0
44
hooks:
55
- id: trailing-whitespace
66
- id: end-of-file-fixer
77
- id: check-yaml
88
- id: check-added-large-files
99
- repo: https://github.com/psf/black
10-
rev: 22.6.0
10+
rev: 24.3.0
1111
hooks:
1212
- id: black

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,4 +422,4 @@ min-public-methods=2
422422

423423
# Exceptions that will emit a warning when being caught. Defaults to
424424
# "Exception"
425-
overgeneral-exceptions=Exception
425+
overgeneral-exceptions=builtins.Exception

docker/onadata-uwsgi/Dockerfile.ubuntu

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ ENV LC_CTYPE en_US.UTF-8
4444
RUN dpkg-reconfigure locales
4545

4646
# Add Deadsnake Repository
47-
RUN add-apt-repository ppa:deadsnakes/ppa -y && apt-get update -q
48-
4947
# Install OnaData Dependencies
50-
RUN apt-get install -y --no-install-recommends \
48+
RUN add-apt-repository 'ppa:deadsnakes/ppa' -y \
49+
&& apt-get update -q \
50+
&& apt-get install -y --no-install-recommends \
5151
libproj-dev \
5252
gdal-bin \
5353
memcached \
@@ -111,5 +111,3 @@ EXPOSE 8000
111111
USER onadata
112112

113113
CMD ["/usr/local/bin/uwsgi", "--ini", "/uwsgi.ini"]
114-
115-

docs/projects.rst

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ You can share a project with a user or multiple users by ``PUT`` a payload with
204204
</pre>
205205

206206
Example 1: Sharing with a specific user
207-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
207+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
208208
::
209209

210210
curl -X PUT -d username=alice -d role=readonly https://api.ona.io/api/v1/projects/1/share
@@ -215,8 +215,8 @@ Response
215215

216216
HTTP 204 NO CONTENT
217217

218-
Example 2: Sharing with mutliple users
219-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
218+
Example 2: Sharing with more than one user
219+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
220220
::
221221

222222
curl -X PUT -d username=alice,jake -d role=readonly https://api.ona.io/api/v1/projects/1/share
@@ -528,14 +528,14 @@ Example
528528
^^^^^^^
529529

530530
::
531-
531+
532532
curl -X GET https://api.ona.io/api/v1/projects/1/invitations
533533

534534
Response
535535
^^^^^^^^
536536

537537
::
538-
538+
539539
[
540540
{
541541
"id": 1,
@@ -571,16 +571,16 @@ Example
571571
^^^^^^^
572572

573573
::
574-
574+
575575
curl -X GET https://api.ona.io/api/v1/projects/1/invitations?status=2
576576

577577
Response
578578
^^^^^^^^
579579

580580
::
581-
581+
582582
[
583-
583+
584584
{
585585
"id": 2,
586586
"email":"[email protected]",
@@ -604,7 +604,7 @@ Example
604604
^^^^^^^
605605

606606
::
607-
607+
608608
curl -X POST -d "[email protected]" -d "role=readonly" https://api.ona.io/api/v1/projects/1/invitations
609609

610610

@@ -629,16 +629,16 @@ Response
629629
^^^^^^^^
630630

631631
::
632-
632+
633633
{
634634
"id": 1,
635635
"email": "[email protected]",
636636
"role": "readonly",
637637
"status": 1,
638638
}
639-
640639

641-
The link embedded in the email will be of the format ``http://{url}``
640+
641+
The link embedded in the email will be of the format ``http://{url}``
642642
where:
643643

644644
- ``url`` - is the URL the recipient will be redirected to on clicking the link. The default is ``{domain}/api/v1/profiles`` where ``domain`` is domain where the API is hosted.
@@ -667,14 +667,14 @@ Example
667667
^^^^^^^
668668

669669
::
670-
670+
671671
curl -X PUT -d "[email protected]" -d "role=editor" -d "invitation_id=1" https://api.ona.io/api/v1/projects/1/invitations/1
672672

673673
Response
674674
^^^^^^^^
675675

676676
::
677-
677+
678678
{
679679
"id": 1,
680680
"email": "[email protected]",
@@ -696,19 +696,19 @@ Example
696696
^^^^^^^
697697

698698
::
699-
699+
700700
curl -X POST -d "invitation_id=6" https://api.ona.io/api/v1/projects/1/resend-invitation
701701

702702

703-
``invitation_id``: The primary key of the ``ProjectInvitation`` to resend.
703+
``invitation_id``: The primary key of the ``ProjectInvitation`` to resend.
704704

705705
- Must be a ``ProjectInvitation`` whose status is **Pending**
706706

707707
Response
708708
^^^^^^^^
709709

710710
::
711-
711+
712712
{
713713
"message": "Success"
714714
}
@@ -727,18 +727,18 @@ Example
727727
^^^^^^^
728728

729729
::
730-
730+
731731
curl -X POST -d "invitation_id=6" https://api.ona.io/api/v1/projects/1/revoke-invitation
732732

733-
``invitation_id``: The primary key of the ``ProjectInvitation`` to resend.
733+
``invitation_id``: The primary key of the ``ProjectInvitation`` to resend.
734734

735735
- Must be a ``ProjectInvitation`` whose status is **Pending**
736736

737737
Response
738738
^^^^^^^^
739739

740740
::
741-
741+
742742
{
743743
"message": "Success"
744744
}
@@ -751,4 +751,4 @@ Since a project invitation is sent to an unregistered user, acceptance of the in
751751
when `creating a new user <https://github.com/onaio/onadata/blob/main/docs/profiles.rst#register-a-new-user>`_.
752752

753753
All pending invitations whose email match the new user's email will be accepted and projects shared with the
754-
user
754+
user

onadata/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77
from __future__ import absolute_import, unicode_literals
88

9-
__version__ = "3.19.0"
9+
__version__ = "4.0.0"
1010

1111

1212
# This will make sure the app is always imported when

onadata/apps/api/tests/management/commands/test_delete_users.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
Test delete user management command.
33
"""
44
import sys
5-
from unittest import mock
6-
from six import StringIO
7-
from django.contrib.auth.models import User
5+
from unittest.mock import patch
6+
7+
from django.contrib.auth import get_user_model
88
from django.core.management import call_command
9-
from onadata.apps.main.tests.test_base import TestBase
9+
10+
from six import StringIO
11+
1012
from onadata.apps.api.management.commands.delete_users import get_user_object_stats
13+
from onadata.apps.main.tests.test_base import TestBase
14+
15+
User = get_user_model()
1116

1217

1318
class DeleteUserTest(TestBase):
@@ -35,7 +40,7 @@ def test_delete_users_with_input(self):
3540
with self.assertRaises(User.DoesNotExist):
3641
User.objects.get(email="[email protected]")
3742

38-
@mock.patch("onadata.apps.api.management.commands.delete_users.input")
43+
@patch("onadata.apps.api.management.commands.delete_users.input")
3944
def test_delete_users_no_input(self, mock_input): # pylint: disable=R0201
4045
"""
4146
Test that when user_input is not provided,

onadata/apps/api/tests/permissions/test_permissions.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Test onadata.apps.api.permissions module.
4+
"""
5+
from unittest.mock import MagicMock, patch
6+
17
from django.contrib.auth.models import User
28
from django.http import Http404
3-
from mock import MagicMock, patch
49

5-
from onadata.apps.api.tests.viewsets.test_abstract_viewset import TestAbstractViewSet
6-
from onadata.apps.logger.models import Instance, XForm
710
from onadata.apps.api.permissions import (
11+
AlternateHasObjectPermissionMixin,
812
IsAuthenticatedSubmission,
913
MetaDataObjectPermissions,
10-
AlternateHasObjectPermissionMixin
1114
)
15+
from onadata.apps.api.tests.viewsets.test_abstract_viewset import TestAbstractViewSet
16+
from onadata.apps.logger.models import Instance, XForm
1217
from onadata.libs.permissions import UserProfile
1318

1419

@@ -25,13 +30,11 @@ def setUp(self):
2530
self.instance.xform = MagicMock(XForm)
2631

2732
def test_delete_instance_metadata_perms(self):
28-
request = MagicMock(user=MagicMock(), method='DELETE')
33+
request = MagicMock(user=MagicMock(), method="DELETE")
2934
obj = MagicMock(content_object=self.instance)
30-
self.assertTrue(
31-
self.permissions.has_object_permission(
32-
request, self.view, obj))
35+
self.assertTrue(self.permissions.has_object_permission(request, self.view, obj))
3336

34-
@patch.object(AlternateHasObjectPermissionMixin, '_has_object_permission')
37+
@patch.object(AlternateHasObjectPermissionMixin, "_has_object_permission")
3538
def test_delete_instance_metadata_without_perms(self, has_perms_mock):
3639
"""
3740
Test that a user cannot delete an instance if they are not allowed
@@ -41,11 +44,11 @@ def test_delete_instance_metadata_without_perms(self, has_perms_mock):
4144
user = User(username="test")
4245
instance = Instance(user=User(username="username"))
4346
instance.xform = XForm()
44-
request = MagicMock(user=user, method='DELETE')
47+
request = MagicMock(user=user, method="DELETE")
4548
obj = MagicMock(content_object=instance)
4649
self.assertFalse(
47-
self.permissions.has_object_permission(
48-
request, self.view, obj))
50+
self.permissions.has_object_permission(request, self.view, obj)
51+
)
4952

5053
def test_is_authenticated_submission_permissions(self):
5154
"""
@@ -56,11 +59,11 @@ def test_is_authenticated_submission_permissions(self):
5659
project = self.xform.project
5760
submission_permission = IsAuthenticatedSubmission()
5861

59-
request = MagicMock(method='GET')
62+
request = MagicMock(method="GET")
6063
view = MagicMock(username=user.username)
6164
self.assertTrue(submission_permission.has_permission(request, self.view))
6265

63-
request = MagicMock(method='POST')
66+
request = MagicMock(method="POST")
6467
view = MagicMock(kwargs={"username": user.username})
6568
self.assertTrue(submission_permission.has_permission(request, view))
6669

0 commit comments

Comments
 (0)