Commit 398fc3e9 authored by Noé Gaumont's avatar 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
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)
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
if __name__ == '__main__':
from unittest import main
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment