Exemplo n.º 1
0
	def test_user_can_change_email(self):
		"""Test user can change their email"""
		self.orm = ORM(self.file_input)
		new_email = '*****@*****.**'
		update_user = ['joegotflow83', 'admin', 'joseph moran', '*****@*****.**']
		self.assertEquals(self.orm.change_email('joegotflow83',
												new_email), update_user)
Exemplo n.º 2
0
	def test_user_can_change_current_password(self):
		"""Test that a user can change their password"""
		self.orm = ORM(self.file_input)
		new_password = '******'
		update_user = ['joegotflow83', 'newadmin', 'joseph moran', '*****@*****.**']
		self.assertEquals(self.orm.change_password('joegotflow83', 
												new_password), update_user)
Exemplo n.º 3
0
	def test_user_can_create_new_user(self):
		"""Test a user can create a new user and save it to the db"""
		self.orm = ORM(self.file_input)
		username = '******'
		password = '******'
		full_name = 'guiseppe moran'
		email = '*****@*****.**'
		new_user = ['joe', 'python', 'guiseppe moran', '*****@*****.**']
		self.assertEquals(self.orm.add_user(username, password, full_name, email),
			 new_user)
Exemplo n.º 4
0
	def test_if_username_already_exists_throw_an_error(self):
		"""Test if a user creates a new username and it already exists
		have them create new username"""
		self.orm = ORM(self.file_input)
		username = '******'
		password = '******'
		full_name = 'joseph moran'
		email = '*****@*****.**'
		self.assertIn(self.orm.add_user(username, password, full_name, email), 
					'That username already exists! Use a different username')
Exemplo n.º 5
0
	def test_db_does_not_pull_user_if_username_not_in_db_for_pull_func(self):
		"""Test that if no username is in the db return False"""
		self.orm = ORM(self.file_input)
		self.assertFalse(self.orm.pull_user_info('mike'))
Exemplo n.º 6
0
	def test_db_can_pull_all_of_users_info_when_logged_in(self):
		"""Test that the users info is pulled once "logged in" """
		self.orm = ORM(self.file_input)
		self.assertEquals(self.orm.pull_user_info('joegotflow83'), 
			['joegotflow83', 'admin', 'joseph moran', '*****@*****.**'])
Exemplo n.º 7
0
	def test_error_occurs_if_invalid_credentials(self):
		"""Test that an exception is thrown if the credentials are invalid"""
		self.orm = ORM(self.file_input)
		self.assertIn(self.orm.check_credentials('username', 'password'), 'Invalid Credentials')
Exemplo n.º 8
0
class ViewsTest(unittest.TestCase):


	def setUp(self):
		"""Set up testing env"""
		self.file_input = [['joegotflow83', 'admin', 'joseph moran', '*****@*****.**'],
			['yoshi', 'dinosaur', 'yoshi the dinosaur', '*****@*****.**']]
		self.orm = ORM(file_contents=self.file_input)

	def tearDown(self):
		"""Tear down the testing env"""
		self.file_input = None
		self.orm = None

	def test_db_file_is_formatted_correctly(self):
		"""Test that the db file is correctly formatted for searching"""
		sample_data = ['joegotflow83,admin,joseph moran,[email protected]',
			'yoshi,dinosaur,yoshi the dinosaur,[email protected]']
		self.assertEquals(ORM.clean_file(self, sample_data), self.file_input)

	def test_db_can_find_username(self):
		"""Test that the db can find a username based on an input"""
		self.orm = ORM(self.file_input)
		self.assertTrue(self.orm.get_username('joegotflow83') == True)

	def test_db_returns_false_if_no_username_in_db(self):
		"""Test that the db returns False if no username in db"""
		self.orm = ORM(self.file_input)
		self.assertTrue(self.orm.get_username('myusername') == False)

	def test_db_can_find_password(self):
		"""Test that the db can find a password based on an input"""
		self.orm = ORM(self.file_input)
		self.assertTrue(self.orm.get_password('admin') == True)

	def test_db_returns_false_if_no_password_in_db(self):
		"""Test that the db returns False if no password in db"""
		self.orm = ORM(self.file_input)
		self.assertFalse(self.orm.get_password('badpassword'))

	def test_user_can_log_on(self):
		"""Test that when a user provides the correct credentials return True"""
		self.orm = ORM(self.file_input)
		self.assertTrue(self.orm.check_credentials('joegotflow83', 'admin'))

	def test_error_occurs_if_invalid_credentials(self):
		"""Test that an exception is thrown if the credentials are invalid"""
		self.orm = ORM(self.file_input)
		self.assertIn(self.orm.check_credentials('username', 'password'), 'Invalid Credentials')

	def test_db_can_pull_all_of_users_info_when_logged_in(self):
		"""Test that the users info is pulled once "logged in" """
		self.orm = ORM(self.file_input)
		self.assertEquals(self.orm.pull_user_info('joegotflow83'), 
			['joegotflow83', 'admin', 'joseph moran', '*****@*****.**'])

	def test_db_does_not_pull_user_if_username_not_in_db_for_pull_func(self):
		"""Test that if no username is in the db return False"""
		self.orm = ORM(self.file_input)
		self.assertFalse(self.orm.pull_user_info('mike'))

	def test_user_info_gets_deleted(self):
		"""Test that the user info gets deleted"""
		self.orm = ORM(self.file_input)
		self.assertEquals(self.orm.delete_user_info('joegotflow83'), True)

	def test_user_gets_welcome_message_when_logged_on(self):
		"""Test that a welcome message is displayed when the user is "logged in" """
		self.orm = ORM(self.file_input)
		username = self.file_input[0][0]
		self.assertIn(self.orm.welcome('joegotflow83'), 'Welcome back {}!'.format(username))

	def test_user_can_pick_an_action(self):
		"""Test a user can perform an action when "logged in" """
		self.orm = ORM(self.file_input)
		self.assertEquals(self.orm.actions(4), 4)

	def test_user_can_create_new_user(self):
		"""Test a user can create a new user and save it to the db"""
		self.orm = ORM(self.file_input)
		username = '******'
		password = '******'
		full_name = 'guiseppe moran'
		email = '*****@*****.**'
		new_user = ['joe', 'python', 'guiseppe moran', '*****@*****.**']
		self.assertEquals(self.orm.add_user(username, password, full_name, email),
			 new_user)

	def test_if_username_already_exists_throw_an_error(self):
		"""Test if a user creates a new username and it already exists
		have them create new username"""
		self.orm = ORM(self.file_input)
		username = '******'
		password = '******'
		full_name = 'joseph moran'
		email = '*****@*****.**'
		self.assertIn(self.orm.add_user(username, password, full_name, email), 
					'That username already exists! Use a different username')

	def test_user_can_change_current_password(self):
		"""Test that a user can change their password"""
		self.orm = ORM(self.file_input)
		new_password = '******'
		update_user = ['joegotflow83', 'newadmin', 'joseph moran', '*****@*****.**']
		self.assertEquals(self.orm.change_password('joegotflow83', 
												new_password), update_user)

	def test_user_can_change_email(self):
		"""Test user can change their email"""
		self.orm = ORM(self.file_input)
		new_email = '*****@*****.**'
		update_user = ['joegotflow83', 'admin', 'joseph moran', '*****@*****.**']
		self.assertEquals(self.orm.change_email('joegotflow83',
												new_email), update_user)

	def test_user_can_logout(self):
		"""Test user can logout"""
		self.orm = ORM(self.file_input)
		self.assertEquals(self.orm.logout('joegotflow83', 'admin'), 
										(False, None, None))
Exemplo n.º 9
0
def get_db(type_, path):
    orm = ORM()
    return orm.get_orm(type_, path)
Exemplo n.º 10
0
	def test_user_can_pick_an_action(self):
		"""Test a user can perform an action when "logged in" """
		self.orm = ORM(self.file_input)
		self.assertEquals(self.orm.actions(4), 4)
Exemplo n.º 11
0
	def test_db_returns_false_if_no_username_in_db(self):
		"""Test that the db returns False if no username in db"""
		self.orm = ORM(self.file_input)
		self.assertTrue(self.orm.get_username('myusername') == False)
Exemplo n.º 12
0
	def test_db_can_find_username(self):
		"""Test that the db can find a username based on an input"""
		self.orm = ORM(self.file_input)
		self.assertTrue(self.orm.get_username('joegotflow83') == True)
Exemplo n.º 13
0
	def test_db_file_is_formatted_correctly(self):
		"""Test that the db file is correctly formatted for searching"""
		sample_data = ['joegotflow83,admin,joseph moran,[email protected]',
			'yoshi,dinosaur,yoshi the dinosaur,[email protected]']
		self.assertEquals(ORM.clean_file(self, sample_data), self.file_input)
Exemplo n.º 14
0
	def test_user_can_logout(self):
		"""Test user can logout"""
		self.orm = ORM(self.file_input)
		self.assertEquals(self.orm.logout('joegotflow83', 'admin'), 
										(False, None, None))
Exemplo n.º 15
0
	def test_user_info_gets_deleted(self):
		"""Test that the user info gets deleted"""
		self.orm = ORM(self.file_input)
		self.assertEquals(self.orm.delete_user_info('joegotflow83'), True)
Exemplo n.º 16
0
	def test_user_gets_welcome_message_when_logged_on(self):
		"""Test that a welcome message is displayed when the user is "logged in" """
		self.orm = ORM(self.file_input)
		username = self.file_input[0][0]
		self.assertIn(self.orm.welcome('joegotflow83'), 'Welcome back {}!'.format(username))
Exemplo n.º 17
0
	def test_db_can_find_password(self):
		"""Test that the db can find a password based on an input"""
		self.orm = ORM(self.file_input)
		self.assertTrue(self.orm.get_password('admin') == True)
Exemplo n.º 18
0
	def setUp(self):
		"""Set up testing env"""
		self.file_input = [['joegotflow83', 'admin', 'joseph moran', '*****@*****.**'],
			['yoshi', 'dinosaur', 'yoshi the dinosaur', '*****@*****.**']]
		self.orm = ORM(file_contents=self.file_input)
Exemplo n.º 19
0
	def test_db_returns_false_if_no_password_in_db(self):
		"""Test that the db returns False if no password in db"""
		self.orm = ORM(self.file_input)
		self.assertFalse(self.orm.get_password('badpassword'))
Exemplo n.º 20
0
	def test_user_can_log_on(self):
		"""Test that when a user provides the correct credentials return True"""
		self.orm = ORM(self.file_input)
		self.assertTrue(self.orm.check_credentials('joegotflow83', 'admin'))
Exemplo n.º 21
0
import orm
from orm import ORM

Orm = ORM.ORM(
    {
        'db_name': 'tutelage',
        'host': '127.0.0.1',
        'port': 5432,
        'user_name': 'postgres',
        'password': '******'
    }, 'psql').app()