Skip to content

Commit

Permalink
Merge pull request #2572 Django 4 upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
ukanga committed Apr 8, 2024
2 parents dfab6c9 + 7f47f20 commit 1c5ad83
Show file tree
Hide file tree
Showing 75 changed files with 2,437 additions and 2,088 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: 22.6.0
rev: 24.3.0
hooks:
- id: black
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -422,4 +422,4 @@ min-public-methods=2

# Exceptions that will emit a warning when being caught. Defaults to
# "Exception"
overgeneral-exceptions=Exception
overgeneral-exceptions=builtins.Exception
8 changes: 3 additions & 5 deletions docker/onadata-uwsgi/Dockerfile.ubuntu
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ ENV LC_CTYPE en_US.UTF-8
RUN dpkg-reconfigure locales

# Add Deadsnake Repository
RUN add-apt-repository ppa:deadsnakes/ppa -y && apt-get update -q

# Install OnaData Dependencies
RUN apt-get install -y --no-install-recommends \
RUN add-apt-repository 'ppa:deadsnakes/ppa' -y \
&& apt-get update -q \
&& apt-get install -y --no-install-recommends \
libproj-dev \
gdal-bin \
memcached \
Expand Down Expand Up @@ -111,5 +111,3 @@ EXPOSE 8000
USER onadata

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


42 changes: 21 additions & 21 deletions docs/projects.rst
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ You can share a project with a user or multiple users by ``PUT`` a payload with
</pre>

Example 1: Sharing with a specific user
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
::

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

HTTP 204 NO CONTENT

Example 2: Sharing with mutliple users
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Example 2: Sharing with more than one user
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
::

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

::

curl -X GET https://api.ona.io/api/v1/projects/1/invitations

Response
^^^^^^^^

::

[
{
"id": 1,
Expand Down Expand Up @@ -571,16 +571,16 @@ Example
^^^^^^^

::

curl -X GET https://api.ona.io/api/v1/projects/1/invitations?status=2

Response
^^^^^^^^

::

[

{
"id": 2,
"email":"[email protected]",
Expand All @@ -604,7 +604,7 @@ Example
^^^^^^^

::

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


Expand All @@ -629,16 +629,16 @@ Response
^^^^^^^^

::

{
"id": 1,
"email": "[email protected]",
"role": "readonly",
"status": 1,
}

The link embedded in the email will be of the format ``http://{url}``

The link embedded in the email will be of the format ``http://{url}``
where:

- ``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.
Expand Down Expand Up @@ -667,14 +667,14 @@ Example
^^^^^^^

::

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

Response
^^^^^^^^

::

{
"id": 1,
"email": "[email protected]",
Expand All @@ -696,19 +696,19 @@ Example
^^^^^^^

::

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


``invitation_id``: The primary key of the ``ProjectInvitation`` to resend.
``invitation_id``: The primary key of the ``ProjectInvitation`` to resend.

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

Response
^^^^^^^^

::

{
"message": "Success"
}
Expand All @@ -727,18 +727,18 @@ Example
^^^^^^^

::

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

``invitation_id``: The primary key of the ``ProjectInvitation`` to resend.
``invitation_id``: The primary key of the ``ProjectInvitation`` to resend.

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

Response
^^^^^^^^

::

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

All pending invitations whose email match the new user's email will be accepted and projects shared with the
user
user
2 changes: 1 addition & 1 deletion onadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""
from __future__ import absolute_import, unicode_literals

__version__ = "3.19.0"
__version__ = "4.0.0"


# This will make sure the app is always imported when
Expand Down
15 changes: 10 additions & 5 deletions onadata/apps/api/tests/management/commands/test_delete_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
Test delete user management command.
"""
import sys
from unittest import mock
from six import StringIO
from django.contrib.auth.models import User
from unittest.mock import patch

from django.contrib.auth import get_user_model
from django.core.management import call_command
from onadata.apps.main.tests.test_base import TestBase

from six import StringIO

from onadata.apps.api.management.commands.delete_users import get_user_object_stats
from onadata.apps.main.tests.test_base import TestBase

User = get_user_model()


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

@mock.patch("onadata.apps.api.management.commands.delete_users.input")
@patch("onadata.apps.api.management.commands.delete_users.input")
def test_delete_users_no_input(self, mock_input): # pylint: disable=R0201
"""
Test that when user_input is not provided,
Expand Down
31 changes: 17 additions & 14 deletions onadata/apps/api/tests/permissions/test_permissions.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# -*- coding: utf-8 -*-
"""
Test onadata.apps.api.permissions module.
"""
from unittest.mock import MagicMock, patch

from django.contrib.auth.models import User
from django.http import Http404
from mock import MagicMock, patch

from onadata.apps.api.tests.viewsets.test_abstract_viewset import TestAbstractViewSet
from onadata.apps.logger.models import Instance, XForm
from onadata.apps.api.permissions import (
AlternateHasObjectPermissionMixin,
IsAuthenticatedSubmission,
MetaDataObjectPermissions,
AlternateHasObjectPermissionMixin
)
from onadata.apps.api.tests.viewsets.test_abstract_viewset import TestAbstractViewSet
from onadata.apps.logger.models import Instance, XForm
from onadata.libs.permissions import UserProfile


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

def test_delete_instance_metadata_perms(self):
request = MagicMock(user=MagicMock(), method='DELETE')
request = MagicMock(user=MagicMock(), method="DELETE")
obj = MagicMock(content_object=self.instance)
self.assertTrue(
self.permissions.has_object_permission(
request, self.view, obj))
self.assertTrue(self.permissions.has_object_permission(request, self.view, obj))

@patch.object(AlternateHasObjectPermissionMixin, '_has_object_permission')
@patch.object(AlternateHasObjectPermissionMixin, "_has_object_permission")
def test_delete_instance_metadata_without_perms(self, has_perms_mock):
"""
Test that a user cannot delete an instance if they are not allowed
Expand All @@ -41,11 +44,11 @@ def test_delete_instance_metadata_without_perms(self, has_perms_mock):
user = User(username="test")
instance = Instance(user=User(username="username"))
instance.xform = XForm()
request = MagicMock(user=user, method='DELETE')
request = MagicMock(user=user, method="DELETE")
obj = MagicMock(content_object=instance)
self.assertFalse(
self.permissions.has_object_permission(
request, self.view, obj))
self.permissions.has_object_permission(request, self.view, obj)
)

def test_is_authenticated_submission_permissions(self):
"""
Expand All @@ -56,11 +59,11 @@ def test_is_authenticated_submission_permissions(self):
project = self.xform.project
submission_permission = IsAuthenticatedSubmission()

request = MagicMock(method='GET')
request = MagicMock(method="GET")
view = MagicMock(username=user.username)
self.assertTrue(submission_permission.has_permission(request, self.view))

request = MagicMock(method='POST')
request = MagicMock(method="POST")
view = MagicMock(kwargs={"username": user.username})
self.assertTrue(submission_permission.has_permission(request, view))

Expand Down
Loading

0 comments on commit 1c5ad83

Please sign in to comment.