Beispiel #1
0
 def test_hash_is_correctly_calculated(self):
     """testing if the hash value is correctly calculated
     """
     client1 = Client(**self.kwargs)
     assert client1.__hash__() == \
         hash(client1.id) + \
         2 * hash(client1.name) + \
         3 * hash(client1.entity_type)
Beispiel #2
0
    def test_goods_attribute_is_set_to_none(self):
        """testing if a TypeError will be raised
        """
        client1 = Client(**self.kwargs)
        with pytest.raises(TypeError) as cm:
            client1.goods = None

        assert str(cm.value) == \
            'Incompatible collection type: None is not list-like'
Beispiel #3
0
    def test_goods_attribute_is_working_properly(self):
        """testing if the goods attribute is working properly
        """
        client1 = Client(**self.kwargs)
        from stalker.models.budget import Good
        good1 = Good(name='Test Good 1')
        good2 = Good(name='Test Good 2')
        good3 = Good(name='Test Good 3')
        client1.goods = [good1, good2, good3]

        assert client1.goods == [good1, good2, good3]
Beispiel #4
0
    def test_goods_attribute_is_set_to_a_list_of_non_good_instances(self):
        """testing if a TypeError will be raised if the goods attribute is set
        to a list of non Good instances.
        """
        client1 = Client(**self.kwargs)
        with pytest.raises(TypeError) as cm:
            client1.goods = ['not', 1, 'list', 'of', 'goods']

        assert str(cm.value) == \
            'Client.goods attribute should be all ' \
            'stalker.models.budget.Good instances, not str'
Beispiel #5
0
 def test_projects_argument_accepts_an_empty_list(self):
     """testing if projects argument accepts an empty list
     """
     # this should work without raising any error
     self.kwargs["projects"] = []
     new_dep = Client(**self.kwargs)
     assert isinstance(new_dep, Client)
Beispiel #6
0
 def test_projects_attribute_defaults_to_empty_list(self):
     """testing if the projects attribute defaults to an empty list if the
      projects argument is skipped
     """
     self.kwargs.pop("projects")
     new_client = Client(**self.kwargs)
     assert new_client.projects == []
    def setUp(self):
        """set the test up
        """
        super(ProjectClientTestCase, self).setUp()

        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 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],
                                    status_list=self.project_statuses)

        from stalker import Role
        self.test_role = Role(name='Test Client')
Beispiel #8
0
 def test_users_attribute_defaults_to_empty_list(self):
     """testing if the users attribute defaults to an empty list if the
      users argument is skipped
     """
     self.kwargs.pop("users")
     new_client = Client(**self.kwargs)
     self.assertEqual(new_client.users, [])
Beispiel #9
0
 def test_users_argument_accepts_an_empty_list(self):
     """testing if users argument accepts an empty list
     """
     # this should work without raising any error
     self.kwargs["users"] = []
     new_dep = Client(**self.kwargs)
     self.assertTrue(isinstance(new_dep, Client))
Beispiel #10
0
    def test_inequality(self):
        """testing inequality of two Client objects
        """
        dep1 = Client(**self.kwargs)
        dep2 = Client(**self.kwargs)

        entity_kwargs = self.kwargs.copy()
        entity_kwargs.pop("users")
        entity_kwargs.pop("projects")
        entity1 = Entity(**entity_kwargs)

        self.kwargs["name"] = "Company X"
        dep3 = Client(**self.kwargs)

        self.assertFalse(dep1 != dep2)
        self.assertTrue(dep1 != dep3)
        self.assertTrue(dep1 != entity1)
Beispiel #11
0
    def test_inequality(self):
        """testing inequality of two Client objects
        """
        client1 = Client(**self.kwargs)
        client2 = Client(**self.kwargs)

        entity_kwargs = self.kwargs.copy()
        entity_kwargs.pop("users")
        entity_kwargs.pop("projects")
        from stalker import Entity
        entity1 = Entity(**entity_kwargs)

        self.kwargs["name"] = "Company X"
        client3 = Client(**self.kwargs)

        assert not client1 != client2
        assert client1 != client3
        assert client1 != entity1
Beispiel #12
0
    def test_projects_argument_is_not_iterable(self):
        """testing if a TypeError will be raised when the given projects
        argument is not an instance of list
        """
        self.kwargs["projects"] = "a project"
        with pytest.raises(TypeError) as cm:
            Client(**self.kwargs)

        assert str(cm.value) == \
            'ProjectClient.project should be a ' \
            'stalker.models.project.Project instance, not str'
Beispiel #13
0
    def test_users_argument_is_not_iterable(self):
        """testing if a TypeError will be raised when the given users
        argument is not an instance of list
        """
        self.kwargs["users"] = "a user"
        with pytest.raises(TypeError) as cm:
            Client(**self.kwargs)

        assert str(cm.value) == \
            'ClientUser.user should be an instance of ' \
            'stalker.models.auth.User, not str'
Beispiel #14
0
    def test_users_argument_is_not_iterable(self):
        """testing if a TypeError will be raised when the given users
        argument is not an instance of list
        """
        self.kwargs["users"] = "a user"
        with self.assertRaises(TypeError) as cm:
            Client(**self.kwargs)

        self.assertEqual(
            str(cm.exception), 'ClientUser.user should be an instance of '
            'stalker.models.auth.User, not str')
Beispiel #15
0
    def test_users_argument_accepts_only_a_list_of_user_objects(self):
        """testing if users argument accepts only a list of user objects
        """
        test_value = [1, 2.3, [], {}]
        self.kwargs["users"] = test_value
        # this should raise a TypeError
        with pytest.raises(TypeError) as cm:
            Client(**self.kwargs)

        assert str(cm.value) == \
            'ClientUser.user should be an instance of ' \
            'stalker.models.auth.User, not int'
Beispiel #16
0
    def test_projects_argument_accepts_only_a_list_of_project_objects(self):
        """testing if projects argument accepts only a list of project objects
        """
        test_value = [1, 2.3, [], {}]
        self.kwargs["projects"] = test_value
        # this should raise a TypeError
        with pytest.raises(TypeError) as cm:
            Client(**self.kwargs)

        assert str(cm.value) == \
            'ProjectClient.project should be a ' \
            'stalker.models.project.Project instance, not int'
Beispiel #17
0
 def test_client_attribute_is_working_properly(self):
     """testing if the client attribute value an be changed properly
     """
     from stalker import Invoice
     test_invoice = Invoice(budget=self.test_budget,
                            client=self.test_client,
                            amount=100,
                            unit='TRY')
     from stalker import Client
     test_client = Client(name='Test Client 2')
     self.assertNotEqual(test_invoice.client, test_client)
     test_invoice.client = test_client
     self.assertEqual(test_invoice.client, test_client)
Beispiel #18
0
    def test_projects_argument_accepts_only_a_list_of_project_objects(self):
        """testing if projects argument accepts only a list of project objects
        """
        test_value = [1, 2.3, [], {}]
        self.kwargs["projects"] = test_value
        # this should raise a TypeError
        with self.assertRaises(TypeError) as cm:
            Client(**self.kwargs)

        self.assertEqual(
            str(cm.exception),
            'ProjectClient.project should be a stalker.models.project.Project '
            'instance, not int')
Beispiel #19
0
def test_role_argument_is_not_a_role_instance():
    """testing if a TypeError will be raised when the role argument is not
    a Role instance
    """
    from stalker import Client, User

    with pytest.raises(TypeError) as cm:
        ClientUser(client=Client(name='Test Client'),
                   user=User(name='Test User',
                             login='******',
                             email='*****@*****.**',
                             password='******'),
                   role='not a role instance')

    assert str(cm.value) == \
        'ClientUser.role should be a stalker.models.auth.Role instance, ' \
        'not str'
Beispiel #20
0
def create_client(request):
    """called when adding a new client
    """
    logged_in_user = get_logged_in_user(request)
    utc_now = local_to_utc(datetime.datetime.now())

    came_from = request.params.get('came_from', '/')

    # parameters
    name = request.params.get('name')
    description = request.params.get('description')

    logger.debug('create_client          :')

    logger.debug('name          : %s' % name)
    logger.debug('description   : %s' % description)

    if name and description:

        try:
            new_client = Client(name=name,
                                description=description,
                                created_by=logged_in_user,
                                date_created=utc_now,
                                date_updated=utc_now)

            DBSession.add(new_client)
            # flash success message
            request.session.flash(
                'success:Client <strong>%s</strong> is created '
                'successfully' % name)
        except BaseException as e:
            request.session.flash('error: %s' % e)
            HTTPFound(location=came_from)

    else:
        transaction.abort()
        return Response('There are missing parameters', 500)

    return Response(
        'success:Client with name <strong>%s</strong> is created.' % name)
Beispiel #21
0
    def test_role_argument_is_not_a_role_instance(self):
        """testing if a TypeError will be raised when the role argument is not
        a Role instance
        """
        from stalker import Client, User

        with self.assertRaises(TypeError) as cm:
            client_user = ClientUser(
                client=Client(name='Test Client'),
                user=User(
                    name='Test User',
                    login='******',
                    email='*****@*****.**',
                    password='******'
                ),
                role='not a role instance'
            )

        self.assertEqual(
            str(cm.exception),
            'ClientUser.role should be a stalker.models.auth.Role instance, '
            'not str'
        )
Beispiel #22
0
    def setUp(self):
        """lets setup the tests
        """
        # create a couple of test users
        self.test_user1 = User(
            name="User1",
            login="******",
            email="*****@*****.**",
            password="******",
        )

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

        self.test_user3 = User(
            name="User3",
            login="******",
            email="*****@*****.**",
            password="******",
        )

        self.test_user4 = User(
            name="User4",
            login="******",
            email="*****@*****.**",
            password="******",
        )

        self.users_list = [
            self.test_user1, self.test_user2, self.test_user3, self.test_user4
        ]

        self.test_admin = User(
            name="admin",
            login="******",
            email="*****@*****.**",
            password="******",
        )

        self.status_new = Status(name="Test status 1", code="Status1")
        self.status_wip = Status(name="Test status 2", code="Status2")
        self.status_cmpl = Status(name="Test status 3", code="Status3")

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

        self.test_repo = Repository(name="Test Repository")

        self.test_project1 = Project(
            name="Test Project 1",
            code='proj1',
            status_list=self.project_statuses,
            repository=self.test_repo,
        )

        self.test_project2 = Project(
            name="Test Project 1",
            code='proj2',
            status_list=self.project_statuses,
            repository=self.test_repo,
        )

        self.test_project3 = Project(
            name="Test Project 1",
            code='proj3',
            status_list=self.project_statuses,
            repository=self.test_repo,
        )

        self.projects_list = [
            self.test_project1, self.test_project2, self.test_project3
        ]

        self.date_created = self.date_updated = datetime.datetime.now()

        self.kwargs = {
            "name": "Test Client",
            "description": "This is a client for testing purposes",
            "created_by": self.test_admin,
            "updated_by": self.test_admin,
            "date_created": self.date_created,
            "date_updated": self.date_updated,
            "users": self.users_list,
            "projects": self.projects_list
        }

        # create a default client object
        self.test_client = Client(**self.kwargs)
Beispiel #23
0
    def setUp(self):
        """run once
        """
        super(PaymentTestCase, self).setUp()
        from stalker import Status

        self.status_new = Status(name='Mew', code='NEW')
        self.status_wfd = Status(name='Waiting For Dependency', code='WFD')
        self.status_rts = Status(name='Ready To Start', code='RTS')
        self.status_wip = Status(name='Work In Progress', code='WIP')
        self.status_prev = Status(name='Pending Review', code='PREV')
        self.status_hrev = Status(name='Has Revision', code='HREV')
        self.status_drev = Status(name='Dependency Has Revision', code='DREV')
        self.status_oh = Status(name='On Hold', code='OH')
        self.status_stop = Status(name='Stopped', code='STOP')
        self.status_cmpl = Status(name='Completed', code='CMPL')

        self.status_new = Status(name='New', code='NEW')
        self.status_app = Status(name='Approved', code='APP')

        from stalker import StatusList
        self.budget_status_list = StatusList(
            name='Budget Statuses',
            target_entity_type='Budget',
            statuses=[self.status_new, self.status_prev, self.status_app])

        self.task_status_list = StatusList(
            name='Task Statses',
            statuses=[
                self.status_wfd, self.status_rts, self.status_wip,
                self.status_prev, self.status_hrev, self.status_drev,
                self.status_oh, self.status_stop, self.status_cmpl
            ],
            target_entity_type='Task')

        from stalker import Project
        self.test_project_status_list = StatusList(
            name="Project Statuses",
            statuses=[self.status_wip, self.status_prev, self.status_cmpl],
            target_entity_type=Project,
        )

        from stalker import Type
        self.test_movie_project_type = Type(
            name="Movie Project",
            code='movie',
            target_entity_type=Project,
        )

        from stalker import Repository
        self.test_repository_type = Type(
            name="Test Repository Type",
            code='test',
            target_entity_type=Repository,
        )

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

        from stalker import User
        self.test_user1 = User(name="User1",
                               login="******",
                               email="*****@*****.**",
                               password="******")

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

        self.test_user3 = User(name="User3",
                               login="******",
                               email="*****@*****.**",
                               password="******")

        self.test_user4 = User(name="User4",
                               login="******",
                               email="*****@*****.**",
                               password="******")

        self.test_user5 = User(name="User5",
                               login="******",
                               email="*****@*****.**",
                               password="******")

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

        self.test_project = Project(name="Test Project1",
                                    code='tp1',
                                    type=self.test_movie_project_type,
                                    status_list=self.test_project_status_list,
                                    repository=self.test_repository,
                                    clients=[self.test_client])

        from stalker import Budget
        self.test_budget = Budget(project=self.test_project,
                                  name='Test Budget 1',
                                  status_list=self.budget_status_list)

        from stalker import Invoice
        self.test_invoice = Invoice(budget=self.test_budget,
                                    client=self.test_client,
                                    amount=1500,
                                    unit='TRY')
Beispiel #24
0
    def setUp(self):
        """run once
        """
        super(InvoiceTestCase, self).setUp()

        from stalker import Status
        self.status_wfd = Status.query.filter_by(code="WFD").first()
        self.status_rts = Status.query.filter_by(code="RTS").first()
        self.status_wip = Status.query.filter_by(code="WIP").first()
        self.status_prev = Status.query.filter_by(code="PREV").first()
        self.status_hrev = Status.query.filter_by(code="HREV").first()
        self.status_drev = Status.query.filter_by(code="DREV").first()
        self.status_oh = Status.query.filter_by(code="OH").first()
        self.status_stop = Status.query.filter_by(code="STOP").first()
        self.status_cmpl = Status.query.filter_by(code="CMPL").first()

        self.status_new = Status.query.filter_by(code='NEW').first()
        self.status_app = Status.query.filter_by(code='APP').first()

        from stalker import db, StatusList
        self.budget_status_list = StatusList(
            name='Budget Statuses',
            target_entity_type='Budget',
            statuses=[self.status_new, self.status_prev, self.status_app])
        db.DBSession.add(self.budget_status_list)

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

        from stalker import Project
        self.test_project_status_list = StatusList(
            name="Project Statuses",
            statuses=[self.status_wip, self.status_prev, self.status_cmpl],
            target_entity_type=Project,
        )
        db.DBSession.add(self.test_project_status_list)

        from stalker import Type
        self.test_movie_project_type = Type(
            name="Movie Project",
            code='movie',
            target_entity_type=Project,
        )
        db.DBSession.add(self.test_movie_project_type)

        from stalker import Repository
        self.test_repository_type = Type(
            name="Test Repository Type",
            code='test',
            target_entity_type=Repository,
        )
        db.DBSession.add(self.test_repository_type)

        self.test_repository = Repository(
            name="Test Repository",
            type=self.test_repository_type,
        )
        db.DBSession.add(self.test_repository)

        from stalker import User
        self.test_user1 = User(name="User1",
                               login="******",
                               email="*****@*****.**",
                               password="******")
        db.DBSession.add(self.test_user1)

        self.test_user2 = User(name="User2",
                               login="******",
                               email="*****@*****.**",
                               password="******")
        db.DBSession.add(self.test_user2)

        self.test_user3 = User(name="User3",
                               login="******",
                               email="*****@*****.**",
                               password="******")
        db.DBSession.add(self.test_user3)

        self.test_user4 = User(name="User4",
                               login="******",
                               email="*****@*****.**",
                               password="******")
        db.DBSession.add(self.test_user4)

        self.test_user5 = User(name="User5",
                               login="******",
                               email="*****@*****.**",
                               password="******")
        db.DBSession.add(self.test_user5)

        from stalker import Client
        self.test_client = Client(name='Test Client', )
        db.DBSession.add(self.test_client)

        self.test_project = Project(name="Test Project1",
                                    code='tp1',
                                    type=self.test_movie_project_type,
                                    status_list=self.test_project_status_list,
                                    repository=self.test_repository,
                                    clients=[self.test_client])
        db.DBSession.add(self.test_project)

        from stalker import Budget
        self.test_budget = Budget(
            project=self.test_project,
            name='Test Budget 1',
        )
        db.DBSession.add(self.test_budget)
        db.DBSession.commit()
Beispiel #25
0
 def test_to_tjp_method_is_working_properly(self):
     """testing if the to_tjp method is working properly
     """
     client1 = Client(**self.kwargs)
     assert client1.to_tjp() == ''
Beispiel #26
0
    def setUp(self):
        """run once
        """
        from stalker import defaults
        import datetime
        defaults.timing_resolution = datetime.timedelta(hours=1)

        # create a new session
        from stalker import db
        db.setup({'sqlalchemy.url': 'sqlite://', 'sqlalchemy.echo': False})
        db.init()

        from stalker import Status
        self.status_wfd = Status.query.filter_by(code="WFD").first()
        self.status_rts = Status.query.filter_by(code="RTS").first()
        self.status_wip = Status.query.filter_by(code="WIP").first()
        self.status_prev = Status.query.filter_by(code="PREV").first()
        self.status_hrev = Status.query.filter_by(code="HREV").first()
        self.status_drev = Status.query.filter_by(code="DREV").first()
        self.status_oh = Status.query.filter_by(code="OH").first()
        self.status_stop = Status.query.filter_by(code="STOP").first()
        self.status_cmpl = Status.query.filter_by(code="CMPL").first()

        self.status_new = Status.query.filter_by(code='NEW').first()
        self.status_app = Status.query.filter_by(code='APP').first()

        from stalker import StatusList
        self.budget_status_list = StatusList(
            name='Budget Statuses',
            target_entity_type='Budget',
            statuses=[self.status_new, self.status_prev, self.status_app])
        db.DBSession.add(self.budget_status_list)

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

        from stalker import Project
        self.test_project_status_list = StatusList(
            name="Project Statuses",
            statuses=[self.status_wip, self.status_prev, self.status_cmpl],
            target_entity_type=Project,
        )

        from stalker import Type
        self.test_movie_project_type = Type(
            name="Movie Project",
            code='movie',
            target_entity_type=Project,
        )

        from stalker import Repository
        self.test_repository_type = Type(
            name="Test Repository Type",
            code='test',
            target_entity_type=Repository,
        )

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

        from stalker import User
        self.test_user1 = User(name="User1",
                               login="******",
                               email="*****@*****.**",
                               password="******")

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

        self.test_user3 = User(name="User3",
                               login="******",
                               email="*****@*****.**",
                               password="******")

        self.test_user4 = User(name="User4",
                               login="******",
                               email="*****@*****.**",
                               password="******")

        self.test_user5 = User(name="User5",
                               login="******",
                               email="*****@*****.**",
                               password="******")

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

        self.test_project = Project(name="Test Project1",
                                    code='tp1',
                                    type=self.test_movie_project_type,
                                    status_list=self.test_project_status_list,
                                    repository=self.test_repository,
                                    clients=[self.test_client])

        from stalker import Budget
        self.test_budget = Budget(
            project=self.test_project,
            name='Test Budget 1',
        )

        from stalker import Invoice
        self.test_invoice = Invoice(budget=self.test_budget,
                                    client=self.test_client,
                                    amount=1500,
                                    unit='TRY')
Beispiel #27
0
    def setUp(self):
        """lets setup the tests
        """
        super(ClientTestCase, self).setUp()
        # create a couple of test users
        from stalker import User
        self.test_user1 = User(
            name="User1",
            login="******",
            email="*****@*****.**",
            password="******",
        )

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

        self.test_user3 = User(
            name="User3",
            login="******",
            email="*****@*****.**",
            password="******",
        )

        self.test_user4 = User(
            name="User4",
            login="******",
            email="*****@*****.**",
            password="******",
        )

        self.users_list = [
            self.test_user1,
            self.test_user2,
            self.test_user3,
            self.test_user4
        ]

        self.test_admin = User(
            name='admin',
            login='******',
            email='*****@*****.**',
            password='******'
        )

        from stalker import Status
        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 StatusList
        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 Repository
        self.test_repo = Repository(
            name="Test Repository"
        )

        from stalker import Project
        self.test_project1 = Project(
            name="Test Project 1",
            code='proj1',
            status_list=self.project_statuses,
            repository=self.test_repo,
        )

        self.test_project2 = Project(
            name="Test Project 1",
            code='proj2',
            status_list=self.project_statuses,
            repository=self.test_repo,
        )

        self.test_project3 = Project(
            name="Test Project 1",
            code='proj3',
            status_list=self.project_statuses,
            repository=self.test_repo,
        )

        self.projects_list = [
            self.test_project1,
            self.test_project2,
            self.test_project3

        ]

        import pytz
        import datetime
        self.date_created = self.date_updated = datetime.datetime.now(pytz.utc)

        self.kwargs = {
            "name": "Test Client",
            "description": "This is a client for testing purposes",
            "created_by": self.test_admin,
            "updated_by": self.test_admin,
            "date_created": self.date_created,
            "date_updated": self.date_updated,
            "users": self.users_list,
            "projects": self.projects_list
        }

        # create a default client object
        self.test_client = Client(**self.kwargs)