Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
beat.web
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
54
Issues
54
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
beat
beat.web
Commits
a28a4610
Commit
a28a4610
authored
Sep 24, 2020
by
Flavio TARSETTI
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[beat][web][accounts] remove unused server address prefix
Part of
#558
parent
d417dbe3
Pipeline
#43082
passed with stage
in 15 minutes and 19 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
131 additions
and
117 deletions
+131
-117
beat/web/accounts/tests/test_api.py
beat/web/accounts/tests/test_api.py
+80
-0
beat/web/accounts/tests/test_views.py
beat/web/accounts/tests/test_views.py
+0
-79
beat/web/accounts/views.py
beat/web/accounts/views.py
+0
-9
beat/web/ui/registration/test_views.py
beat/web/ui/registration/test_views.py
+51
-29
No files found.
beat/web/accounts/tests/test_api.py
View file @
a28a4610
...
...
@@ -31,14 +31,20 @@ from datetime import timedelta
import
simplejson
as
json
from
django.conf
import
settings
from
django.contrib.auth.models
import
User
from
django.core
import
mail
from
django.test
import
Client
from
django.test
import
override_settings
from
django.urls
import
reverse
from
rest_framework
import
status
from
rest_framework.test
import
APITestCase
from
...utils.tests.helpers
import
reload_urlconf
from
..models
import
Profile
from
..models
import
SupervisionTrack
from
..models
import
TemporaryUrl
from
..models
import
generate_url_hash
from
.core
import
AccountTestMixin
from
.test_views
import
ViewTestCase
# ----------------------------------------------------------
...
...
@@ -1402,3 +1408,77 @@ class TemporaryUrlTestCase(AccountTestCase):
.
count
()
)
self
.
assertEqual
(
count
,
0
)
# ----------------------------------------------------------
class
EmailSendingTestCase
(
ViewTestCase
,
AccountTestMixin
):
def
run_email_check_yearly_revalidation_possible_rejection
(
self
,
prefix
):
client
=
self
.
yearrevalidationuser
logged_in
=
self
.
client
.
login
(
username
=
"yearrevalidationuser"
,
password
=
"1234"
)
self
.
assertTrue
(
logged_in
)
self
.
assertEqual
(
client
.
username
,
"yearrevalidationuser"
)
revalidation_url
=
reverse
(
"api_accounts:revalidate_account"
)
response
=
self
.
client
.
put
(
revalidation_url
,
format
=
"json"
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_204_NO_CONTENT
)
self
.
client
.
logout
()
reference_url
=
response
.
wsgi_request
.
build_absolute_uri
(
reverse
(
"accounts:temp_url_rejection"
,
kwargs
=
{
"hash_url"
:
generate_url_hash
()},
)
)
self
.
assertEqual
(
len
(
mail
.
outbox
),
1
)
text_lines
=
mail
.
outbox
[
0
].
body
.
split
(
"
\
n
"
)
generated_url
=
text_lines
[
8
]
self
.
assertTrue
(
prefix
in
generated_url
)
self
.
assertEqual
(
generated_url
.
rsplit
(
"/"
,
2
)[
0
],
reference_url
.
rsplit
(
"/"
,
2
)[
0
]
)
client
=
Client
()
response
=
client
.
get
(
generated_url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
len
(
mail
.
outbox
),
2
)
def
test_email_for_yearly_revalidation_possible_rejection
(
self
):
for
prefix
in
[
""
,
"/platform"
]:
with
self
.
subTest
(
url_prefix
=
prefix
):
mail
.
outbox
=
[]
# YearRevalidation user
# Create and assign key
now
=
datetime
.
datetime
.
now
()
expiration_date_delta
=
datetime
.
timedelta
(
days
=
settings
.
ACCOUNT_BLOCKAGE_AFTER_FIRST_REJECTION_DAYS
)
self
.
yearrevalidationuser
.
profile
.
supervision_key
=
(
self
.
yearrevalidationuser
.
profile
.
_generate_current_supervision_key
()
)
supervisiontrack
=
SupervisionTrack
.
objects
.
create
(
supervisee
=
self
.
yearrevalidationuser
,
supervisor
=
self
.
firstsupervisor
,
is_valid
=
True
,
start_date
=
now
,
expiration_date
=
now
+
expiration_date_delta
,
last_validation_date
=
now
,
)
# Assign key to supervision track
supervisiontrack
.
supervision_key
=
(
self
.
yearrevalidationuser
.
profile
.
supervision_key
)
supervisiontrack
.
save
()
self
.
yearrevalidationuser
.
profile
.
supervision
.
add
(
supervisiontrack
)
self
.
yearrevalidationuser
.
profile
.
save
()
self
.
yearrevalidationuser
.
save
()
with
override_settings
(
URL_PREFIX
=
prefix
):
reload_urlconf
()
self
.
run_email_check_yearly_revalidation_possible_rejection
(
prefix
)
beat/web/accounts/tests/test_views.py
View file @
a28a4610
...
...
@@ -30,14 +30,10 @@ from datetime import timedelta
from
django.conf
import
settings
from
django.contrib.auth.models
import
User
from
django.core
import
mail
from
django.test
import
Client
from
django.test
import
TestCase
from
django.test
import
override_settings
from
django.urls
import
reverse
from
rest_framework
import
status
from
...utils.tests.helpers
import
reload_urlconf
from
..models
import
SupervisionTrack
from
..models
import
TemporaryUrl
from
.core
import
AccountTestMixin
...
...
@@ -321,78 +317,3 @@ class TemporaryUrlTestCase(ViewTestCase):
.
count
()
)
self
.
assertEqual
(
count
,
0
)
# ----------------------------------------------------------
class
EmailSendingTestCase
(
ViewTestCase
,
AccountTestMixin
):
def
setUp
(
self
):
super
().
setUp
()
def
run_email_check_yearly_revalidation_possible_rejection
(
self
,
year_revalidation_url
):
client
=
self
.
yearrevalidationuser
logged_in
=
self
.
client
.
login
(
username
=
"yearrevalidationuser"
,
password
=
"1234"
)
self
.
assertTrue
(
logged_in
)
self
.
assertEqual
(
client
.
username
,
"yearrevalidationuser"
)
revalidation_url
=
reverse
(
"api_accounts:revalidate_account"
)
response
=
self
.
client
.
put
(
revalidation_url
,
format
=
"json"
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_204_NO_CONTENT
)
self
.
client
.
logout
()
self
.
assertEqual
(
len
(
mail
.
outbox
),
1
)
text_lines
=
mail
.
outbox
[
0
].
body
.
split
(
"
\
n
"
)
self
.
assertTrue
(
text_lines
[
8
].
startswith
(
year_revalidation_url
.
split
(
"/settings/"
)[
0
]
+
"/rejection/"
)
)
client
=
Client
()
response
=
client
.
get
(
text_lines
[
8
])
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
len
(
mail
.
outbox
),
2
)
def
test_email_for_yearly_revalidation_possible_rejection
(
self
):
for
prefix
in
[
""
,
"/platform"
]:
with
self
.
subTest
(
url_prefix
=
prefix
):
mail
.
outbox
=
[]
# YearRevalidation user
# Create and assign key
now
=
datetime
.
datetime
.
now
()
expiration_date_delta
=
datetime
.
timedelta
(
days
=
settings
.
ACCOUNT_BLOCKAGE_AFTER_FIRST_REJECTION_DAYS
)
self
.
yearrevalidationuser
.
profile
.
supervision_key
=
(
self
.
yearrevalidationuser
.
profile
.
_generate_current_supervision_key
()
)
supervisiontrack
=
SupervisionTrack
.
objects
.
create
(
supervisee
=
self
.
yearrevalidationuser
,
supervisor
=
self
.
firstsupervisor
,
is_valid
=
True
,
start_date
=
now
,
expiration_date
=
now
+
expiration_date_delta
,
last_validation_date
=
now
,
)
# Assign key to supervision track
supervisiontrack
.
supervision_key
=
(
self
.
yearrevalidationuser
.
profile
.
supervision_key
)
supervisiontrack
.
save
()
self
.
yearrevalidationuser
.
profile
.
supervision
.
add
(
supervisiontrack
)
self
.
yearrevalidationuser
.
profile
.
save
()
self
.
yearrevalidationuser
.
save
()
with
override_settings
(
URL_PREFIX
=
prefix
):
reload_urlconf
()
self
.
run_email_check_yearly_revalidation_possible_rejection
(
"http://testserver"
+
prefix
+
"/accounts/settings/"
)
beat/web/accounts/views.py
View file @
a28a4610
...
...
@@ -26,7 +26,6 @@
###############################################################################
import
datetime
from
urllib.parse
import
urlparse
from
django.conf
import
settings
from
django.contrib
import
messages
...
...
@@ -298,13 +297,9 @@ def accept_supervisee(supervisiontrack, supervisee, now):
supervisee
.
is_active
=
True
supervisee
.
save
()
parsed_url
=
urlparse
(
settings
.
URL_PREFIX
)
server_address
=
"%s://%s"
%
(
parsed_url
.
scheme
,
parsed_url
.
hostname
)
context
=
{
"supervisor"
:
supervisiontrack
.
supervisor
,
"supervisee"
:
supervisee
,
"prefix"
:
server_address
,
}
mail
.
send_email
(
...
...
@@ -389,13 +384,9 @@ def load_temporary_url_rejection(request, hash_url):
supervisiontrack
=
temp_url
.
supervision_track
supervisee
=
supervisiontrack
.
supervisee
parsed_url
=
urlparse
(
settings
.
URL_PREFIX
)
server_address
=
"%s://%s"
%
(
parsed_url
.
scheme
,
parsed_url
.
hostname
)
context
=
{
"supervisor"
:
supervisiontrack
.
supervisor
,
"supervisee"
:
supervisee
,
"prefix"
:
server_address
,
}
now
=
datetime
.
datetime
.
now
()
...
...
beat/web/ui/registration/test_views.py
View file @
a28a4610
...
...
@@ -29,6 +29,7 @@ from django.test import Client
from
django.test
import
override_settings
from
django.urls
import
reverse
from
...accounts.models
import
generate_url_hash
from
...accounts.tests.core
import
AccountTestMixin
from
...accounts.tests.test_views
import
ViewTestCase
from
...utils.tests.helpers
import
reload_urlconf
...
...
@@ -37,10 +38,7 @@ from ...utils.tests.helpers import reload_urlconf
class
EmailSendingTestCase
(
ViewTestCase
,
AccountTestMixin
):
def
setUp
(
self
):
super
().
setUp
()
def
run_email_check_signup
(
self
,
reference_url
):
def
run_email_check_signup
(
self
,
prefix
):
client
=
Client
()
response
=
client
.
post
(
reverse
(
"registration"
),
...
...
@@ -56,11 +54,19 @@ class EmailSendingTestCase(ViewTestCase, AccountTestMixin):
),
)
reference_url
=
response
.
wsgi_request
.
build_absolute_uri
(
reverse
(
"registration"
)
)
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertEqual
(
len
(
mail
.
outbox
),
1
)
text_lines
=
mail
.
outbox
[
0
].
body
.
split
(
"
\
n
"
)
self
.
assertTrue
(
text_lines
[
6
].
startswith
(
reference_url
))
generated_url
=
text_lines
[
6
]
self
.
assertTrue
(
prefix
in
generated_url
)
self
.
assertEqual
(
generated_url
.
rsplit
(
"/"
,
3
)[
0
],
reference_url
.
rsplit
(
"/"
,
1
)[
0
]
)
def
test_email_for_signup
(
self
):
for
prefix
in
[
""
,
"/platform"
]:
...
...
@@ -69,11 +75,9 @@ class EmailSendingTestCase(ViewTestCase, AccountTestMixin):
User
.
objects
.
filter
(
username
=
"test"
).
delete
()
with
override_settings
(
URL_PREFIX
=
prefix
):
reload_urlconf
()
self
.
run_email_check_signup
(
"http://testserver"
+
prefix
+
"/signup/"
)
self
.
run_email_check_signup
(
prefix
)
def
run_email_check_activation
(
self
,
signup_url
):
def
run_email_check_activation
(
self
,
prefix
):
client
=
Client
()
response
=
client
.
post
(
reverse
(
"registration"
),
...
...
@@ -90,19 +94,35 @@ class EmailSendingTestCase(ViewTestCase, AccountTestMixin):
)
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertEqual
(
len
(
mail
.
outbox
),
1
)
reference_url
=
response
.
wsgi_request
.
build_absolute_uri
(
reverse
(
"registration"
)
)
self
.
assertEqual
(
len
(
mail
.
outbox
),
1
)
text_lines
=
mail
.
outbox
[
0
].
body
.
split
(
"
\
n
"
)
self
.
assertTrue
(
text_lines
[
6
].
startswith
(
signup_url
))
generated_url
=
text_lines
[
6
]
self
.
assertTrue
(
prefix
in
generated_url
)
self
.
assertEqual
(
generated_url
.
rsplit
(
"/"
,
3
)[
0
],
reference_url
.
rsplit
(
"/"
,
1
)[
0
]
)
response
=
client
.
get
(
text_lines
[
6
]
)
response
=
client
.
get
(
generated_url
)
self
.
assertEqual
(
len
(
mail
.
outbox
),
2
)
text_lines
=
mail
.
outbox
[
1
].
body
.
split
(
"
\
n
"
)
self
.
assertTrue
(
text_lines
[
16
].
startswith
(
signup_url
.
split
(
"/signup/"
)[
0
]
+
"/accounts/validation/"
reference_url
=
response
.
wsgi_request
.
build_absolute_uri
(
reverse
(
"accounts:temp_url_validation"
,
kwargs
=
{
"hash_url"
:
generate_url_hash
()},
)
)
generated_url
=
text_lines
[
16
]
self
.
assertTrue
(
prefix
in
generated_url
)
self
.
assertEqual
(
generated_url
.
rsplit
(
"/"
,
2
)[
0
],
reference_url
.
rsplit
(
"/"
,
2
)[
0
]
)
def
test_email_for_activation
(
self
):
for
prefix
in
[
""
,
"/platform"
]:
...
...
@@ -111,11 +131,9 @@ class EmailSendingTestCase(ViewTestCase, AccountTestMixin):
User
.
objects
.
filter
(
username
=
"test"
).
delete
()
with
override_settings
(
URL_PREFIX
=
prefix
):
reload_urlconf
()
self
.
run_email_check_activation
(
"http://testserver"
+
prefix
+
"/signup/"
)
self
.
run_email_check_activation
(
prefix
)
def
run_email_check_reactivation
(
self
,
unblock_url
):
def
run_email_check_reactivation
(
self
,
prefix
):
client
=
Client
()
response
=
client
.
post
(
reverse
(
"blocked_user_reactivation"
),
...
...
@@ -125,20 +143,26 @@ class EmailSendingTestCase(ViewTestCase, AccountTestMixin):
)
self
.
assertEqual
(
response
.
status_code
,
200
)
reference_url
=
response
.
wsgi_request
.
build_absolute_uri
(
reverse
(
"accounts:temp_url_validation"
,
kwargs
=
{
"hash_url"
:
generate_url_hash
()},
)
)
self
.
assertEqual
(
len
(
mail
.
outbox
),
2
)
text_lines
=
mail
.
outbox
[
0
].
body
.
split
(
"
\
n
"
)
self
.
assertTrue
(
text_lines
[
16
].
startswith
(
unblock_url
.
split
(
"/blocked_user_reactivation/"
)[
0
]
+
"/accounts/validation/"
)
generated_url
=
text_lines
[
16
]
self
.
assertTrue
(
prefix
in
generated_url
)
self
.
assertEqual
(
generated_url
.
rsplit
(
"/"
,
2
)[
0
],
reference_url
.
rsplit
(
"/"
,
2
)[
0
]
)
response
=
client
.
get
(
text_lines
[
16
]
)
response
=
client
.
get
(
generated_url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
len
(
mail
.
outbox
),
3
)
text_lines
=
mail
.
outbox
[
2
].
body
.
split
(
"
\
n
"
)
def
test_email_for_reactivation
(
self
):
for
prefix
in
[
""
,
"/platform"
]:
...
...
@@ -153,6 +177,4 @@ class EmailSendingTestCase(ViewTestCase, AccountTestMixin):
with
override_settings
(
URL_PREFIX
=
prefix
):
reload_urlconf
()
self
.
run_email_check_reactivation
(
"http://testserver"
+
prefix
+
"/blocked_user_reactivation/"
)
self
.
run_email_check_reactivation
(
prefix
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment