Skip to content

Commit

Permalink
Merge pull request #243 from Volontaria/develop
Browse files Browse the repository at this point in the history
New release
  • Loading branch information
RignonNoel authored Jul 14, 2020
2 parents 145044a + 73f3406 commit d4a2011
Show file tree
Hide file tree
Showing 65 changed files with 649 additions and 114 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: python

dist: xenial
python:
- 3.6

Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# CHANGELOG

## 2.0

We updated our version of `django-cors-headers`, but this change include a breaking change, you need to update
your `CORS_ORIGIN_WHITELIST` according
to [their documentation](https://github.com/ottoyiu/django-cors-headers/blob/master/HISTORY.rst#300-2019-05-10)

10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
- Front-end repository : https://github.com/Volontaria/Website-Volontaria
- Documentation for the project : http://volontaria.readthedocs.io

## Issue manager
## Interested

Issues are handled in a [Redmine instance](https://genielibre.com/projects/volontaria).
Feel free to create an account there to begin contributing!

## Important

API-Volontaria is not yet ready for testing and is still under development! It will not work as expected! If you'd like to join the public beta test group please contact us.
If you'd like to install Volontaria for your organization feel free to contact us to sync your effort with our
development team and get important tips on deployment and configuration.
20 changes: 13 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
Django==2.1.5
django-filter==2.0.0
djangorestframework==3.8.2
Markdown==2.6.11
Django==2.2.14
django-filter==2.2.0
djangorestframework==3.10.3
Markdown==3.2.1
drfdocs==0.0.11
django-cors-headers==2.4.0
django-cors-headers==3.0.2
Faker==0.8.17
factory-boy==2.10.0
django-import-export==1.0.1
django-anymail==4.2
django-import-export==2.0.1
django-anymail==6.1
coreapi==2.3.3
django-orderable==6.0.1
django-ckeditor==5.7.1
django-reversion==3.0.3
xlrd==1.2.0
xlwt==1.3.0
openpyxl==3.0.3
Empty file added source/__init__.py
Empty file.
Empty file.
15 changes: 15 additions & 0 deletions source/apiVolontaria/apiVolontaria/permissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from rest_framework import permissions


class IsAdminOrReadOnly(permissions.BasePermission):
"""
Custom permission to only allow admins to modify objects.
"""

def has_permission(self, request, view):
# Read permissions are allowed to any request,
# so we'll always allow GET, HEAD or OPTIONS requests.
if request.method in permissions.SAFE_METHODS:
return True

return request.user.is_staff
3 changes: 1 addition & 2 deletions source/apiVolontaria/apiVolontaria/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth import authenticate, password_validation

from django.core import exceptions
from volunteer.models import Cell
from .models import ActionToken, Profile

Expand Down Expand Up @@ -230,7 +229,7 @@ class Meta:

class ResetPasswordSerializer(serializers.Serializer):

username = serializers.CharField(required=True)
username_email = serializers.CharField(required=True)


class ChangePasswordSerializer(serializers.Serializer):
Expand Down
7 changes: 6 additions & 1 deletion source/apiVolontaria/apiVolontaria/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@
'apiVolontaria',
'volunteer',
'location',
'pages',
'ckeditor_api',
'import_export',
'anymail'
'anymail',
'orderable',
'ckeditor',
'reversion',
]

MIDDLEWARE = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from rest_framework.test import APITestCase
from django.utils import timezone

from ..models import ActionToken
from ..factories import UserFactory
from apiVolontaria.models import ActionToken
from apiVolontaria.factories import UserFactory


class ActionTokenTests(APITestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from rest_framework.test import APITestCase
from django.core.exceptions import ValidationError

from ..models import Profile
from ..factories import UserFactory
from apiVolontaria.models import Profile
from apiVolontaria.factories import UserFactory


class ProfileTests(APITestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from django.urls import reverse
from django.contrib.auth.models import User

from ..factories import UserFactory
from ..models import ActionToken
from apiVolontaria.factories import UserFactory
from apiVolontaria.models import ActionToken


class ChangePasswordTests(APITestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from django.urls import reverse
from django.test.utils import override_settings

from ..factories import UserFactory
from ..models import ActionToken
from apiVolontaria.factories import UserFactory
from apiVolontaria.models import ActionToken

from django.core import mail
from anymail.exceptions import AnymailCancelSend
Expand All @@ -35,13 +35,49 @@ def setUp(self):
}
}
)

def test_create_new_token(self):
"""
Ensure we can have a new token to change our password
"""
data = {
'username': self.user.username,
'username_email': self.user.username,
}

response = self.client.post(
reverse('reset_password'),
data,
format='json',
)

# Test that one message was sent:
self.assertEqual(len(mail.outbox), 1)

# The token has been created
tokens = ActionToken.objects.filter(
user=self.user,
type='password_change',
)

self.assertEqual(response.content, b'')

self.assertEqual(response.status_code, status.HTTP_201_CREATED)

self.assertTrue(len(tokens) == 1)

@override_settings(
CONSTANT={
"EMAIL_SERVICE": True,
"FRONTEND_INTEGRATION": {
"FORGOT_PASSWORD_URL": "fake_url",
}
}
)
def test_create_new_token_with_email(self):
"""
Ensure we can have a new token to change our password
"""
data = {
'username_email': self.user.email,
}

response = self.client.post(
Expand Down Expand Up @@ -78,7 +114,7 @@ def test_create_new_token_with_call_exception(self):
Ensure we can not have a new token to change our password because exception
"""
data = {
'username': self.user.username,
'username_email': self.user.username,
}

response = self.client.post(
Expand Down Expand Up @@ -112,7 +148,6 @@ def test_create_new_token_with_call_exception(self):
}
}
)

def test_create_new_token_without_username_param(self):
"""
Ensure we can't have a new token to change our password without
Expand All @@ -133,7 +168,7 @@ def test_create_new_token_without_username_param(self):
)

content = {
'username': ['This field is required.']
'username_email': ['This field is required.']
}

self.assertEqual(json.loads(response.content), content)
Expand All @@ -150,14 +185,13 @@ def test_create_new_token_without_username_param(self):
}
}
)

def test_create_new_token_with_an_empty_username_param(self):
"""
Ensure we can't have a new token to change our password without
give our username in param
"""
data = {
'username': '',
'username_email': '',
}

response = self.client.post(
Expand All @@ -173,7 +207,7 @@ def test_create_new_token_with_an_empty_username_param(self):
)

content = {
'username': ["This field may not be blank."],
'username_email': ["This field may not be blank."],
}

self.assertEqual(json.loads(response.content), content)
Expand All @@ -190,14 +224,13 @@ def test_create_new_token_with_an_empty_username_param(self):
}
}
)

def test_create_new_token_with_bad_username(self):
"""
Ensure we can't have a new token to change our password without
a valid username
"""
data = {
'username': 'test',
'username_email': 'test',
}

response = self.client.post(
Expand All @@ -213,7 +246,7 @@ def test_create_new_token_with_bad_username(self):
)

content = {
'username': ["No account with this username."],
'username_email': ["No account with this username or email."],
}
self.assertEqual(json.loads(response.content), content)

Expand All @@ -229,7 +262,6 @@ def test_create_new_token_with_bad_username(self):
}
}
)

def test_create_new_token_when_token_already_exist(self):
"""
Ensure we can have a new token to change our password
Expand All @@ -241,7 +273,7 @@ def test_create_new_token_when_token_already_exist(self):
)

data = {
'username': self.user.username,
'username_email': self.user.username,
}

response = self.client.post(
Expand Down Expand Up @@ -279,7 +311,7 @@ def test_create_new_token_without_email_service(self):
Ensure we can have a new token to change our password
"""
data = {
'username': self.user.username,
'username_email': self.user.username,
}

response = self.client.post(
Expand All @@ -302,6 +334,7 @@ def test_create_new_token_without_email_service(self):
self.assertEqual(response.status_code, status.HTTP_501_NOT_IMPLEMENTED)

self.assertTrue(len(tokens) == 0)

@override_settings(
CONSTANT={
"EMAIL_SERVICE": True,
Expand All @@ -315,7 +348,7 @@ def test_create_new_token_with_failure_email(self):
Ensure we can nt send email after create new token
"""
data = {
'username': self.user.username,
'username_email': self.user.username,
}

@receiver(pre_send, weak=False)
Expand Down
4 changes: 2 additions & 2 deletions source/apiVolontaria/apiVolontaria/tests/tests_view_Users.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from django.test.utils import override_settings
from django.contrib.auth.models import User

from ..models import ActionToken
from apiVolontaria.models import ActionToken
from location.models import Address, StateProvince, Country
from volunteer.models import Cell, Event, Cycle, TaskType, Participation
from ..factories import UserFactory, AdminFactory
from apiVolontaria.factories import UserFactory, AdminFactory
from django.core import mail

from anymail.exceptions import AnymailCancelSend
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from django.urls import reverse
from django.contrib.auth.models import User

from ..factories import UserFactory
from ..models import ActionToken
from apiVolontaria.factories import UserFactory
from apiVolontaria.models import ActionToken


class UsersActivationTests(APITestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

from location.models import Country, StateProvince, Address
from volunteer.models import Cell
from .. import models
from ..factories import UserFactory, AdminFactory
from apiVolontaria import models
from apiVolontaria.factories import UserFactory, AdminFactory


class UsersIdTests(APITestCase):
Expand Down
Loading

0 comments on commit d4a2011

Please sign in to comment.