Skip to content

Commit

Permalink
Make pass test_login_bare() and little other improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
BuhtigithuB committed Oct 5, 2016
1 parent 1877f49 commit 77c0384
Showing 1 changed file with 62 additions and 25 deletions.
87 changes: 62 additions & 25 deletions gluon/tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,28 +525,47 @@ def setUp(self):
self.auth.define_tables(username=True, signature=False)
self.db.define_table('t0', Field('tt'), self.auth.signature)
self.auth.enable_record_versioning(self.db)
self.auth.settings.registration_requires_verification = False
self.auth.settings.registration_requires_approval = False
# Create a user
self.auth.get_or_create_user(dict(first_name='Bart',
last_name='Simpson',
username='bart',
email='[email protected]',
password='bart_password',
registration_key='bart',
registration_id=''
),
login=False)
self.db.commit()
self.assertFalse(self.auth.is_logged_in())
# self.auth.settings.registration_requires_verification = False
# self.auth.settings.registration_requires_approval = False
# Note: get_or_create_user() doesn't seems to create user properly it better to use register_bare() and
# prevent login_bare() test from succeed. db insert the user manually not properly work either.
# Not working
# self.auth.get_or_create_user(dict(first_name='Bart',
# last_name='Simpson',
# username='bart',
# email='[email protected]',
# password='bart_password',
# # registration_key=None,
# #registration_id='[email protected]'
# ),
# login=False)
# Not working
# self.db.auth_user.insert(first_name='Bart',
# last_name='Simpson',
# username='bart',
# email='[email protected]',
# password='bart_password')
# self.db.commit()
self.auth.register_bare(first_name='Bart',
last_name='Simpson',
username='bart',
email='[email protected]',
password='bart_password')

def test_assert_setup(self):
self.assertEqual(self.db(self.db.auth_user.username == 'bart').select().first()['username'], 'bart')
self.assertTrue('auth_user' in self.db)
self.assertTrue('auth_group' in self.db)
self.assertTrue('auth_membership' in self.db)
self.assertTrue('auth_permission' in self.db)
self.assertTrue('auth_event' in self.db)
bart_record = self.db(self.db.auth_user.username == 'bart').select().first()
self.assertEqual(bart_record['username'], 'bart')
self.assertEqual(bart_record['registration_key'], '')
bart_id = self.db(self.db.auth_user.username == 'bart').select().first().id
bart_group_id = self.db(self.db.auth_group.role == 'user_{0}'.format(bart_id)).select().first().id
self.assertTrue(self.db((self.db.auth_membership.group_id == bart_group_id) &
(self.db.auth_membership.user_id == bart_id)).select().first())

# Just calling many form functions
def test_basic_blank_forms(self):
Expand Down Expand Up @@ -652,16 +671,31 @@ def test_get_or_create_user(self):
# TODO: def test_login_user(self):
# TODO: def test__get_login_settings(self):

# login_bare() seems broken see my post on web2py-developpers
# commented for now
# def test_login_bare(self):
# # The following test case should succeed but failed as I never received the user record but False
# self.auth.login_bare(username='bart', password='bart_password')
# self.assertTrue(self.auth.is_logged_in())
# # Failing login because bad_password
# self.assertEqual(self.auth.login_bare(username='bart', password='wrong_password'), False)
# self.auth.logout_bare()
# self.db.auth_user.truncate()
def test_login_bare(self):
self.auth.login_bare(username='bart', password='bart_password')
self.assertTrue(self.auth.is_logged_in())
self.auth.logout_bare()
# Failing login because wrong_password
self.assertFalse(self.auth.login_bare(username='bart', password='wrong_password'))
# NOTE : The following failed for some reason, but I can't find out why
# self.auth = Auth(self.db)
# self.auth.define_tables(username=False, signature=False)
# self.auth.settings.registration_requires_verification = False
# self.auth.settings.registration_requires_approval = False
# self.auth.register_bare(first_name='Omer',
# last_name='Simpson',
# # no username field passed, failed with :
# # ValueError('register_bare: userfield not provided or invalid')
# # Or
# # username='omer',
# # Or
# # username='[email protected]',
# # In either previous cases, it failed with :
# # self.assertTrue(self.auth.is_logged_in()) AssertionError: False is not true
# email='[email protected]',
# password='omer_password')
# self.auth.login_bare(username='[email protected]', password='omer_password')
# self.assertTrue(self.auth.is_logged_in())

def test_register_bare(self):
# corner case empty register call register_bare without args
Expand Down Expand Up @@ -817,7 +851,10 @@ def test_allows_jwt(self):
self.myassertRaisesRegex(HTTP, "400*", self.auth.allows_jwt)

# TODO: def test_requires(self):
# TODO: def test_requires_login(self):

# def test_login(self):
# Basic testing above in "test_basic_blank_forms()" could be refined here

# TODO: def test_requires_login_or_token(self):
# TODO: def test_requires_membership(self):
# TODO: def test_requires_permission(self):
Expand Down

0 comments on commit 77c0384

Please sign in to comment.