示例#1
0
    def test_get_project_by_name(self):
        project_name = u'A nice project'
        customer_name = u'A good customer'
        session = DBSession()
        project = Project(name=project_name)
        customer = Customer(name=customer_name)
        customer.add_project(project)
        session.add(customer)
        transaction.commit()

        resp = self.proxy.get_project_by_name(project_name)
        self.assertEqual(resp['name'], project_name)
示例#2
0
    def test_project_attributes(self):
        project_name = u'Another nice project'
        customer_name = u'A very good customer'
        session = DBSession()
        project = Project(name=project_name)
        customer = Customer(name=customer_name)
        customer.add_project(project)
        applications1 = Application(name=u'Trac')
        applications2 = Application(name=u'Svn')
        customerR1 = CustomerRequest(name=u'A bad request')
        customerR2 = CustomerRequest(name=u'A good request')
        project.add_application(applications1)
        project.add_application(applications2)
        project.add_customer_request(customerR1)
        project.add_customer_request(customerR2)
        session.add(customer)
        transaction.commit()

        resp = self.proxy.get_project_by_name(project_name)
        self.assertTrue(u'Trac' in resp['applications'])
        self.assertTrue(u'another-nice-project_1' in [item for sublist in resp['customer_requests'] for item in sublist])
        self.assertTrue(u'another-nice-project_2' in [item for sublist in resp['customer_requests'] for item in sublist])
        self.assertTrue(2, len(resp['customer_requests']))
        self.assertTrue(2, len(resp['applications']))
示例#3
0
    def test_time_entry_creation(self):
        """
        This test check time entry parameters
        """
        #customer data
        customer_name = u'RFCCustomer'
        #project data
        project_name = u'A new project'
        project_id = 'a-new-project'
        #entry data
        entry_date = datetime.date(2011, 05, 26)
        entry_hours = '2:30'
        entry_location = u'RedTurtle Technology'
        entry_description = u'Trying to create ticket for API tests'
        entry_ticket = '45'

        #Start to create customer, project and time entry for project
        session = DBSession()
        project = Project(name=project_name, id=project_id)
        customer = Customer(name=customer_name)
        customer.add_project(project)
        session.add(customer)
        transaction.commit()

        #Try to get errors
        resp = self.proxy.create_new_simple_time_entry(1, entry_date,
                                                       entry_hours, entry_description,
                                                       entry_location,10)
        self.assertEqual(resp['message'], u"'int' object has no attribute 'decode'")

        resp = self.proxy.create_new_simple_time_entry(entry_ticket,
                                                       entry_date,
                                                       u'9000',
                                                       entry_description,
                                                       entry_location,
                                                       10)

        self.assertEqual(resp['message'], u'Cannot parse time (must be HH:MM)')

        resp = self.proxy.create_new_simple_time_entry(entry_ticket,
                                                       entry_date,
                                                       u'9:40',
                                                       entry_description,
                                                       entry_location,
                                                       10)

        self.assertEqual(resp['message'], u'Time value too big (must be <= 8:00)')

        resp = self.proxy.create_new_simple_time_entry(entry_ticket,
                                                       entry_date,
                                                       entry_hours,
                                                       entry_description,
                                                       entry_location,
                                                       100)
        self.assertEqual(resp['message'], u'Not able to get the project with id 100')

        resp = self.proxy.create_new_simple_time_entry(entry_ticket,
                                                       '2011 01 01',
                                                       entry_hours,
                                                       entry_description,
                                                       entry_location,
                                                       100)
        self.assertEqual(resp['message'],  u"time data '2011 01 01' does not match format '%Y-%m-%d'")

        #Let's try to create a simple time entry
        resp = self.proxy.create_new_simple_time_entry(entry_ticket,
                                                       entry_date,
                                                       entry_hours,
                                                       entry_description,
                                                       entry_location,
                                                       project_id)

        self.assertRegexpMatches(resp['message'], u'Correctly added time entry \d+ for %s ticket #%s' %(project_id, entry_ticket))

        resp = self.proxy.create_new_simple_time_entry(entry_ticket,
                                                       entry_date,
                                                       entry_hours,
                                                       '',
                                                       entry_location,
                                                       project_id)
        self.assertEqual(resp['message'], u"Description is required.")

        #Now try to create a more complex time entry
        entry_start = datetime.datetime(2011, 01, 01, 15, 30)
        entry_end = datetime.datetime(2011, 01, 01, 17, 30)
        entry_ticket = '#99'

        resp = self.proxy.create_new_advanced_time_entry(99,
                                                         entry_start,
                                                         entry_end,
                                                         entry_description,
                                                         entry_location,
                                                         10)
        self.assertEqual(resp['message'], u"'int' object has no attribute 'decode'")

        resp = self.proxy.create_new_advanced_time_entry(entry_ticket,
                                                         entry_start,
                                                         entry_end,
                                                         entry_description,
                                                         entry_location,
                                                         100)
        self.assertEqual(resp['message'], u'Not able to get the project with id 100')

        resp = self.proxy.create_new_advanced_time_entry(entry_ticket,
                                                         '2011 08 24',
                                                         entry_end,
                                                         entry_description,
                                                         entry_location,
                                                         10)
        self.assertEqual(resp['message'], u"time data '2011 08 24' does not match format '%Y-%m-%d %H:%M:%S'")

        resp = self.proxy.create_new_advanced_time_entry(entry_ticket,
                                                         entry_start,
                                                         entry_end,
                                                         entry_description,
                                                         entry_location,
                                                         project_id)
        self.assertRegexpMatches(resp['message'], u'Correctly added time entry \d+ for %s ticket #%s' %(project_id, entry_ticket))