Beispiel #1
0
    def test_put_tags_view_will_raise_404(self):
        """testing if the PUT /api/entities/{id}/tags view will return 404
        """
        from stalker import db, User, Tag
        test_user1 = User(name='Test User 1',
                          login='******',
                          email='*****@*****.**',
                          password='******')
        db.DBSession.add(test_user1)

        tag1 = Tag(name='Tag1')
        tag2 = Tag(name='Tag2')
        tag3 = Tag(name='Tag3')
        tag4 = Tag(name='Tag4')
        tag5 = Tag(name='Tag5')
        db.DBSession.add_all([tag1, tag2, tag3, tag4, tag5])

        test_user1.tags = [tag1, tag2, tag3]

        import transaction
        transaction.commit()

        test_user1 = User.query.filter(User.login == test_user1.login).first()
        self.test_app.put('/api/entities/%s/tags?tag=%s' %
                          (test_user1.id, tag4.name),
                          status=404)
Beispiel #2
0
    def test_delete_tags_view_is_working_properly(self):
        """testing if the DELETE /api/entities/{id}/tags view is working
        properly
        """
        from stalker import db, User, Tag
        test_user1 = User(name='Test User 1',
                          login='******',
                          email='*****@*****.**',
                          password='******')
        db.DBSession.add(test_user1)

        tag1 = Tag(name='Tag1')
        tag2 = Tag(name='Tag2')
        tag3 = Tag(name='Tag3')
        tag4 = Tag(name='Tag4')
        tag5 = Tag(name='Tag5')
        db.DBSession.add_all([tag1, tag2, tag3, tag4, tag5])

        test_user1.tags = [tag1, tag2, tag3]

        import transaction
        transaction.commit()

        test_user1 = User.query.filter(User.login == test_user1.login).first()
        self.test_app.delete('/api/entities/%s/tags?tag=%s' %
                             (test_user1.id, tag3.name),
                             status=200)

        test_user1 = User.query.filter(User.login == test_user1.login).first()
        self.assertEqual(sorted([tag.name for tag in test_user1.tags]),
                         ['Tag1', 'Tag2'])
Beispiel #3
0
    def test_update_entity_is_working_properly_with_post(self):
        """testing if POST: /api/entities/{id} is working properly
        """
        from stalker import db, Entity, User
        test_user_1 = User(name='Test User 1',
                           login='******',
                           email='*****@*****.**',
                           password='******')
        db.DBSession.add(test_user_1)

        test_user_2 = User(name='Test User 2',
                           login='******',
                           email='*****@*****.**',
                           password='******')
        db.DBSession.add(test_user_2)

        test_entity = Entity(name='Test Entity', created_by=test_user_1)
        db.DBSession.add(test_entity)
        db.DBSession.commit()

        self.test_app.post('/api/entities/%s' % test_entity.id,
                           params={
                               'name': 'New Entity Name',
                               'description': 'New Description',
                               'updated_by_id': test_user_2.id
                           },
                           status=200)

        test_entity_db = Entity.query.get(test_entity.id)
        self.assertEqual(test_entity_db.name, 'New Entity Name')
        self.assertEqual(test_entity_db.description, 'New Description')
        self.assertEqual(test_entity_db.updated_by, test_user_2)
Beispiel #4
0
    def setUp(self):
        """setup the test
        """
        # create a resource
        self.test_resource1 = User(
            name="User1",
            login="******",
            email="*****@*****.**",
            password="******",
        )

        self.test_resource2 = User(
            name="User2",
            login="******",
            email="*****@*****.**",
            password="******"
        )

        self.test_repo = Repository(name="test repository")

        # create a Project
        self.test_status1 = Status(name="Status1", code="STS1")
        self.test_status2 = Status(name="Status2", code="STS2")
        self.test_status3 = Status(name="Status3", code="STS3")

        self.test_project_status_list = StatusList(
            name="Project Statuses",
            statuses=[self.test_status1],
            target_entity_type=Project
        )

        self.test_task_status_list = StatusList.query\
            .filter_by(target_entity_type='Task').first()

        self.test_project = Project(
            name="test project",
            code='tp',
            repository=self.test_repo,
            status_list=self.test_project_status_list
        )

        # create a Task
        self.test_task = Task(
            name="test task",
            project=self.test_project,
            status_list=self.test_task_status_list
        )

        self.kwargs = {
            "task": self.test_task,
            "resource": self.test_resource1,
            "start": datetime.datetime(2013, 3, 22, 1, 0),
            "duration": datetime.timedelta(10)
        }

        # create a TimeLog
        # and test it
        self.test_time_log = TimeLog(**self.kwargs)
Beispiel #5
0
    def setUp(self):
        """set the test up
        """
        super(AuthenticationLogTestCase, self).setUp()

        from stalker import User
        self.test_user1 = User(name='Test User 1',
                               login='******',
                               email='*****@*****.**',
                               password='******')

        self.test_user2 = User(name='Test User 2',
                               login='******',
                               email='*****@*****.**',
                               password='******')
Beispiel #6
0
    def test_update_entity_is_working_properly(self):
        """testing if update_note is working properly
        """
        from stalker import db, Note, User
        test_user = User(name='Test User',
                         login='******',
                         email='*****@*****.**',
                         password='******')
        db.DBSession.add(test_user)

        note1 = Note(content='This is a test note')
        db.DBSession.add(note1)
        db.DBSession.commit()

        from stalker_pyramid.testing import DummyRequest, DummyMultiDict
        request = DummyRequest()
        request.matchdict['id'] = note1.id
        request.params = DummyMultiDict()
        request.params['content'] = 'this is the new content'
        request.params['updated_by_id'] = test_user.id

        note_view = note.NoteViews(request)
        note_view.update_entity()

        note1 = Note.query.first()
        self.assertEqual(note1.content, 'this is the new content')
        self.assertEqual(note1.updated_by, test_user)
Beispiel #7
0
    def setUp(self):
        """set the test
        """
        super(SimpleEntityDBTester, self).setUp()
        from stalker import User
        import json
        self.test_user = User(
            name="Test User",
            login="******",
            email="*****@*****.**",
            password="******",
            generic_text=json.dumps({'Phone number': '123'}, sort_keys=True),
        )
        from stalker.db.session import DBSession
        DBSession.add(self.test_user)
        DBSession.commit()

        import datetime
        import pytz
        self.date_created = \
            datetime.datetime(2010, 10, 21, 3, 8, 0, tzinfo=pytz.utc)
        self.date_updated = self.date_created

        self.kwargs = {
            "name": "Test Entity",
            "code": "TstEnt",
            "description": "This is a test entity, and this is a proper \
            description for it",
            "created_by": self.test_user,
            "updated_by": self.test_user,
            "date_created": self.date_created,
            "date_updated": self.date_updated,
            'generic_text': json.dumps({'Phone number': '123'},
                                       sort_keys=True),
        }
    def setUp(self):
        """setup the test
        """
        super(VacationTestCase, self).setUp()

        # create a user
        from stalker import User
        self.test_user = User(
            name='Test User',
            login='******',
            email='*****@*****.**',
            password='******',
        )

        # vacation type
        from stalker import Type
        self.personal_vacation = Type(name='Personal',
                                      code='PERS',
                                      target_entity_type='Vacation')

        self.studio_vacation = Type(name='Studio Wide',
                                    code='STD',
                                    target_entity_type='Vacation')

        import datetime
        import pytz
        self.kwargs = {
            'user': self.test_user,
            'type': self.personal_vacation,
            'start': datetime.datetime(2013, 6, 6, 10, 0, tzinfo=pytz.utc),
            'end': datetime.datetime(2013, 6, 10, 19, 0, tzinfo=pytz.utc)
        }

        self.test_vacation = Vacation(**self.kwargs)
Beispiel #9
0
    def setUp(self):
        """set the test up
        """
        super(ProjectClientTestDBCase, self).setUp()

        from stalker import Status, Repository
        self.test_repo = Repository(name='Test Repo')
        self.status_new = Status(name='New', code='NEW')
        self.status_wip = Status(name='Work In Progress', code='WIP')
        self.status_cmpl = Status(name='Completed', code='CMPL')

        from stalker import User
        self.test_user1 = User(name='Test User 1',
                               login='******',
                               email='*****@*****.**',
                               password='******')

        from stalker import Client
        self.test_client = Client(name='Test Client')

        from stalker import Project
        self.test_project = Project(
            name='Test Project 1',
            code='TP1',
            repositories=[self.test_repo],
        )

        from stalker import Role
        self.test_role = Role(name='Test Client')
Beispiel #10
0
    def setUp(self):
        """setup the test
        """
        # create a user
        self.test_user = User(
            name='Test User',
            login='******',
            email='*****@*****.**',
            password='******',
        )

        # vacation type
        self.personal_vacation = Type(
            name='Personal',
            code='PERS',
            target_entity_type='Vacation'
        )

        self.studio_vacation = Type(
            name='Studio Wide',
            code='STD',
            target_entity_type='Vacation'
        )

        self.kwargs = {
            'user': self.test_user,
            'type': self.personal_vacation,
            'start': datetime.datetime(2013, 6, 6, 10, 0),
            'end': datetime.datetime(2013, 6, 10, 19, 0)
        }

        self.test_vacation = Vacation(**self.kwargs)
    def test_delete_entity(self):
        """testing if delete_entity() method is working properly
        """
        from stalker import db, User, Vacation
        user1 = User(name='Test User 1',
                     login='******',
                     email='*****@*****.**',
                     password='******')
        db.DBSession.add(user1)

        import datetime
        start = datetime.datetime(2016, 4, 22, 10)
        end = datetime.datetime(2016, 4, 22, 16)
        vac1 = Vacation(user=user1, start=start, end=end)

        db.DBSession.commit()

        vac1 = Vacation.query.filter(Vacation.name == vac1.name).first()

        from stalker_pyramid.testing import DummyRequest
        request = DummyRequest()
        request.matchdict['id'] = vac1.id

        vacation_views = vacation.VacationViews(request)
        vacation_views.delete_entity()

        vac = Vacation.query.filter(Vacation.name == vac1.name).all()
        self.assertEqual(vac, [])
    def test_create_entity_with_missing_end(self):
        """testing if create_entity() method is working properly with missing
        end parameter
        """
        from stalker import db, User
        user1 = User(name='Test User 1',
                     login='******',
                     email='*****@*****.**',
                     password='******')
        db.DBSession.add(user1)
        db.DBSession.commit()

        import datetime
        start = datetime.datetime(2016, 4, 22, 10)
        user1 = User.query.filter(User.login == user1.login).first()

        from stalker_pyramid.testing import DummyRequest, DummyMultiDict
        from stalker_pyramid.views import EntityViewBase
        request = DummyRequest()
        request.params = DummyMultiDict()
        request.params['user_id'] = user1.id
        request.params['start'] = \
            EntityViewBase.milliseconds_since_epoch(start)

        vacation_views = vacation.VacationViews(request)

        from pyramid.httpexceptions import HTTPServerError
        with self.assertRaises(HTTPServerError) as cm:
            vacation_views.create_entity()

        self.assertEqual(str(cm.exception), 'Missing "end" parameter')
Beispiel #13
0
    def setUp(self):
        """setting up some proper values
        """
        # create a user
        self.test_user = User(name="Test User",
                              login="******",
                              email="*****@*****.**",
                              password="******")

        # create some test Tag objects, not necessarily needed but create them
        self.test_tag1 = Tag(name="Test Tag 1")
        self.test_tag2 = Tag(name="Test Tag 1")  # make it equal to tag1
        self.test_tag3 = Tag(name="Test Tag 3")

        self.tags = [self.test_tag1, self.test_tag2]

        # create a couple of test Note objects
        self.test_note1 = Note(name="test note1", content="test note1")
        self.test_note2 = Note(name="test note2", content="test note2")
        self.test_note3 = Note(name="test note3", content="test note3")

        self.notes = [self.test_note1, self.test_note2]

        self.kwargs = {
            "name": "Test Entity",
            "description": "This is a test entity, and this is a proper \
            description for it",
            "created_by": self.test_user,
            "updated_by": self.test_user,
            "tags": self.tags,
            "notes": self.notes,
        }

        # create a proper SimpleEntity to use it later in the tests
        self.test_entity = Entity(**self.kwargs)
Beispiel #14
0
    def setUp(self):
        """set the test up
        """
        super(ProjectUserTestDBCase, self).setUp()

        from stalker import Repository
        self.test_repo = Repository(name='Test Repo')

        from stalker.db.session import DBSession
        DBSession.add(self.test_repo)
        DBSession.commit()

        from stalker import User
        self.test_user1 = User(name='Test User 1',
                               login='******',
                               email='*****@*****.**',
                               password='******')
        DBSession.add(self.test_user1)

        from stalker import Project
        self.test_project = Project(
            name='Test Project 1',
            code='TP1',
            repositories=[self.test_repo],
        )
        DBSession.add(self.test_project)

        from stalker import Role
        self.test_role = Role(name='Test User')
        DBSession.add(self.test_role)
        DBSession.commit()
    def test_update_entity_change_end_with_post(self):
        """testing POST: /api/vacations/{id}?end={value} is working properly
        """
        from stalker import db, User, Vacation
        user1 = User(name='Test User 1',
                     login='******',
                     email='*****@*****.**',
                     password='******')
        db.DBSession.add(user1)

        import datetime
        start = datetime.datetime(2016, 4, 22, 10)
        end = datetime.datetime(2016, 4, 22, 16)
        new_end = datetime.datetime(2016, 4, 22, 17)
        vac1 = Vacation(user=user1, start=start, end=end)
        db.DBSession.commit()

        user1 = User.query.filter(User.login == user1.login).first()
        vac1 = Vacation.query.filter(Vacation.name == vac1.name).first()

        from stalker_pyramid.views import EntityViewBase
        self.admin_login()
        self.test_app.patch(
            '/api/vacations/%s' % vac1.id,
            params={'end': EntityViewBase.milliseconds_since_epoch(new_end)},
            status=200)

        vac = Vacation.query.filter(Vacation.name == vac1.name).first()
        self.assertEqual(vac.start, start)
        self.assertEqual(vac.end, new_end)
        self.assertEqual(vac.user, user1)
    def test_create_entity_missing_end(self):
        """testing if PUT: /api/vacations view with missing end parameter
        """
        from stalker import db, User
        user1 = User(name='Test User 1',
                     login='******',
                     email='*****@*****.**',
                     password='******')
        db.DBSession.add(user1)
        db.DBSession.commit()

        import datetime
        start = datetime.datetime(2016, 4, 22, 10)
        user1 = User.query.filter(User.login == user1.login).first()

        from stalker_pyramid.views import EntityViewBase
        self.admin_login()
        response = self.test_app.put(
            '/api/vacations',
            params={
                'user_id': user1.id,
                'start': EntityViewBase.milliseconds_since_epoch(start)
            },
            status=500)

        self.assertEqual(str(response.body),
                         'Server Error: Missing "end" parameter')
    def test_create_entity_missing_user_id(self):
        """testing if PUT: /api/vacations view with missing user_id parameter
        """
        from stalker import db, User
        user1 = User(name='Test User 1',
                     login='******',
                     email='*****@*****.**',
                     password='******')
        db.DBSession.add(user1)
        db.DBSession.commit()

        import datetime
        start = datetime.datetime(2016, 4, 22, 10)
        end = datetime.datetime(2016, 4, 22, 16)

        from stalker_pyramid.views import EntityViewBase
        response = self.test_app.put(
            '/api/vacations',
            params={
                'start': EntityViewBase.milliseconds_since_epoch(start),
                'end': EntityViewBase.milliseconds_since_epoch(end),
            },
            status=500)

        self.assertEqual(response.body,
                         'Server Error: Missing "user_id" parameter')
Beispiel #18
0
    def setUp(self):
        """set the test up
        """
        from stalker import Status, StatusList, Repository
        self.test_repo = Repository(name='Test Repo')
        self.status_new = Status(name='New', code='NEW')
        self.status_wip = Status(name='Work In Progress', code='WIP')
        self.status_cmpl = Status(name='Completed', code='CMPL')

        self.project_statuses = StatusList(
            name='Project Status List',
            statuses=[self.status_new, self.status_wip, self.status_cmpl],
            target_entity_type='Project')

        from stalker import User
        self.test_user1 = User(name='Test User 1',
                               login='******',
                               email='*****@*****.**',
                               password='******')

        from stalker import Project
        self.test_project = Project(name='Test Project 1',
                                    code='TP1',
                                    repositories=[self.test_repo],
                                    status_list=self.project_statuses)

        from stalker import Role
        self.test_role = Role(name='Test User')
    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)
Beispiel #20
0
    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
        from stalker import User
        new_user = User(name='Test User',
                        login='******',
                        email='*****@*****.**',
                        password='******')

        # save it to the Database
        from stalker.db.session import DBSession
        DBSession.add(new_user)
        DBSession.commit()
        assert new_user.id is not None

        # save it to the local storage
        from stalker import LocalSession
        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()

        assert local_session2.logged_in_user_id == new_user.id
        assert local_session2.logged_in_user == new_user
    def test_update_entity_change_user(self):
        """testing if update_entity() method is working properly for changing
        user attribute
        """
        from stalker import db, User, Vacation
        user1 = User(name='Test User 1',
                     login='******',
                     email='*****@*****.**',
                     password='******')
        db.DBSession.add(user1)

        user2 = User(name='Test User 2',
                     login='******',
                     email='*****@*****.**',
                     password='******')
        db.DBSession.add(user2)

        import datetime
        start = datetime.datetime(2016, 4, 22, 10)
        end = datetime.datetime(2016, 4, 22, 16)
        vac1 = Vacation(user=user1, start=start, end=end)

        db.DBSession.commit()

        user2 = User.query.filter(User.login == user2.login).first()
        vac1 = Vacation.query.filter(Vacation.name == vac1.name).first()
        # also update updated_by_id attribute

        from stalker_pyramid.testing import DummyRequest, DummyMultiDict
        request = DummyRequest()
        request.matchdict['id'] = vac1.id

        request.params = DummyMultiDict()

        # change user
        request.params['user_id'] = user2.id
        request.params['updated_by_id'] = user2.id

        self.patch_logged_in_user(request)
        vacation_views = vacation.VacationViews(request)
        vacation_views.update_entity()

        vac = Vacation.query.filter(Vacation.name == vac1.name).first()
        self.assertEqual(vac.start, start)
        self.assertEqual(vac.end, end)
        self.assertEqual(vac.user, user2)
        self.assertEqual(vac.updated_by, user2)
Beispiel #22
0
    def test_delete_will_delete_the_session_cache(self):
        """testing if the LocalSession.delete() will delete the current cache
        file
        """
        # create a new user
        from stalker import db, User
        new_user = User(
            name='Test User',
            login='******',
            email='*****@*****.**',
            password='******'
        )

        # save it to the Database
        db.DBSession.add(new_user)
        db.DBSession.commit()

        self.assertTrue(new_user.id is not None)

        # save it to the local storage
        from stalker import LocalSession
        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
        import os
        from stalker import defaults
        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()
Beispiel #23
0
    def test_get_tags_view_is_working_properly(self):
        """testing if the GET /api/entities/{id}/tags view is working properly
        """
        from stalker import db, User, Tag
        test_user1 = User(name='Test User 1',
                          login='******',
                          email='*****@*****.**',
                          password='******')
        db.DBSession.add(test_user1)

        tag1 = Tag(name='Tag1')
        tag2 = Tag(name='Tag2')
        tag3 = Tag(name='Tag3')
        tag4 = Tag(name='Tag4')
        tag5 = Tag(name='Tag5')
        db.DBSession.add_all([tag1, tag2, tag3, tag4, tag5])

        test_user1.tags = [tag1, tag2, tag3]

        import transaction
        transaction.commit()

        test_user1 = User.query.filter(User.login == test_user1.login).first()
        response = self.test_app.get('/api/entities/%s/tags' % test_user1.id,
                                     status=200)

        self.assertEqual(
            sorted(response.json_body),
            sorted([{
                'id': tag1.id,
                '$ref': '/api/tags/%s' % tag1.id,
                'name': 'Tag1',
                'entity_type': 'Tag'
            }, {
                'id': tag2.id,
                '$ref': '/api/tags/%s' % tag2.id,
                'name': 'Tag2',
                'entity_type': 'Tag'
            }, {
                'id': tag3.id,
                '$ref': '/api/tags/%s' % tag3.id,
                'name': 'Tag3',
                'entity_type': 'Tag'
            }]))
Beispiel #24
0
    def setUp(self):
        """create the test data
        """
        super(DepartmentViewsFunctionalTestCase, self).setUp()

        from stalker import db, User
        self.test_user1 = User(name='Test User 1',
                               login='******',
                               email='*****@*****.**',
                               password='******',
                               created_by=self.admin)
        db.DBSession.add(self.test_user1)

        self.test_user2 = User(name='Test User 2',
                               login='******',
                               email='*****@*****.**',
                               password='******',
                               created_by=self.admin)
        db.DBSession.add(self.test_user2)

        self.test_user3 = User(name='Test User 3',
                               login='******',
                               email='*****@*****.**',
                               password='******',
                               created_by=self.admin)
        db.DBSession.add(self.test_user3)

        from stalker import Department
        self.test_department1 = Department(name='Test Department 1',
                                           created_by=self.admin)
        db.DBSession.add(self.test_department1)

        self.test_department2 = Department(name='Test Department 2',
                                           created_by=self.admin)
        db.DBSession.add(self.test_department2)

        # create a couple of roles
        from stalker import Role
        self.test_role1 = Role(name='Test Role 1', created_by=self.admin)
        self.test_role2 = Role(name='Test Role 2', created_by=self.admin)
        self.test_role3 = Role(name='Test Role 3', created_by=self.admin)
        db.DBSession.add_all(
            [self.test_role1, self.test_role2, self.test_role3])
        db.DBSession.commit()
Beispiel #25
0
    def create_user(self):
        """
        Creates new user
        """

        from stalker.db.session import DBSession
        from stalker import User

        new_user = User(
            name="{0}".format(self.user_name),
            login="******".format(self.user_login),
            email="{0}".format(self.user_email),
            password="******".format(self.user_password)
        )
        

        #Checks if the user's name and e-mail address are registered in the database.
        #Sends a warning message to the user if registered.

        if not User.query.filter_by(email=self.user_email).scalar() == None:
            QtWidgets.QMessageBox.warning(
                self,
                "Warning",
                "The email address you entered already belongs to an existing user , Please re-enter your e-mail address!"
            )

        elif not User.query.filter_by(login=self.user_login).scalar() == None:
            QtWidgets.QMessageBox.warning(
                self,
                "Warning",
                "The user '{0}' already exists, Please enter new username!".format(self.user_login)
            )


        else:
            try: 
                # Save the user to database
                DBSession.save(new_user)

            #Gets the string representation of an exception
            except BaseException as e:
                DBSession.rollback()
                QtWidgets.QMessageBox.critical(
                    self,
                    "Error",
                    str(e) 
                )

            # now we can give the information message
            QtWidgets.QMessageBox.information(
                self,
                "Success",
                "User '{0}' successfully created!".format(self.user_login)
            )
            # then we can close this dialog
            self.close() 
Beispiel #26
0
    def test_reported_by_attribute_is_synonym_of_created_by(self):
        """testing if the reported_by attribute is a synonym for the created_by
        attribute
        """
        user1 = User(name='user1',
                     login='******',
                     password='******',
                     email='*****@*****.**')

        self.test_ticket.reported_by = user1
        self.assertEqual(user1, self.test_ticket.created_by)
Beispiel #27
0
    def test_user_attribute_is_working_properly(self):
        """testing if the user attribute is working properly
        """
        new_user = User(name='test user 2',
                        login='******',
                        email='*****@*****.**',
                        password='******')

        self.assertNotEqual(self.test_vacation.user, new_user)
        self.test_vacation.user = new_user
        self.assertEqual(self.test_vacation.user, new_user)
Beispiel #28
0
    def test_user_attribute_back_populates_vacations_attribute(self):
        """testing if the user attribute back populates vacations attribute of
        the User instance
        """
        new_user = User(name='test user 2',
                        login='******',
                        email='*****@*****.**',
                        password='******')

        self.test_vacation.user = new_user
        self.assertTrue(self.test_vacation in new_user.vacations)
Beispiel #29
0
    def test_reported_by_attribute_is_synonym_of_created_by(self):
        """testing if the reported_by attribute is a synonym for the created_by
        attribute
        """
        from stalker import User
        user1 = User(name='user1',
                     login='******',
                     password='******',
                     email='*****@*****.**')

        self.test_ticket.reported_by = user1
        assert user1 == self.test_ticket.created_by
    def test_user_attribute_is_working_properly(self):
        """testing if the user attribute is working properly
        """
        from stalker import User
        new_user = User(name='test user 2',
                        login='******',
                        email='*****@*****.**',
                        password='******')

        assert self.test_vacation.user != new_user
        self.test_vacation.user = new_user
        assert self.test_vacation.user == new_user
Beispiel #31
0
class UserTest(unittest2.TestCase):
    """Tests the user class
    """

    @classmethod
    def setUpClass(cls):
        """set up the test for class
        """
        DBSession.remove()

    @classmethod
    def tearDownClass(cls):
        """clean up the test
        """
        DBSession.remove()

    def setUp(self):
        """setup the test
        """
        # setup a test database
        self.TEST_DATABASE_URI = "sqlite:///:memory:"
        db.setup()
        db.init()

        # need to have some test object for
        # a department
        self.test_department1 = Department(name="Test Department 1")
        self.test_department2 = Department(name="Test Department 2")
        self.test_department3 = Department(name="Test Department 3")

        DBSession.add_all([self.test_department1, self.test_department2, self.test_department3])

        # a couple of groups
        self.test_group1 = Group(name="Test Group 1")
        self.test_group2 = Group(name="Test Group 2")
        self.test_group3 = Group(name="Test Group 3")

        DBSession.add_all([self.test_group1, self.test_group2, self.test_group3])

        # a couple of statuses
        self.test_status1 = Status(name="Completed", code="CMPLT")
        self.test_status2 = Status(name="Work In Progress", code="WIP")
        self.test_status3 = Status(name="Waiting To Start", code="WTS")
        self.test_status4 = Status(name="Pending Review", code="PRev")

        DBSession.add_all([self.test_status1, self.test_status2, self.test_status3, self.test_status4])

        # a project status list
        self.project_status_list = StatusList(
            name="Project Status List",
            statuses=[self.test_status1, self.test_status2, self.test_status3, self.test_status4],
            target_entity_type=Project,
        )

        # a repository type
        self.test_repository_type = Type(name="Test", code="test", target_entity_type=Repository)

        # a repository
        self.test_repository = Repository(name="Test Repository", type=self.test_repository_type)

        # a project type
        self.commercial_project_type = Type(name="Commercial Project", code="comm", target_entity_type=Project)

        # a couple of projects
        self.test_project1 = Project(
            name="Test Project 1",
            code="tp1",
            status_list=self.project_status_list,
            type=self.commercial_project_type,
            repository=self.test_repository,
        )

        self.test_project2 = Project(
            name="Test Project 2",
            code="tp2",
            status_list=self.project_status_list,
            type=self.commercial_project_type,
            repository=self.test_repository,
        )

        self.test_project3 = Project(
            name="Test Project 3",
            code="tp3",
            status_list=self.project_status_list,
            type=self.commercial_project_type,
            repository=self.test_repository,
        )

        DBSession.add_all([self.test_project1, self.test_project2, self.test_project3])

        # a task status list
        self.task_status_list = StatusList.query.filter_by(target_entity_type="Task").first()

        # a couple of tasks
        self.test_task1 = Task(name="Test Task 1", status_list=self.task_status_list, project=self.test_project1)

        self.test_task2 = Task(name="Test Task 2", status_list=self.task_status_list, project=self.test_project1)

        self.test_task3 = Task(name="Test Task 3", status_list=self.task_status_list, project=self.test_project2)

        self.test_task4 = Task(name="Test Task 4", status_list=self.task_status_list, project=self.test_project3)

        DBSession.add_all([self.test_task1, self.test_task2, self.test_task3, self.test_task4])

        # for task1
        self.test_version1 = Version(task=self.test_task1, full_path="some/path")
        DBSession.add(self.test_version1)

        self.test_version2 = Version(task=self.test_task1, full_path="some/path")
        DBSession.add(self.test_version2)

        self.test_version3 = Version(task=self.test_task1, full_path="some/path")
        DBSession.add(self.test_version3)

        # for task2
        self.test_version4 = Version(task=self.test_task2, full_path="some/path")
        DBSession.add(self.test_version4)

        self.test_version5 = Version(task=self.test_task2, full_path="some/path")
        DBSession.add(self.test_version5)

        self.test_version6 = Version(task=self.test_task2, full_path="some/path")
        DBSession.add(self.test_version6)

        # for task3
        self.test_version7 = Version(task=self.test_task3, full_path="some/path")
        DBSession.add(self.test_version7)

        self.test_version8 = Version(task=self.test_task3, full_path="some/path")
        DBSession.add(self.test_version8)

        self.test_version9 = Version(task=self.test_task3, full_path="some/path")
        DBSession.add(self.test_version9)

        # for task4
        self.test_version10 = Version(task=self.test_task4, full_path="some/path")
        DBSession.add(self.test_version10)

        self.test_version11 = Version(task=self.test_task4, full_path="some/path")
        DBSession.add(self.test_version11)

        self.test_version12 = Version(task=self.test_task4, full_path="some/path")
        DBSession.add(self.test_version12)

        # *********************************************************************
        # Tickets
        # *********************************************************************

        # no need to create status list for tickets cause we have a database
        # set up an running so it will be automatically linked

        # tickets for version1
        self.test_ticket1 = Ticket(project=self.test_project1, links=[self.test_version1])
        DBSession.add(self.test_ticket1)
        # set it to closed
        self.test_ticket1.resolve()

        # create a new ticket and leave it open
        self.test_ticket2 = Ticket(project=self.test_project1, links=[self.test_version1])
        DBSession.add(self.test_ticket2)

        # create a new ticket and close and then reopen it
        self.test_ticket3 = Ticket(project=self.test_project1, links=[self.test_version1])
        DBSession.add(self.test_ticket3)
        self.test_ticket3.resolve()
        self.test_ticket3.reopen()

        # *********************************************************************
        # tickets for version2
        # create a new ticket and leave it open
        self.test_ticket4 = Ticket(project=self.test_project1, links=[self.test_version2])
        DBSession.add(self.test_ticket4)

        # create a new Ticket and close it
        self.test_ticket5 = Ticket(project=self.test_project1, links=[self.test_version2])
        DBSession.add(self.test_ticket5)
        self.test_ticket5.resolve()

        # create a new Ticket and close it
        self.test_ticket6 = Ticket(project=self.test_project1, links=[self.test_version3])
        DBSession.add(self.test_ticket6)
        self.test_ticket6.resolve()

        # *********************************************************************
        # tickets for version3
        # create a new ticket and close it
        self.test_ticket7 = Ticket(project=self.test_project1, links=[self.test_version3])
        DBSession.add(self.test_ticket7)
        self.test_ticket7.resolve()

        # create a new ticket and close it
        self.test_ticket8 = Ticket(project=self.test_project1, links=[self.test_version3])
        DBSession.add(self.test_ticket8)
        self.test_ticket8.resolve()

        # *********************************************************************
        # tickets for version4
        # create a new ticket and close it
        self.test_ticket9 = Ticket(project=self.test_project1, links=[self.test_version4])
        DBSession.add(self.test_ticket9)

        self.test_ticket9.resolve()

        # no tickets for any other version
        # *********************************************************************

        # a status list for sequence
        self.sequence_status_list = StatusList.query.filter_by(target_entity_type="Sequence").first()

        # a couple of sequences
        self.test_sequence1 = Sequence(
            name="Test Seq 1", code="ts1", project=self.test_project1, status_list=self.sequence_status_list
        )

        self.test_sequence2 = Sequence(
            name="Test Seq 2", code="ts2", project=self.test_project1, status_list=self.sequence_status_list
        )

        self.test_sequence3 = Sequence(
            name="Test Seq 3", code="ts3", project=self.test_project1, status_list=self.sequence_status_list
        )

        self.test_sequence4 = Sequence(
            name="Test Seq 4", code="ts4", project=self.test_project1, status_list=self.sequence_status_list
        )

        DBSession.add_all([self.test_sequence1, self.test_sequence2, self.test_sequence3, self.test_sequence4])

        # a test admin
        # self.test_admin = User(
        #    name='Admin',
        #    login='******',
        #    email='*****@*****.**',
        #    password='******'
        # )
        self.test_admin = User.query.filter_by(name=defaults.admin_name).first()
        self.assertIsNotNone(self.test_admin)

        # create the default values for parameters
        self.kwargs = {
            "name": "Erkan Ozgur Yilmaz",
            "login": "******",
            "description": "this is a test user",
            "password": "******",
            "email": "*****@*****.**",
            "departments": [self.test_department1],
            "groups": [self.test_group1, self.test_group2],
            "created_by": self.test_admin,
            "updated_by": self.test_admin,
        }

        # create a proper user object
        self.test_user = User(**self.kwargs)
        DBSession.add(self.test_user)
        DBSession.commit()

        # just change the kwargs for other tests
        self.kwargs["name"] = "some other name"
        self.kwargs["email"] = "*****@*****.**"

    def tearDown(self):
        """tear down the test
        """
        DBSession.remove()

    def test___auto_name__class_attribute_is_set_to_False(self):
        """testing if the __auto_name__ class attribute is set to False for
        User class
        """
        self.assertFalse(User.__auto_name__)

    def test_email_argument_accepting_only_string_or_unicode(self):
        """testing if email argument accepting only string or unicode
        values
        """
        # try to create a new user with wrong attribute
        test_values = [1, 1.3, ["an email"], {"an": "email"}]

        for test_value in test_values:
            self.kwargs["email"] = test_value
            self.assertRaises(TypeError, User, **self.kwargs)

    def test_email_attribute_accepting_only_string_or_unicode(self):
        """testing if email attribute accepting only string or unicode
        values
        """
        # try to assign something else than a string or unicode
        test_value = 1

        self.assertRaises(TypeError, setattr, self.test_user, "email", test_value)

        test_value = ["an email"]

        self.assertRaises(TypeError, setattr, self.test_user, "email", test_value)

    def test_email_argument_format(self):
        """testing if given an email in wrong format will raise a ValueError
        """
        test_values = ["an email in no format", "an_email_with_no_part2", "@an_email_with_only_part2", "@"]

        # any of this values should raise a ValueError
        for test_value in test_values:
            self.kwargs["email"] = test_value
            self.assertRaises(ValueError, User, **self.kwargs)

    def test_email_attribute_format(self):
        """testing if given an email in wrong format will raise a ValueError 
        """
        test_values = [
            "an email in no format",
            "an_email_with_no_part2",
            "@an_email_with_only_part2",
            "@",
            "eoyilmaz@",
            "[email protected]@com",
        ]
        # any of these email values should raise a ValueError
        for value in test_values:
            self.assertRaises(ValueError, setattr, self.test_user, "email", value)

    def test_email_argument_should_be_a_unique_value(self):
        """testing if the email argument should be a unique value
        """
        # this test should include a database
        test_email = "*****@*****.**"
        self.kwargs["login"] = "******"
        self.kwargs["email"] = test_email
        user1 = User(**self.kwargs)
        DBSession.add(user1)
        DBSession.commit()

        self.kwargs["login"] = "******"
        user2 = User(**self.kwargs)
        DBSession.add(user2)

        self.assertRaises(Exception, DBSession.commit)

    def test_email_attribute_is_working_properly(self):
        """testing if email attribute works properly
        """
        test_email = "*****@*****.**"
        self.test_user.email = test_email
        self.assertEqual(self.test_user.email, test_email)

    def test_login_argument_conversion_to_strings(self):
        """testing if a ValueError will be raised when the given objects
        conversion to string results an empty string
        """
        test_values = ["----++==#@#$"]
        for test_value in test_values:
            self.kwargs["login"] = test_value
            self.assertRaises(ValueError, User, **self.kwargs)

    def test_login_argument_for_empty_string(self):
        """testing if a ValueError will be raised when trying to assign an
        empty string to login argument
        """
        self.kwargs["login"] = ""
        self.assertRaises(ValueError, User, **self.kwargs)

    def test_login_attribute_for_empty_string(self):
        """testing if a ValueError will be raised when trying to assign an
        empty string to login attribute
        """
        self.assertRaises(ValueError, setattr, self.test_user, "login", "")

    def test_login_argument_is_skipped(self):
        """testing if a TypeError will be raised when the login argument is
        skipped
        """
        self.kwargs.pop("login")
        self.assertRaises(TypeError, User, **self.kwargs)

    def test_login_argument_is_None(self):
        """testing if a TypeError will be raised when trying to assign None
        to login argument
        """
        self.kwargs["login"] = None
        self.assertRaises(TypeError, User, **self.kwargs)

    def test_login_attribute_is_None(self):
        """testing if a TypeError will be raised when trying to assign None
        to login attribute
        """
        self.assertRaises(TypeError, setattr, self.test_user, "login", None)

    def test_login_argument_formatted_correctly(self):
        """testing if login argument formatted correctly
        """
        #                 input       expected
        test_values = [
            ("e. ozgur", "eozgur"),
            ("erkan", "erkan"),
            ("Ozgur", "ozgur"),
            ("Erkan ozgur", "erkanozgur"),
            ("eRKAN", "erkan"),
            ("eRkaN", "erkan"),
            (" eRkAn", "erkan"),
            (" eRkan ozGur", "erkanozgur"),
            ("213 e.ozgur", "eozgur"),
        ]

        for valuePair in test_values:
            # set the input and expect the expected output
            self.kwargs["login"] = valuePair[0]
            test_user = User(**self.kwargs)
            self.assertEqual(test_user.login, valuePair[1])

    def test_login_attribute_formatted_correctly(self):
        """testing if login attribute formatted correctly
        """
        #                 input       expected
        test_values = [
            ("e. ozgur", "eozgur"),
            ("erkan", "erkan"),
            ("Ozgur", "ozgur"),
            ("Erkan ozgur", "erkanozgur"),
            ("eRKAN", "erkan"),
            ("eRkaN", "erkan"),
            (" eRkAn", "erkan"),
            (" eRkan ozGur", "erkanozgur"),
        ]

        for valuePair in test_values:
            # set the input and expect the expected output
            self.test_user.login = valuePair[0]

            self.assertEqual(self.test_user.login, valuePair[1])

    def test_login_argument_should_be_a_unique_value(self):
        """testing if the login argument should be a unique value
        """
        # this test should include a database
        test_login = "******"
        self.kwargs["login"] = test_login
        self.kwargs["email"] = "*****@*****.**"
        user1 = User(**self.kwargs)
        DBSession.add(user1)
        DBSession.commit()

        self.kwargs["email"] = "*****@*****.**"

        user2 = User(**self.kwargs)
        DBSession.add(user2)

        self.assertRaises(Exception, DBSession.commit)

    def test_login_argument_is_working_properly(self):
        """testing if the login argument is working properly
        """
        self.assertEqual(self.test_user.login, self.kwargs["login"])

    def test_login_attribute_is_working_properly(self):
        """testing if the login attribute is working properly
        """
        test_value = "newlogin"
        self.test_user.login = test_value
        self.assertEqual(self.test_user.login, test_value)

    def test_last_login_attribute_None(self):
        """testing if nothing happens when the last login attribute is set to
        None
        """
        # nothing should happen
        self.test_user.last_login = None

    def test_last_login_attribute_accepts_only_datetime_instance_or_None(self):
        """testing if a TypeError will be raised for values other than
        datetime.datetime instances tried to be assigned to last_login
        attribute
        """
        test_values = [1, 2.3, "login time", ["last login time"], {"a last": "login time"}]
        for test_value in test_values:
            self.assertRaises(TypeError, setattr, self.test_user, "last_login", test_value)

    def test_last_login_attribute_works_properly(self):
        """testing if the last_login attribute works properly
        """
        test_value = datetime.datetime.now()
        self.test_user.last_login = test_value
        self.assertEqual(self.test_user.last_login, test_value)

    def test_departments_argument_is_skipped(self):
        """testing if a User can be created without a Department instance
        """
        try:
            self.kwargs.pop("departments")
        except KeyError:
            pass

        new_user = User(**self.kwargs)
        self.assertEqual(new_user.departments, [])

    def test_departments_argument_is_None(self):
        """testing if a User can be created with the departments argument value
        is to None
        """
        self.kwargs["departments"] = None
        new_user = User(**self.kwargs)
        self.assertEqual(new_user.departments, [])

    def test_departments_attribute_is_set_None(self):
        """testing if a TypeError will be raised when the User's departments
        attribute set to None
        """
        self.assertRaises(TypeError, setattr, self.test_user, "departments", None)

    def test_departments_argument_is_an_empty_list(self):
        """testing if a User can be created with the departments argument is an
        empty list
        """
        self.kwargs["departments"] = []
        new_user = User(**self.kwargs)

    def test_departments_attribute_is_an_empty_list(self):
        """testing if the departments attribute can be set to an empty list
        """
        self.test_user.departments = []
        self.assertEqual(self.test_user.departments, [])

    def test_departments_argument_only_accepts_list_of_department_objects(self):
        """testing if a TypeError will be raised when trying to assign
        anything other than a Department object to departments argument
        """
        # try to assign something other than a department object
        test_values = ["A department", 1, 1.0, ["a department"], {"a": "deparment"}]

        self.kwargs["departments"] = test_values
        self.assertRaises(TypeError, User, **self.kwargs)

    def test_departments_attribute_only_accepts_department_objects(self):
        """testing if a TypeError will be raised when trying to assign
        anything other than a Department object to departments attribute
        """
        # try to assign something other than a department
        test_value = "a department"
        self.assertRaises(TypeError, setattr, self.test_user, "departments", test_value)

    def test_departments_attribute_works_properly(self):
        """testing if departments attribute works properly
        """
        # try to set and get the same value back
        self.test_user.departments = [self.test_department2]
        self.assertItemsEqual(self.test_user.departments, [self.test_department2])

    def test_departments_attribute_supports_appending(self):
        """testing if departments attribute supports appending
        """
        self.test_user.departments = []
        self.test_user.departments.append(self.test_department1)
        self.test_user.departments.append(self.test_department2)
        self.assertItemsEqual(self.test_user.departments, [self.test_department1, self.test_department2])

    def test_password_argument_being_None(self):
        """testing if a TypeError will be raised when trying to assign None
        to the password argument
        """
        self.kwargs["password"] = None
        self.assertRaises(TypeError, User, **self.kwargs)

    def test_password_attribute_being_None(self):
        """testing if a TypeError will be raised when tyring to assign None to
        the password attribute
        """
        self.assertRaises(TypeError, setattr, self.test_user, "password", None)

    def test_password_attribute_works_properly(self):
        """testing if password attribute works properly
        """
        test_password = "******"
        self.test_user.password = test_password
        self.assertNotEquals(self.test_user.password, test_password)

    def test_password_argument_being_scrambled(self):
        """testing if password is scrambled when trying to store it
        """
        test_password = "******"
        self.kwargs["password"] = test_password
        aNew_user = User(**self.kwargs)
        self.assertNotEquals(aNew_user.password, test_password)

    def test_password_attribute_being_scrambled(self):
        """testing if password is scrambled when trying to store it
        """
        test_password = "******"
        self.test_user.password = test_password

        # test if they are not the same any more
        self.assertNotEquals(self.test_user.password, test_password)

    def test_check_password_works_properly(self):
        """testing if check_password method works properly
        """
        test_password = "******"
        self.test_user.password = test_password

        # check if it is scrambled
        self.assertNotEquals(self.test_user.password, test_password)

        # check if check_password returns True
        self.assertTrue(self.test_user.check_password(test_password))

        # check if check_password returns False
        self.assertFalse(self.test_user.check_password("wrong pass"))

    def test_groups_argument_for_None(self):
        """testing if the groups attribute will be an empty list
        when the groups argument is None
        """
        self.kwargs["groups"] = None
        new_user = User(**self.kwargs)
        self.assertEqual(new_user.groups, [])

    def test_groups_attribute_for_None(self):
        """testing if a TypeError will be raised when groups attribute is set
        to None
        """
        self.assertRaises(TypeError, setattr, self.test_user, "groups", None)

    def test_groups_argument_accepts_only_Group_instances(self):
        """testing if a TypeError will be raised when trying to assign anything
        other then a Group instances to the group argument
        """
        test_values = [23123, 1231.43122, "a_group", ["group1", "group2", 234]]

        for test_value in test_values:
            self.kwargs["groups"] = test_value
            self.assertRaises(TypeError, User, **self.kwargs)

    def test_groups_attribute_accepts_only_Group_instances(self):
        """testing if a TypeError will be raised when trying to assign anything
        other then a Group instances to the group attribute
        """
        test_values = [23123, 1231.43122, "a_group", ["group1", "group2", 234]]

        for test_value in test_values:
            self.assertRaises(TypeError, setattr, self.test_user, "groups", test_value)

    def test_groups_attribute_works_properly(self):
        """testing if groups attribute works properly
        """
        test_pg = [self.test_group3]
        self.test_user.groups = test_pg
        self.assertEqual(self.test_user.groups, test_pg)

    def test_groups_attribute_elements_accepts_Group_only(self):
        """testing if a TypeError will be raised when trying to assign
        something other than a Group instances to the groups list
        """
        # append
        self.assertRaises(TypeError, self.test_user.groups.append, 0)

        # __setitem__
        self.assertRaises(TypeError, self.test_user.groups.__setitem__, 0, 0)

    def test_projects_attribute_is_None(self):
        """testing if a TypeError will be raised when the projects attribute is
        set to None
        """
        self.assertRaises(TypeError, setattr, self.test_user, "projects", None)

    def test_projects_attribute_is_set_to_a_value_which_is_not_a_list(self):
        """testing if the projects attribute is accepting lists only
        """
        self.assertRaises(TypeError, setattr, self.test_user, "projects", "not a list")

    def test_projects_attribute_is_set_to_list_of_other_objects_than_Project_instances(self):
        """testing if a TypeError will be raised when the projects attribute is
        set to a value which is a list of other values than Projects instances
        """
        self.assertRaises(TypeError, setattr, self.test_user, "projects", ["not", "a", "list", "of", "projects", 32])

    def test_projects_attribute_is_working_properly(self):
        """testing if the projects attribute is working properly
        """
        test_list = [self.test_project1, self.test_project2]
        self.test_user.projects = test_list
        self.assertItemsEqual(test_list, self.test_user.projects)
        self.test_user.projects.append(self.test_project3)
        self.assertIn(self.test_project3, self.test_user.projects)
        # also check the backref
        self.assertIn(self.test_user, self.test_project1.users)
        self.assertIn(self.test_user, self.test_project2.users)
        self.assertIn(self.test_user, self.test_project3.users)

    def test_projects_lead_attribute_None(self):
        """testing if a TypeError will be raised when the project_lead
        attribute is set to None
        """
        self.assertRaises(TypeError, setattr, self.test_user, "projects_lead", None)

    def test_projects_lead_attribute_accepts_empty_list(self):
        """testing if projects_lead attribute accepts an empty list
        """

        # this should work without any problem
        self.test_user.projects_lead = []

    def test_projects_lead_attribute_accepts_only_lists(self):
        """testing if a TypeError will be raised when trying to assign a list
        of other objects than a list of Project objects to the
        projects_lead attribute
        """
        test_values = ["a project", 123123, {}, 12.2132]
        for test_value in test_values:
            self.assertRaises(TypeError, setattr, self.test_user, "projects_lead", test_value)

    def test_projects_lead_attribute_accepts_only_list_of_project_obj(self):
        """testing if a TypeError will be raised when trying to assign a list
        of other object than a list of Project objects to the
        projects_lead attribute
        """
        test_value = ["a project", 123123, [], {}, 12.2132]
        self.assertRaises(TypeError, setattr, self.test_user, "projects_lead", test_value)

    def test_projects_lead_attribute_working_properly(self):
        """testing if the projects_lead attribute is working properly
        """
        projects_lead = [self.test_project1, self.test_project2, self.test_project3]
        self.test_user.projects_lead = projects_lead
        self.assertEqual(self.test_user.projects_lead, projects_lead)

    def test_projects_lead_attribute_elements_accepts_Project_only(self):
        """testing if a TypeError will be raised when trying to assign
        something other than a Project object to the projects_lead list
        """
        # append
        self.assertRaises(TypeError, self.test_user.projects_lead.append, 0)

    def test_tasks_attribute_None(self):
        """testing if a TypeError will be raised when the tasks attribute is
        set to None
        """
        self.assertRaises(TypeError, setattr, self.test_user, "tasks", None)

    def test_tasks_attribute_accepts_only_list_of_task_objects(self):
        """testing if a TypeError will be raised when trying to assign
        anything other than a list of task objects to the tasks argument
        """
        test_values = [12312, 1233244.2341, ["aTask1", "aTask2"], "a_task"]

        for test_value in test_values:
            self.assertRaises(TypeError, setattr, self.test_user, "tasks", test_value)

    def test_tasks_attribute_accepts_an_empty_list(self):
        """testing if nothing happens when trying to assign an empty list to
        tasks attribute
        """
        # this should work without any error
        self.test_user.tasks = []

    def test_tasks_attribute_works_properly(self):
        """testing if tasks attribute is working properly
        """
        tasks = [self.test_task1, self.test_task2, self.test_task3, self.test_task4]

        self.test_user.tasks = tasks

        self.assertEqual(self.test_user.tasks, tasks)

    def test_tasks_attribute_elements_accepts_Tasks_only(self):
        """testing if a TypeError will be raised when trying to assign
        something other than a Task object to the tasks list
        """
        # append
        self.assertRaises(TypeError, self.test_user.tasks.append, 0)

    def test_equality_operator(self):
        """testing equality of two users
        """
        self.kwargs.update(
            {
                "name": "Generic User",
                "description": "this is a different user",
                "login": "******",
                "email": "*****@*****.**",
                "password": "******",
            }
        )

        new_user = User(**self.kwargs)

        self.assertFalse(self.test_user == new_user)

    def test_inequality_operator(self):
        """testing inequality of two users
        """
        self.kwargs.update(
            {
                "name": "Generic User",
                "description": "this is a different user",
                "login": "******",
                "email": "*****@*****.**",
                "password": "******",
            }
        )

        new_user = User(**self.kwargs)

        self.assertTrue(self.test_user != new_user)

    def test___repr__(self):
        """testing the representation
        """
        self.assertEqual(self.test_user.__repr__(), "<%s ('%s') (User)>" % (self.test_user.name, self.test_user.login))

    def test_tickets_attribute_is_an_empty_list_by_default(self):
        """testing if the User.tickets is an empty list by default
        """
        self.assertEqual(self.test_user.tickets, [])

    def test_open_tickets_attribute_is_an_empty_list_by_default(self):
        """testing if the User.open_tickets is an empty list by default
        """
        self.assertEqual(self.test_user.open_tickets, [])

    def test_tickets_attribute_is_read_only(self):
        """testing if the User.tickets attribute is a read only attribute
        """
        self.assertRaises(AttributeError, setattr, self.test_user, "tickets", [])

    def test_open_tickets_attribute_is_read_only(self):
        """testing if the User.open_tickets attribute is a read only attribute
        """
        self.assertRaises(AttributeError, setattr, self.test_user, "open_tickets", [])

    def test_tickets_attribute_returns_all_tickets_owned_by_this_user(self):
        """testing if User.tickets returns all the tickets owned by this user
        """
        self.assertEqual(len(self.test_user.tasks), 0)

        # there should be no tickets assigned to this user
        self.assertTrue(self.test_user.tickets == [])

        # be careful not all of these are open tickets
        self.test_ticket1.reassign(self.test_user, self.test_user)
        self.test_ticket2.reassign(self.test_user, self.test_user)
        self.test_ticket3.reassign(self.test_user, self.test_user)
        self.test_ticket4.reassign(self.test_user, self.test_user)
        self.test_ticket5.reassign(self.test_user, self.test_user)
        self.test_ticket6.reassign(self.test_user, self.test_user)
        self.test_ticket7.reassign(self.test_user, self.test_user)
        self.test_ticket8.reassign(self.test_user, self.test_user)

        # now we should have some tickets
        self.assertTrue(len(self.test_user.tickets) > 0)

        # now check for exact items
        self.assertItemsEqual(self.test_user.tickets, [self.test_ticket2, self.test_ticket3, self.test_ticket4])

    def test_open_tickets_attribute_returns_all_open_tickets_owned_by_this_user(self):
        """testing if User.open_tickets returns all the open tickets owned by
        this user
        """
        self.assertEqual(len(self.test_user.tasks), 0)

        # there should be no tickets assigned to this user
        self.assertTrue(self.test_user.open_tickets == [])

        # assign the user to some tickets
        self.test_ticket1.reopen(self.test_user)
        self.test_ticket2.reopen(self.test_user)
        self.test_ticket3.reopen(self.test_user)
        self.test_ticket4.reopen(self.test_user)
        self.test_ticket5.reopen(self.test_user)
        self.test_ticket6.reopen(self.test_user)
        self.test_ticket7.reopen(self.test_user)
        self.test_ticket8.reopen(self.test_user)

        # be careful not all of these are open tickets
        self.test_ticket1.reassign(self.test_user, self.test_user)
        self.test_ticket2.reassign(self.test_user, self.test_user)
        self.test_ticket3.reassign(self.test_user, self.test_user)
        self.test_ticket4.reassign(self.test_user, self.test_user)
        self.test_ticket5.reassign(self.test_user, self.test_user)
        self.test_ticket6.reassign(self.test_user, self.test_user)
        self.test_ticket7.reassign(self.test_user, self.test_user)
        self.test_ticket8.reassign(self.test_user, self.test_user)

        # now we should have some open tickets
        self.assertTrue(len(self.test_user.open_tickets) > 0)

        # now check for exact items
        self.assertItemsEqual(
            self.test_user.open_tickets,
            [
                self.test_ticket1,
                self.test_ticket2,
                self.test_ticket3,
                self.test_ticket4,
                self.test_ticket5,
                self.test_ticket6,
                self.test_ticket7,
                self.test_ticket8,
            ],
        )

        # close a couple of them
        from stalker.models.ticket import FIXED, CANTFIX, WONTFIX, DUPLICATE, WORKSFORME, INVALID

        self.test_ticket1.resolve(self.test_user, FIXED)
        self.test_ticket2.resolve(self.test_user, INVALID)
        self.test_ticket3.resolve(self.test_user, CANTFIX)

        # new check again
        self.assertItemsEqual(
            self.test_user.open_tickets,
            [self.test_ticket4, self.test_ticket5, self.test_ticket6, self.test_ticket7, self.test_ticket8],
        )

    def test_tjp_id_is_working_properly(self):
        """testing if the tjp_id is working properly
        """
        self.assertEqual(self.test_user.tjp_id, "User_%s" % self.test_user.id)

    def test_to_tjp_is_working_properly(self):
        """testing if the to_tjp property is working properly
        """
        expected_tjp = 'resource User_82 "Erkan Ozgur Yilmaz"'
        self.assertEqual(expected_tjp, self.test_user.to_tjp)

    def test_to_tjp_is_working_properly_for_a_user_with_vacations(self):
        """testing if the to_tjp property is working properly for a user with
        vacations
        """
        personal_vacation = Type(name="Personal", code="PERS", target_entity_type="Vacation")

        vac1 = Vacation(
            user=self.test_user,
            type=personal_vacation,
            start=datetime.datetime(2013, 6, 7, 0, 0),
            end=datetime.datetime(2013, 6, 21, 0, 0),
        )

        vac2 = Vacation(
            user=self.test_user,
            type=personal_vacation,
            start=datetime.datetime(2013, 7, 1, 0, 0),
            end=datetime.datetime(2013, 7, 15, 0, 0),
        )

        expected_tjp = """resource User_82 "Erkan Ozgur Yilmaz" {
            vacation 2013-06-07-00:00:00 - 2013-06-21-00:00:00
            vacation 2013-07-01-00:00:00 - 2013-07-15-00:00:00
            }"""
        # print expected_tjp
        # print '---------------'
        # print self.test_user.to_tjp
        self.assertEqual(expected_tjp, self.test_user.to_tjp)

    def test_vacations_attribute_is_set_to_None(self):
        """testing if a TypeError will be raised when the vacations attribute
        is set to None
        """
        self.assertRaises(TypeError, setattr, self.test_user, "vacations", None)

    def test_vacations_attribute_is_not_a_list(self):
        """testing if a TypeError will be raised when the vacations attribute
        is set to a value other than a list
        """
        self.assertRaises(TypeError, setattr, self.test_user, "vacations", "not a list of Vacation instances")

    def test_vacations_attribute_is_not_a_list_of_Vacation_instances(self):
        """testing if a TypeError will be raised when the vacations attribute
        is set to a list of other objects than Vacation instances
        """
        self.assertRaises(TypeError, setattr, self.test_user, "vacations", ["list of", "other", "instances", 1])

    def test_vacations_attribute_is_working_properly(self):
        """testing if the vacations attribute is working properly
        """
        some_other_user = User(name="Some Other User", login="******", email="*****@*****.**", password="******")

        personal_vac_type = Type(name="Personal Vacation", code="PERS", target_entity_type="Vacation")

        vac1 = Vacation(
            user=some_other_user,
            type=personal_vac_type,
            start=datetime.datetime(2013, 6, 7),
            end=datetime.datetime(2013, 6, 10),
        )

        self.assertNotIn(vac1, self.test_user.vacations)

        self.test_user.vacations.append(vac1)

        self.assertIn(vac1, self.test_user.vacations)
Beispiel #32
0
    def setUp(self):
        """setup the test
        """
        # setup a test database
        self.TEST_DATABASE_URI = "sqlite:///:memory:"
        db.setup()
        db.init()

        # need to have some test object for
        # a department
        self.test_department1 = Department(name="Test Department 1")
        self.test_department2 = Department(name="Test Department 2")
        self.test_department3 = Department(name="Test Department 3")

        DBSession.add_all([self.test_department1, self.test_department2, self.test_department3])

        # a couple of groups
        self.test_group1 = Group(name="Test Group 1")
        self.test_group2 = Group(name="Test Group 2")
        self.test_group3 = Group(name="Test Group 3")

        DBSession.add_all([self.test_group1, self.test_group2, self.test_group3])

        # a couple of statuses
        self.test_status1 = Status(name="Completed", code="CMPLT")
        self.test_status2 = Status(name="Work In Progress", code="WIP")
        self.test_status3 = Status(name="Waiting To Start", code="WTS")
        self.test_status4 = Status(name="Pending Review", code="PRev")

        DBSession.add_all([self.test_status1, self.test_status2, self.test_status3, self.test_status4])

        # a project status list
        self.project_status_list = StatusList(
            name="Project Status List",
            statuses=[self.test_status1, self.test_status2, self.test_status3, self.test_status4],
            target_entity_type=Project,
        )

        # a repository type
        self.test_repository_type = Type(name="Test", code="test", target_entity_type=Repository)

        # a repository
        self.test_repository = Repository(name="Test Repository", type=self.test_repository_type)

        # a project type
        self.commercial_project_type = Type(name="Commercial Project", code="comm", target_entity_type=Project)

        # a couple of projects
        self.test_project1 = Project(
            name="Test Project 1",
            code="tp1",
            status_list=self.project_status_list,
            type=self.commercial_project_type,
            repository=self.test_repository,
        )

        self.test_project2 = Project(
            name="Test Project 2",
            code="tp2",
            status_list=self.project_status_list,
            type=self.commercial_project_type,
            repository=self.test_repository,
        )

        self.test_project3 = Project(
            name="Test Project 3",
            code="tp3",
            status_list=self.project_status_list,
            type=self.commercial_project_type,
            repository=self.test_repository,
        )

        DBSession.add_all([self.test_project1, self.test_project2, self.test_project3])

        # a task status list
        self.task_status_list = StatusList.query.filter_by(target_entity_type="Task").first()

        # a couple of tasks
        self.test_task1 = Task(name="Test Task 1", status_list=self.task_status_list, project=self.test_project1)

        self.test_task2 = Task(name="Test Task 2", status_list=self.task_status_list, project=self.test_project1)

        self.test_task3 = Task(name="Test Task 3", status_list=self.task_status_list, project=self.test_project2)

        self.test_task4 = Task(name="Test Task 4", status_list=self.task_status_list, project=self.test_project3)

        DBSession.add_all([self.test_task1, self.test_task2, self.test_task3, self.test_task4])

        # for task1
        self.test_version1 = Version(task=self.test_task1, full_path="some/path")
        DBSession.add(self.test_version1)

        self.test_version2 = Version(task=self.test_task1, full_path="some/path")
        DBSession.add(self.test_version2)

        self.test_version3 = Version(task=self.test_task1, full_path="some/path")
        DBSession.add(self.test_version3)

        # for task2
        self.test_version4 = Version(task=self.test_task2, full_path="some/path")
        DBSession.add(self.test_version4)

        self.test_version5 = Version(task=self.test_task2, full_path="some/path")
        DBSession.add(self.test_version5)

        self.test_version6 = Version(task=self.test_task2, full_path="some/path")
        DBSession.add(self.test_version6)

        # for task3
        self.test_version7 = Version(task=self.test_task3, full_path="some/path")
        DBSession.add(self.test_version7)

        self.test_version8 = Version(task=self.test_task3, full_path="some/path")
        DBSession.add(self.test_version8)

        self.test_version9 = Version(task=self.test_task3, full_path="some/path")
        DBSession.add(self.test_version9)

        # for task4
        self.test_version10 = Version(task=self.test_task4, full_path="some/path")
        DBSession.add(self.test_version10)

        self.test_version11 = Version(task=self.test_task4, full_path="some/path")
        DBSession.add(self.test_version11)

        self.test_version12 = Version(task=self.test_task4, full_path="some/path")
        DBSession.add(self.test_version12)

        # *********************************************************************
        # Tickets
        # *********************************************************************

        # no need to create status list for tickets cause we have a database
        # set up an running so it will be automatically linked

        # tickets for version1
        self.test_ticket1 = Ticket(project=self.test_project1, links=[self.test_version1])
        DBSession.add(self.test_ticket1)
        # set it to closed
        self.test_ticket1.resolve()

        # create a new ticket and leave it open
        self.test_ticket2 = Ticket(project=self.test_project1, links=[self.test_version1])
        DBSession.add(self.test_ticket2)

        # create a new ticket and close and then reopen it
        self.test_ticket3 = Ticket(project=self.test_project1, links=[self.test_version1])
        DBSession.add(self.test_ticket3)
        self.test_ticket3.resolve()
        self.test_ticket3.reopen()

        # *********************************************************************
        # tickets for version2
        # create a new ticket and leave it open
        self.test_ticket4 = Ticket(project=self.test_project1, links=[self.test_version2])
        DBSession.add(self.test_ticket4)

        # create a new Ticket and close it
        self.test_ticket5 = Ticket(project=self.test_project1, links=[self.test_version2])
        DBSession.add(self.test_ticket5)
        self.test_ticket5.resolve()

        # create a new Ticket and close it
        self.test_ticket6 = Ticket(project=self.test_project1, links=[self.test_version3])
        DBSession.add(self.test_ticket6)
        self.test_ticket6.resolve()

        # *********************************************************************
        # tickets for version3
        # create a new ticket and close it
        self.test_ticket7 = Ticket(project=self.test_project1, links=[self.test_version3])
        DBSession.add(self.test_ticket7)
        self.test_ticket7.resolve()

        # create a new ticket and close it
        self.test_ticket8 = Ticket(project=self.test_project1, links=[self.test_version3])
        DBSession.add(self.test_ticket8)
        self.test_ticket8.resolve()

        # *********************************************************************
        # tickets for version4
        # create a new ticket and close it
        self.test_ticket9 = Ticket(project=self.test_project1, links=[self.test_version4])
        DBSession.add(self.test_ticket9)

        self.test_ticket9.resolve()

        # no tickets for any other version
        # *********************************************************************

        # a status list for sequence
        self.sequence_status_list = StatusList.query.filter_by(target_entity_type="Sequence").first()

        # a couple of sequences
        self.test_sequence1 = Sequence(
            name="Test Seq 1", code="ts1", project=self.test_project1, status_list=self.sequence_status_list
        )

        self.test_sequence2 = Sequence(
            name="Test Seq 2", code="ts2", project=self.test_project1, status_list=self.sequence_status_list
        )

        self.test_sequence3 = Sequence(
            name="Test Seq 3", code="ts3", project=self.test_project1, status_list=self.sequence_status_list
        )

        self.test_sequence4 = Sequence(
            name="Test Seq 4", code="ts4", project=self.test_project1, status_list=self.sequence_status_list
        )

        DBSession.add_all([self.test_sequence1, self.test_sequence2, self.test_sequence3, self.test_sequence4])

        # a test admin
        # self.test_admin = User(
        #    name='Admin',
        #    login='******',
        #    email='*****@*****.**',
        #    password='******'
        # )
        self.test_admin = User.query.filter_by(name=defaults.admin_name).first()
        self.assertIsNotNone(self.test_admin)

        # create the default values for parameters
        self.kwargs = {
            "name": "Erkan Ozgur Yilmaz",
            "login": "******",
            "description": "this is a test user",
            "password": "******",
            "email": "*****@*****.**",
            "departments": [self.test_department1],
            "groups": [self.test_group1, self.test_group2],
            "created_by": self.test_admin,
            "updated_by": self.test_admin,
        }

        # create a proper user object
        self.test_user = User(**self.kwargs)
        DBSession.add(self.test_user)
        DBSession.commit()

        # just change the kwargs for other tests
        self.kwargs["name"] = "some other name"
        self.kwargs["email"] = "*****@*****.**"