コード例 #1
0
 def setUp(self):
     # create test user
     self.username = '******'
     self.password = '******'
     self.user = User.objects.create_user(username=self.username,
                                          password=self.password)
     self.client.login(username=self.username, password=self.password)
     # retrieve the view
     self.view_name = 'reporter:customer-rd'
     # add customer to database
     models.Customer(name='customer 1',
                     watchman_group_id='g_1111111',
                     repairshopr_id='1111111').save()
     self.customer = models.Customer.objects.first()
コード例 #2
0
 def test_customer_list_filter_name(self):
     # add customers to database
     customer = models.Customer(name='customer 1',
                                watchman_group_id='g_1111111',
                                repairshopr_id='1111111')
     customer.save()
     models.Customer(name='customer 2',
                     watchman_group_id='g_2222222',
                     repairshopr_id='2222222').save()
     # request
     response = self.client.get(reverse(self.view_name),
                                {'name': customer.name})
     response_body = json.loads(response.content.decode('utf-8'))
     # test response
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(len(response_body['results']), 1)
     self.assertIn(
         {
             'pk': customer.id,
             'name': customer.name,
             'watchman_group_id': customer.watchman_group_id,
             'repairshopr_id': customer.repairshopr_id
         }, response_body['results'])
コード例 #3
0
 def test_schedule_list_filter_customer(self):
     """
     Tests that schedules are listed if they match the id filter parameter.
     """
     customer = models.Customer(name='customer 2',
                                watchman_group_id='g_2222222',
                                repairshopr_id='2222222')
     customer.save()
     # create schedules
     request_body_1 = {
         'periodic_task': {
             'minute': '0',
             'hour': '2',
             'day_of_week': '*',
             'day_of_month': '*',
             'month_of_year': '*',
         },
         'customer': self.customer.id,
         'task_type': 'watchman'
     }
     request_body_2 = {
         'periodic_task': {
             'minute': '0',
             'hour': '2',
             'day_of_week': '*',
             'day_of_month': '*',
             'month_of_year': '*',
         },
         'customer': customer.id,
         'task_type': 'repairshopr'
     }
     response = self.client.post(reverse(self.view_name),
                                 request_body_1,
                                 format='json')
     response_body = json.loads(response.content.decode('utf-8'))
     self.client.post(reverse(self.view_name),
                      request_body_2,
                      format='json')
     # request
     response = self.client.get(reverse(self.view_name),
                                {'customer': response_body['customer']})
     response_body = json.loads(response.content.decode('utf-8'))
     # test response
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(len(response_body['results']), 1)
     self.assertDictContainsSubset(request_body_1,
                                   response_body['results'][0])