Пример #1
0
    def test_save_get_login_filtered_users(self):
        test_user_1 = User()
        test_user_1.login = '******'
        test_user_1.password = '******'

        test_user_2 = User()
        test_user_2.login = '******'
        test_user_2.password = '******'

        success = self.storage.save_user(test_user_1)
        self.assertEqual(success, True)
        success = self.storage.save_user(test_user_2)
        self.assertEqual(success, True)
        success = self.storage.save_user(test_user_1)
        self.assertEqual(success, True)

        filter = UserStorageAdapter.Filter()
        filter.login('first login')
        users_in_db = self.storage.get_users(filter)
        self.assertEqual(len(users_in_db), 2)

        test_user_1.uid = 1
        self.assertEqual(users_in_db[0], test_user_1)

        test_user_1.uid = 3
        self.assertEqual(users_in_db[1], test_user_1)
Пример #2
0
    def test_save_get_all_filtered_users(self):
        test_user_1 = User()
        test_user_1.login = '******'
        test_user_1.password = '******'
        test_user_1.online = True

        success = self.storage.save_user(test_user_1)
        self.assertEqual(success, True)
        success = self.storage.save_user(test_user_1)
        self.assertEqual(success, True)

        filter = UserStorageAdapter.Filter()
        filter.login('first login')
        filter.online(False)
        users_in_db = self.storage.get_users(filter)
        self.assertEqual(len(users_in_db), 0)
Пример #3
0
    def test_save_get_project(self):
        project = Project()
        project.creator = 1
        project.name = 'Test'

        user = User()
        user.login = '******'
        self.user_storage.save_user(user)

        success = self.storage.save_project(project)
        self.assertEqual(success, True)

        projects_in_db = self.storage.get_projects(1)
        self.assertEqual(len(projects_in_db), 1)

        project.pid = 1
        self.assertEqual(project, projects_in_db[0])
Пример #4
0
    def setUp(self):
        self.storage_task = TaskStorageAdapter(_TEST_DB)
        self.storage_user = UserStorageAdapter(_TEST_DB)
        self.storage_project = ProjectStorageAdapter(_TEST_DB)

        user = User()
        self.storage_user.save_user(user)
        project = Project()
        project.creator = 1
        self.storage_project.save_project(project)
Пример #5
0
    def test_save_remove_get_users(self):
        test_user = User()
        test_user.login = '******'
        test_user.password = '******'
        test_user.online = True

        success = self.storage.save_user(test_user)
        self.assertEqual(success, True)
        success = self.storage.save_user(test_user)
        self.assertEqual(success, True)

        users_in_db = self.storage.get_users()

        success = self.storage.delete_user(users_in_db[0].uid)
        self.assertEqual(success, True)

        users_in_db_after_delete = self.storage.get_users()

        self.assertEqual(len(users_in_db_after_delete), 1)
        self.assertEqual(users_in_db_after_delete[0], users_in_db[1])
Пример #6
0
    def test_save_edit_get_project(self):
        project = Project()
        project.creator = 1
        project.name = 'Test'

        user = User()
        user.login = '******'
        self.user_storage.save_user(user)

        self.storage.save_project(project)

        project_fields = {Project.Field.pid: 1, Project.Field.name: 'New test'}
        success = self.storage.edit_project(project_fields)
        self.assertEqual(success, True)

        projects_in_db = self.storage.get_projects(1)
        self.assertEqual(len(projects_in_db), 1)

        project.pid = 1
        project.name = 'New test'
        self.assertEqual(project, projects_in_db[0])
Пример #7
0
    def test_save_task_remove_user(self):
        test_task_1 = Task()
        test_task_1.pid = 1
        test_task_1.title = 'title 1'
        test_task_1.description = 'description 1'
        test_task_1.deadline_time = 23233

        test_task_2 = Task()
        test_task_2.pid = 1
        test_task_2.title = 'title 2'
        test_task_2.description = 'description 1'
        test_task_2.deadline_time = 23233

        test_user = User()
        test_user.login = '******'
        test_user.password = '******'
        test_user.online = True

        self.storage_user.save_user(test_user)
        test_user.uid = self.storage_user.get_users()[0].uid
        test_task_1.uid = test_user.uid
        self.storage_task.save_task(test_task_1)
        self.storage_task.save_task(test_task_2)

        self.storage_user.delete_user(test_user.uid)

        tasks_in_db = self.storage_task.get_tasks()
        self.assertEqual(len(tasks_in_db), 1)

        test_task_2.tid = tasks_in_db[0].tid
        self.assertEqual(test_task_2, tasks_in_db[0])
 def to_user(self):
     user = User()
     user.uid = self.uid
     user.login = self.login
     user.password = self.password
     user.online = self.online
     return user
Пример #9
0
    def test_save_remove_get_project(self):
        project1 = Project()
        project1.creator = 1
        project1.name = 'Test 1'

        project2 = Project()
        project2.creator = 1
        project2.name = 'Test 2'

        user = User()
        user.login = '******'
        self.user_storage.save_user(user)

        self.storage.save_project(project1)
        self.storage.save_project(project2)

        success = self.storage.remove_project(2)
        self.assertEqual(success, True)

        projects_in_db = self.storage.get_projects(1)
        self.assertEqual(len(projects_in_db), 1)

        project1.pid = 1
        self.assertEqual(project1, projects_in_db[0])
    def test_default_project_created_when_new_user_added(self):

        class ProjectStorageAdapterMock():

            _saved_project = None

            def save_project(self, project):
                self.__class__._saved_project = project
                return True

        class UserStorageAdapterMock():

            _saved_user = None

            def save_user(self, user):
                self.__class__._saved_user = user
                self.__class__._saved_user.uid = 1
                return True

            def check_user_existence(self, login):
                return False

            def get_last_saved_user(self):
                return self._saved_user

        Controller.init_storage_adapters(user_storage_adapter=UserStorageAdapterMock,
                              project_storage_adapter=ProjectStorageAdapterMock)

        user = User()
        user.login = '******'
        self.user_controller.save_user(user)

        project = Project()
        project.creator = 1
        project.name = Project.default_project_name
        self.assertEqual(project, ProjectStorageAdapterMock._saved_project)
Пример #11
0
    def test_save_get_users(self):
        test_user = User()
        test_user.login = '******'
        test_user.password = '******'

        success = self.storage.save_user(test_user)
        self.assertEqual(success, True)
        success = self.storage.save_user(test_user)
        self.assertEqual(success, True)

        users_in_db = self.storage.get_users()
        self.assertEqual(len(users_in_db), 2)

        test_user.uid = 1
        self.assertEqual(users_in_db[0], test_user)
        test_user.uid = 2
        self.assertEqual(users_in_db[1], test_user)
Пример #12
0
    def test_save_get_user_task(self):
        test_task = Task()
        test_task.pid = 1
        test_task.title = 'title 1'
        test_task.description = 'description 1'
        test_task.deadline_time = 23233

        test_user = User()
        test_user.login = '******'
        test_user.password = '******'
        test_user.online = True

        self.storage_user.save_user(test_user)
        test_user.uid = self.storage_user.get_users()[0].uid
        test_task.uid = test_user.uid
        self.storage_task.save_task(test_task)

        filter = TaskStorageAdapter.Filter()
        filter.uid(test_user.uid)
        tasks_in_db = self.storage_task.get_tasks(filter)
        self.assertEqual(len(tasks_in_db), 1)

        test_task.tid = tasks_in_db[0].tid
        self.assertEqual(test_task, tasks_in_db[0])
Пример #13
0
    def test_save_edit_get_tasks(self):
        test_user = User()
        test_user.login = '******'
        test_user.password = '******'
        test_user.online = True

        edited_test_user = User()
        edited_test_user.uid = 1
        edited_test_user.login = '******'
        edited_test_user.password = '******'
        edited_test_user.online = False

        success = self.storage.save_user(test_user)
        self.assertEqual(success, True)
        success = self.storage.save_user(test_user)
        self.assertEqual(success, True)

        users_in_db = self.storage.get_users()

        success = self.storage.edit_user({
            User.Field.uid: 1,
            User.Field.login: '******',
            User.Field.online: False
        })
        self.assertEqual(success, True)

        users_in_db_after_edit = self.storage.get_users()

        self.assertEqual(len(users_in_db_after_edit), 2)
        self.assertEqual(users_in_db_after_edit[0], edited_test_user)
        self.assertEqual(users_in_db_after_edit[1], users_in_db[1])
Пример #14
0
    def test_save_get_login_online_filtered_users(self):
        test_user_1 = User()
        test_user_1.login = '******'
        test_user_1.password = '******'
        test_user_1.online = True

        test_user_2 = User()
        test_user_2.login = '******'
        test_user_2.password = '******'
        test_user_2.online = False

        test_user_3 = User()
        test_user_3.login = '******'
        test_user_3.password = '******'
        test_user_3.online = True

        success = self.storage.save_user(test_user_1)
        self.assertEqual(success, True)
        success = self.storage.save_user(test_user_2)
        self.assertEqual(success, True)
        success = self.storage.save_user(test_user_3)
        self.assertEqual(success, True)

        filter = UserStorageAdapter.Filter()
        filter.login('second login')
        filter.online(False)
        users_in_db = self.storage.get_users(filter)
        self.assertEqual(len(users_in_db), 1)

        test_user_2.uid = 2
        self.assertEqual(users_in_db[0], test_user_2)
Пример #15
0
 def get_users(self, uid):
     user = User()
     return [user]