-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'bs/fixed_issue_3975_' of github.com:openvinotoolkit/cva…
…t into bs/fixed_issue_3975_
- Loading branch information
Showing
4 changed files
with
79 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Copyright (C) 2021 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
from django.urls import reverse | ||
from rest_framework import status | ||
from rest_framework.test import APITestCase | ||
from rest_framework.authtoken.models import Token | ||
from django.test import override_settings | ||
from cvat.apps.iam.urls import urlpatterns as iam_url_patterns | ||
from django.urls import path, re_path | ||
from allauth.account.views import ConfirmEmailView, EmailVerificationSentView | ||
|
||
|
||
urlpatterns = iam_url_patterns + [ | ||
re_path(r'^account-confirm-email/(?P<key>[-:\w]+)/$', ConfirmEmailView.as_view(), | ||
name='account_confirm_email'), | ||
path('register/account-email-verification-sent', EmailVerificationSentView.as_view(), | ||
name='account_email_verification_sent'), | ||
] | ||
|
||
|
||
class UserRegisterAPITestCase(APITestCase): | ||
|
||
user_data = {'first_name': 'test_first', 'last_name': 'test_last', 'username': 'test_username', | ||
'email': 'test_email@test.com', 'password1': '$Test357Test%', 'password2': '$Test357Test%', | ||
'confirmations': []} | ||
|
||
def _run_api_v1_user_register(self, data): | ||
url = reverse('rest_register') | ||
response = self.client.post(url, data, format='json') | ||
return response | ||
|
||
def _check_response(self, response, data): | ||
self.assertEqual(response.status_code, status.HTTP_201_CREATED) | ||
self.assertEqual(response.data, data) | ||
|
||
@override_settings(ACCOUNT_EMAIL_VERIFICATION='none') | ||
def test_api_v1_user_register_with_email_verification_none(self): | ||
""" | ||
Ensure we can register a user and get auth token key when email verification is none | ||
""" | ||
response = self._run_api_v1_user_register(self.user_data) | ||
user_token = Token.objects.get(user__username=response.data['username']) | ||
self._check_response(response, {'first_name': 'test_first', 'last_name': 'test_last', | ||
'username': 'test_username', 'email': 'test_email@test.com', | ||
'email_verification_required': False, 'key': user_token.key}) | ||
|
||
# Since URLConf is executed before running the tests, so we have to manually configure the url patterns for | ||
# the tests and pass it using ROOT_URLCONF in the override settings decorator | ||
|
||
@override_settings(ACCOUNT_EMAIL_VERIFICATION='optional', ROOT_URLCONF=__name__) | ||
def test_api_v1_user_register_with_email_verification_optional(self): | ||
""" | ||
Ensure we can register a user and get auth token key when email verification is optional | ||
""" | ||
response = self._run_api_v1_user_register(self.user_data) | ||
user_token = Token.objects.get(user__username=response.data['username']) | ||
self._check_response(response, {'first_name': 'test_first', 'last_name': 'test_last', | ||
'username': 'test_username', 'email': 'test_email@test.com', | ||
'email_verification_required': False, 'key': user_token.key}) | ||
|
||
@override_settings(ACCOUNT_EMAIL_REQUIRED=True, ACCOUNT_EMAIL_VERIFICATION='mandatory', | ||
EMAIL_BACKEND='django.core.mail.backends.console.EmailBackend', ROOT_URLCONF=__name__) | ||
def test_register_account_with_email_verification_mandatory(self): | ||
""" | ||
Ensure we can register a user and it does not return auth token key when email verification is mandatory | ||
""" | ||
response = self._run_api_v1_user_register(self.user_data) | ||
self._check_response(response, {'first_name': 'test_first', 'last_name': 'test_last', | ||
'username': 'test_username', 'email': 'test_email@test.com', | ||
'email_verification_required': True, 'key': None}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters