Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v1.2.0 #76

Merged
merged 1 commit into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions seven23/api/users/tests_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""
Tests Account API
"""
import datetime
from django.test import TransactionTestCase
# Default user model may get swapped out of the system and hence.
from django.contrib.auth.models import User

from rest_framework.test import APIClient

from rest_framework import status

from seven23.models.accounts.models import Account, AccountGuests
from seven23.models.categories.models import Category
from seven23.models.transactions.models import DebitsCredits
from seven23.models.currency.models import Currency


class ApiUsersTest(TransactionTestCase):
""" Account retrieve """

def setUp(self):
self.client = APIClient()

def test_registration_new_user(self):
"""
Create a user using rest-auth and get auth key in response.
"""
response = self.client.post('/api/v1/rest-auth/registration/', {
'username': 'test',
'password1': 'testtest',
'password2': 'testtest',
'email': 'test@sebastienbarbier.com',
'origin': 'https://next.seven23.io',
}, format='json')
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
data = response.json()
# Test if response data key is define, a string, and not empty or blank
self.assertTrue('key' in data)

# Verify user serializer is returning profile user
response = self.client.get('/api/v1/rest-auth/user/', HTTP_AUTHORIZATION='Token ' + data['key'])
self.assertEqual(response.status_code, status.HTTP_200_OK)
data = response.json()
# Test if response data key is define, a string, and not empty or blank
self.assertTrue('username' in data)
self.assertEqual(data['username'], 'test')
self.assertTrue('profile' in data)
self.assertTrue('avatar' in data['profile'])
self.assertTrue('social_networks' in data['profile'])
1 change: 1 addition & 0 deletions seven23/api/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def delete_user(request):
"""
Permanently delete a user
"""
# Confirm provided password to be valid to trigger the deletion.
if authenticate(username=request.user.username, password=request.data['password']):
request.user.delete()
return HttpResponse(status=200)
Expand Down
4 changes: 2 additions & 2 deletions seven23/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
os.path.join(BASE_DIR, 'seven23/static'),
)


LOGIN_URL = '/'

# Database confugration using environment variable DATABASES_URL
Expand Down Expand Up @@ -196,7 +195,8 @@
'DEFAULT_FILTER_BACKENDS': ('django_filters.rest_framework.DjangoFilterBackend',),
}

REST_AUTH_SERIALIZERS = {
REST_AUTH = {
'SESSION_LOGIN': False,
'USER_DETAILS_SERIALIZER': 'seven23.models.rest_auth.serializers.UserSerializer',
'PASSWORD_RESET_SERIALIZER': 'seven23.models.rest_auth.serializers.PasswordResetSerializer',
}
Expand Down