def login(self): """does the nasty details for user to login """ # check the given user password from stalker import User # get the user first login = self.login_or_email_lineEdit.text() password = self.password_lineEdit.text() # check with the login or email attribute user = User.query \ .filter(or_(User.login == login, User.email == login)) \ .first() if user: self.success = user.check_password(password) if self.success: from stalker.models.auth import LocalSession session = LocalSession() session.store_user(user) session.save() self.accept() else: QtGui.QMessageBox.critical( self, "Error", "login or password is incorrect" )
def test_save_serializes_the_class_itself(self): """testing if the save function serializes the class to the filesystem """ new_local_session = LocalSession() new_local_session.save() # check if a file is created in the users local storage self.assertTrue( os.path.exists( os.path.join(defaults.local_storage_path, defaults.local_session_data_file_name)))
def test_save_serializes_the_class_itself(self): """testing if the save function serializes the class to the filesystem """ new_local_session = LocalSession() new_local_session.save() # check if a file is created in the users local storage self.assertTrue( os.path.exists( os.path.join( defaults.local_storage_path, defaults.local_session_data_file_name ) ) )
def test_delete_will_delete_the_session_cache(self): """testing if the LocalSession.delete() will delete the current cache file """ # create a new user new_user = User( name='Test User', login='******', email='*****@*****.**', password='******' ) # save it to the Database DBSession.add(new_user) DBSession.commit() self.assertTrue(new_user.id is not None) # save it to the local storage local_session = LocalSession() local_session.store_user(new_user) # save the session local_session.save() # check if the file is created # check if a file is created in the users local storage self.assertTrue( os.path.exists( os.path.join( defaults.local_storage_path, defaults.local_session_data_file_name ) ) ) # now delete the session by calling delete() local_session.delete() # check if the file is gone # check if a file is created in the users local storage self.assertFalse( os.path.exists( os.path.join( defaults.local_storage_path, defaults.local_session_data_file_name ) ) ) # delete a second time # this should not raise an OSError local_session.delete()
def test_logged_in_user_returns_the_stored_User_instance_from_last_time( self): """testing if logged_in_user returns the logged in user """ # create a new user new_user = User(name='Test User', login='******', email='*****@*****.**', password='******') # save it to the Database DBSession.add(new_user) DBSession.commit() self.assertTrue(new_user.id is not None) # save it to the local storage local_session = LocalSession() local_session.store_user(new_user) # save the session local_session.save() # now get it back with a new local_session local_session2 = LocalSession() self.assertEqual(local_session2.logged_in_user_id, new_user.id) self.assertEqual(local_session2.logged_in_user, new_user)
def login(self): """does the nasty details for user to login """ # check the given user password from stalker import User # get the user first login = self.login_or_email_lineEdit.text() password = self.password_lineEdit.text() # check with the login or email attribute user = User.query \ .filter(or_(User.login == login, User.email == login)) \ .first() if user: self.success = user.check_password(password) if self.success: from stalker.models.auth import LocalSession session = LocalSession() session.store_user(user) session.save() # also store a log import datetime from stalker.models.auth import LOGIN, AuthenticationLog al = AuthenticationLog( user=user, date=datetime.datetime.now(), action=LOGIN ) from stalker import db db.DBSession.add(al) db.DBSession.commit() self.accept() else: QtWidgets.QMessageBox.critical( self, "Error", "login or password is incorrect" )
def test_delete_will_delete_the_session_cache(self): """testing if the LocalSession.delete() will delete the current cache file """ # create a new user new_user = User(name='Test User', login='******', email='*****@*****.**', password='******') # save it to the Database DBSession.add(new_user) DBSession.commit() self.assertTrue(new_user.id is not None) # save it to the local storage local_session = LocalSession() local_session.store_user(new_user) # save the session local_session.save() # check if the file is created # check if a file is created in the users local storage self.assertTrue( os.path.exists( os.path.join(defaults.local_storage_path, defaults.local_session_data_file_name))) # now delete the session by calling delete() local_session.delete() # check if the file is gone # check if a file is created in the users local storage self.assertFalse( os.path.exists( os.path.join(defaults.local_storage_path, defaults.local_session_data_file_name))) # delete a second time # this should not raise an OSError local_session.delete()
def test_LocalSession_will_not_use_the_stored_data_if_it_is_invalid(self): """testing if the LocalSession will not use the stored session if it is not valid anymore """ # create a new user new_user = User(name='Test User', login='******', email='*****@*****.**', password='******') # save it to the Database DBSession.add(new_user) DBSession.commit() self.assertTrue(new_user.id is not None) # save it to the local storage local_session = LocalSession() local_session.store_user(new_user) # save the session local_session.save() # set the valid time to an early date local_session.valid_to = \ datetime.datetime.now() - datetime.timedelta(10) # pickle the data data = json.dumps( { 'valid_to': local_session.valid_to, 'logged_in_user_id': -1 }, default=local_session.default_json_serializer) print('data: %s' % data) local_session._write_data(data) # now get it back with a new local_session local_session2 = LocalSession() self.assertEqual(local_session2.logged_in_user_id, None) self.assertTrue(local_session2.logged_in_user is None)
def login(self): """does the nasty details for user to login """ # check the given user password from stalker import User # get the user first login = self.login_or_email_lineEdit.text() password = self.password_lineEdit.text() # check with the login or email attribute user = User.query \ .filter(or_(User.login == login, User.email == login)) \ .first() if user: self.success = user.check_password(password) if self.success: from stalker.models.auth import LocalSession session = LocalSession() session.store_user(user) session.save() self.accept() else: QtGui.QMessageBox.critical(self, "Error", "login or password is incorrect")
def test_LocalSession_initialized_with_previous_session_data(self): """testing if the when creating a new LocalSession instance the class is restored from previous time """ # test data logged_in_user_id = -10 # create a local_session local_session = LocalSession() # store some data local_session.logged_in_user_id = logged_in_user_id local_session.save() # now create a new LocalSession local_session2 = LocalSession() # now try to get the data back self.assertEqual( local_session2.logged_in_user_id, logged_in_user_id )
def test_LocalSession_will_not_use_the_stored_data_if_it_is_invalid(self): """testing if the LocalSession will not use the stored session if it is not valid anymore """ # create a new user new_user = User( name='Test User', login='******', email='*****@*****.**', password='******' ) # save it to the Database DBSession.add(new_user) DBSession.commit() self.assertTrue(new_user.id is not None) # save it to the local storage local_session = LocalSession() local_session.store_user(new_user) # save the session local_session.save() # set the valid time to an early date local_session.valid_to = \ datetime.datetime.now() - datetime.timedelta(10) # pickle the data data = json.dumps( { 'valid_to': local_session.valid_to, 'logged_in_user_id': -1 }, default=local_session.default_json_serializer ) print('data: %s' % data) local_session._write_data(data) # now get it back with a new local_session local_session2 = LocalSession() self.assertEqual( local_session2.logged_in_user_id, None ) self.assertTrue(local_session2.logged_in_user is None)
def test_logged_in_user_returns_the_stored_User_instance_from_last_time(self): """testing if logged_in_user returns the logged in user """ # create a new user new_user = User( name='Test User', login='******', email='*****@*****.**', password='******' ) # save it to the Database DBSession.add(new_user) DBSession.commit() self.assertIsNotNone(new_user.id) # save it to the local storage local_session = LocalSession() local_session.store_user(new_user) # save the session local_session.save() # now get it back with a new local_session local_session2 = LocalSession() self.assertEqual( local_session2.logged_in_user_id, new_user.id ) self.assertEqual( local_session2.logged_in_user, new_user )
def login(self): """does the nasty details for user to login """ # check the given user password from stalker import User # get the user first login = self.login_or_email_lineEdit.text() password = self.password_lineEdit.text() # check with the login or email attribute user = User.query \ .filter(or_(User.login == login, User.email == login)) \ .first() if user: self.success = user.check_password(password) if self.success: from stalker.models.auth import LocalSession session = LocalSession() session.store_user(user) session.save() # also store a log import datetime from stalker.models.auth import LOGIN, AuthenticationLog al = AuthenticationLog( user=user, date=datetime.datetime.now(), action=LOGIN ) from stalker.db.session import DBSession DBSession.add(al) DBSession.commit() self.accept() else: QtWidgets.QMessageBox.critical( self, "Error", "login or password is incorrect" )
def test_LocalSession_initialized_with_previous_session_data(self): """testing if the when creating a new LocalSession instance the class is restored from previous time """ # test data logged_in_user_id = -10 # create a local_session local_session = LocalSession() # store some data local_session.logged_in_user_id = logged_in_user_id local_session.save() # now create a new LocalSession local_session2 = LocalSession() # now try to get the data back self.assertEqual(local_session2.logged_in_user_id, logged_in_user_id)
def setUpClass(cls): """setup once """ # remove the transaction manager db.DBSession.remove() cls.repo_path = tempfile.mkdtemp() defaults.local_storage_path = tempfile.mktemp() db.setup({ 'sqlalchemy.url': 'sqlite:///:memory:', 'sqlalchemy.echo': 'false' }) db.init() # create Power Users Group cls.power_users_group = Group(name='Power Users') db.DBSession.add(cls.power_users_group) db.DBSession.commit() # create a LocalSession first cls.admin = User.query.all()[0] cls.lsession = LocalSession() cls.lsession.store_user(cls.admin) cls.lsession.save() # create a repository cls.test_repo1 = Repository(name='Test Repository', windows_path='T:/TestRepo/', linux_path='/mnt/T/TestRepo/', osx_path='/Volumes/T/TestRepo/') cls.test_structure1 = Structure(name='Test Project Structure', templates=[], custom_template='') cls.status_new = Status.query.filter_by(code='NEW').first() cls.status_wip = Status.query.filter_by(code='WIP').first() cls.status_cmpl = Status.query.filter_by(code='CMPL').first() cls.project_status_list = StatusList( name='Project Statuses', statuses=[cls.status_new, cls.status_wip, cls.status_cmpl], target_entity_type=Project) # create a couple of projects cls.test_project1 = Project(name='Project 1', code='P1', repository=cls.test_repo1, structure=cls.test_structure1, status_list=cls.project_status_list) cls.test_project2 = Project(name='Project 2', code='P2', repository=cls.test_repo1, structure=cls.test_structure1, status_list=cls.project_status_list) cls.test_project3 = Project(name='Project 3', code='P3', repository=cls.test_repo1, structure=cls.test_structure1, status_list=cls.project_status_list) cls.projects = [ cls.test_project1, cls.test_project2, cls.test_project3 ] cls.test_user1 = User( name='Test User', # groups=[self.power_users_group], login='******', email='*****@*****.**', password='******') db.DBSession.add(cls.test_user1) db.DBSession.commit() cls.admin.projects.append(cls.test_project1) cls.admin.projects.append(cls.test_project2) cls.admin.projects.append(cls.test_project3) cls.test_user1.projects.append(cls.test_project1) cls.test_user1.projects.append(cls.test_project2) cls.test_user1.projects.append(cls.test_project3) # project 1 cls.test_task1 = Task( name='Test Task 1', project=cls.test_project1, resources=[cls.admin], ) cls.test_task2 = Task( name='Test Task 2', project=cls.test_project1, resources=[cls.admin], ) cls.test_task3 = Task( name='Test Task 2', project=cls.test_project1, resources=[cls.admin], ) # project 2 cls.test_task4 = Task( name='Test Task 4', project=cls.test_project2, resources=[cls.admin], ) cls.test_task5 = Task( name='Test Task 5', project=cls.test_project2, resources=[cls.admin], ) cls.test_task6 = Task( name='Test Task 6', parent=cls.test_task5, resources=[cls.admin], ) cls.test_task7 = Task( name='Test Task 7', parent=cls.test_task5, resources=[], ) cls.test_task8 = Task( name='Test Task 8', parent=cls.test_task5, resources=[], ) cls.test_task9 = Task( name='Test Task 9', parent=cls.test_task5, resources=[], ) # +-> Project 1 # | | # | +-> Task1 # | | # | +-> Task2 # | | # | +-> Task3 # | # +-> Project 2 # | | # | +-> Task4 # | | # | +-> Task5 # | | # | +-> Task6 # | | # | +-> Task7 (no resource) # | | # | +-> Task8 (no resource) # | | # | +-> Task9 (no resource) # | # +-> Project 3 # record them all to the db db.DBSession.add_all([ cls.admin, cls.test_project1, cls.test_project2, cls.test_project3, cls.test_task1, cls.test_task2, cls.test_task3, cls.test_task4, cls.test_task5, cls.test_task6, cls.test_task7, cls.test_task8, cls.test_task9 ]) db.DBSession.commit() cls.all_tasks = [ cls.test_task1, cls.test_task2, cls.test_task3, cls.test_task4, cls.test_task5, cls.test_task6, cls.test_task7, cls.test_task8, cls.test_task9 ] # create versions cls.test_version1 = Version(cls.test_task1, created_by=cls.admin, created_with='Test', description='Test Description') db.DBSession.add(cls.test_version1) db.DBSession.commit() cls.test_version2 = Version(cls.test_task1, created_by=cls.admin, created_with='Test', description='Test Description') db.DBSession.add(cls.test_version2) db.DBSession.commit() cls.test_version3 = Version(cls.test_task1, created_by=cls.admin, created_with='Test', description='Test Description') cls.test_version3.is_published = True db.DBSession.add(cls.test_version3) db.DBSession.commit() cls.test_version4 = Version(cls.test_task1, take_name='Main@GPU', created_by=cls.admin, created_with='Test', description='Test Description') cls.test_version4.is_published = True db.DBSession.add(cls.test_version4) db.DBSession.commit() if not QtGui.QApplication.instance(): logger.debug('creating a new QApplication') cls.app = QtGui.QApplication(sys.argv) else: logger.debug('using the present QApplication: %s' % QtGui.qApp) # self.app = QtGui.qApp cls.app = QtGui.QApplication.instance() # cls.test_environment = TestEnvironment() cls.dialog = version_creator.MainDialog()