Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cubicweb
cubicweb
Commits
d71e322282ce
Commit
398fc3e9
authored
Mar 30, 2021
by
Noé Gaumont
🐙
Browse files
test: add test for anonymous user creation
This is linked to commit
46f4268461fa
parent
d14437cc4556
Pipeline
#45802
passed with stages
in 34 minutes and 46 seconds
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
cubicweb/pyramid/test/test_core.py
View file @
d71e3222
from
pyramid.config
import
Configurator
from
cubicweb.pyramid.test
import
PyramidCWTest
from
cubicweb.pyramid.core
import
includeme
from
cubicweb.view
import
View
from
cubicweb.web
import
Redirect
from
cubicweb
import
ValidationError
from
cubicweb
import
ValidationError
,
NoResultError
class
Redirector
(
View
):
...
...
@@ -44,6 +47,38 @@ class CoreTest(PyramidCWTest):
self
.
assertEqual
(
res
.
text
,
'OK'
)
self
.
assertEqual
(
res
.
status_int
,
200
)
def
test_register_anonymous_user
(
self
):
new_login
=
'anon2'
# Make sure the user is not defined yet
with
self
.
admin_access
.
cnx
()
as
cnx
:
new_anon
=
cnx
.
find
(
'CWUser'
,
login
=
new_login
)
with
self
.
assertRaises
(
NoResultError
):
cnx
.
find
(
'CWUser'
,
login
=
new_login
).
one
()
settings
=
{
'cubicweb.bwcompat'
:
False
,
'cubicweb.session.secret'
:
'test'
,
}
config
=
Configurator
(
settings
=
settings
)
config
.
registry
[
'cubicweb.repository'
]
=
self
.
repo
config
.
registry
[
'cubicweb.config'
]
=
self
.
config
# Simulates changing anon in the all-in-one by changing the ApptestConfiguration used during
self
.
config
.
anonymous_credential
=
(
new_login
,
'password'
)
# Simulates instance restart (i.e. pyramid.core.include is called)
includeme
(
config
)
with
self
.
admin_access
.
cnx
()
as
cnx
:
# This raises if the user does not exist
new_anon
=
cnx
.
find
(
'CWUser'
,
login
=
new_login
).
one
()
self
.
assertEquals
(
config
.
registry
[
'cubicweb.anonymous_eid'
],
new_anon
.
eid
)
# Erase the user to keep a clean database
new_anon
.
cw_delete
()
cnx
.
commit
()
if
__name__
==
'__main__'
:
from
unittest
import
main
...
...
Write
Preview
Supports
Markdown
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