Beispiel #1
0
 def test_product_filter(self):
     ItemFactory(creating_task=self.task, amount=3)
     included_other_product_type = ProductTypeFactory()
     included_other_task = TaskFactory(
         process_type=self.process_type,
         product_type=included_other_product_type)
     included_other_item = ItemFactory(creating_task=included_other_task,
                                       amount=7)
     excluded_other_product_type = ProductTypeFactory()
     excluded_other_task = TaskFactory(
         process_type=self.process_type,
         product_type=excluded_other_product_type)
     excluded_other_item = ItemFactory(creating_task=excluded_other_task,
                                       amount=7)
     product_ids = [
         str(i)
         for i in [self.product_type.id, included_other_product_type.id]
     ]
     product_id_string = ','.join(product_ids)
     query_params = {
         'team': self.product_type.team_created_by.id,
         'product_types': product_id_string
     }
     response = self.client.get(self.url, query_params, format='json')
     self.assertEqual(len(response.data['results']), 2)
     response_product_ids = [
         response.data['results'][0]['product_id'],
         response.data['results'][1]['product_id']
     ]
     self.assertEqual(sorted(product_ids), sorted(response_product_ids))
Beispiel #2
0
 def test_is_trashed_filter(self):
     TaskFactory()
     TaskFactory(is_trashed=True)
     query_params = {'team': self.team.id}
     response = self.client.get(self.url, query_params)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(response.data), 1)
Beispiel #3
0
    def test_create_movement(self):
        task1 = TaskFactory(process_type=self.process_type,
                            product_type=self.product_type)
        task2 = TaskFactory(process_type=self.process_type,
                            product_type=self.product_type)
        task3 = TaskFactory(process_type=self.process_type,
                            product_type=self.product_type)
        old_item1 = ItemFactory(creating_task=task1)
        old_item2 = ItemFactory(creating_task=task2)
        old_item3 = ItemFactory(creating_task=task3)
        self.assertEqual(old_item1.team_inventory, self.sending_team)
        self.assertEqual(old_item2.team_inventory, self.sending_team)
        self.assertEqual(old_item3.team_inventory, self.sending_team)
        url = reverse('create_movement')
        data = {
            'origin': self.process_type.created_by.id,
            'team_origin': self.sending_team.id,
            'team_destination': self.receiving_team.id,
            'items': [{
                'item': old_item1.id
            }, {
                'item': old_item2.id
            }]
        }
        response = self.client.post(url, data, format='json')
        self.assertEqual(response.status_code, 201)

        new_item1 = Item.objects.get(id=old_item1.id)
        new_item2 = Item.objects.get(id=old_item2.id)
        new_item3 = Item.objects.get(id=old_item3.id)
        self.assertEqual(new_item1.team_inventory, self.receiving_team)
        self.assertEqual(new_item2.team_inventory, self.receiving_team)
        self.assertEqual(new_item3.team_inventory, self.sending_team)
Beispiel #4
0
 def test_aggregate_products(self):
     process_type = ProcessTypeFactory()
     product_type1 = ProductTypeFactory()
     product_type2 = ProductTypeFactory()
     task1 = TaskFactory(process_type=process_type,
                         product_type=product_type1)
     ItemFactory(creating_task=task1, amount=2.3)
     task2 = TaskFactory(process_type=process_type,
                         product_type=product_type2)
     ItemFactory(creating_task=task2, amount=4.1)
     query_params = {'team': self.team.id, 'aggregate_products': 'true'}
     response = self.client.get(self.url, query_params)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(response.data), 1)
     row = response.data[0]
     self.assertEqual(row['process_type']['id'], task1.process_type.id)
     self.assertEqual(row['process_type']['name'], process_type.name)
     self.assertEqual(row['process_type']['code'], process_type.code)
     self.assertEqual(row['process_type']['unit'], process_type.unit)
     self.assertEqual(row['process_type']['icon'], process_type.icon)
     self.assertEqual(len(row['product_types']), 2)
     result_products = [
         row['product_types'][0]['id'], row['product_types'][1]['id']
     ]
     self.assertEqual(sorted(result_products),
                      sorted([product_type1.id, product_type2.id]))
     self.assertEqual(row['amount'], Decimal('6.4'))
Beispiel #5
0
 def test_label_search(self):
     task1 = TaskFactory()
     task2 = TaskFactory(custom_display='customtaskname')
     query_params = {'team': self.team.id, 'label': 'customtaskname'}
     response = self.client.get(self.url, query_params)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(response.data), 1)
Beispiel #6
0
 def test_process_type_filter(self):
     task1 = TaskFactory()
     task2 = TaskFactory()
     task3 = TaskFactory()
     process_types = '{},{}'.format(task2.process_type.id,
                                    task3.process_type.id)
     query_params = {'team': self.team.id, 'process_types': process_types}
     response = self.client.get(self.url, query_params)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(response.data), 2)
Beispiel #7
0
 def test_team_filter(self):
     task = TaskFactory()
     other_team = TeamFactory(name='other-team')
     other_team_process_type = ProcessTypeFactory(
         team_created_by=other_team)
     other_team_product_type = ProductTypeFactory(
         team_created_by=other_team)
     other_team_task = TaskFactory(process_type=other_team_process_type,
                                   product_type=other_team_product_type)
     response = self.client.get(self.url, self.query_params)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(response.data), 1)
     self.assertEqual(response.data[0]['process_type']['id'],
                      task.process_type.id)
Beispiel #8
0
 def test_flag_filter(self):
     unflagged_task = TaskFactory()
     flagged_task = TaskFactory(is_flagged=True,
                                process_type=unflagged_task.process_type,
                                product_type=unflagged_task.product_type)
     ItemFactory(creating_task=unflagged_task, amount=2.3)
     ItemFactory(creating_task=flagged_task, amount=5.9)
     query_params = {'team': self.team.id, 'flagged': 'true'}
     response = self.client.get(self.url, query_params)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(response.data), 1)
     row = response.data[0]
     self.assertEqual(row['runs'], 1)
     self.assertEqual(row['amount'], Decimal('5.9'))
Beispiel #9
0
 def test_exlude_items_with_deleted_tasks(self):
     deleted_task = TaskFactory(process_type=self.process_type,
                                product_type=self.product_type,
                                is_trashed=True)
     item = ItemFactory(creating_task=deleted_task, amount=3)
     response = self.client.get(self.url, self.query_params, format='json')
     self.assertEqual(len(response.data['results']), 0)
Beispiel #10
0
 def setUp(self):
     self.product_type = ProductTypeFactory(name='product-name',
                                            code='product-code')
     self.process_type = ProcessTypeFactory(name='process-name',
                                            code='pc',
                                            unit='process-unit')
     self.task = TaskFactory.create(process_type=self.process_type,
                                    product_type=self.product_type)
Beispiel #11
0
 def test_other_items(self):
     wrong_process_task = TaskFactory(process_type=ProcessTypeFactory(),
                                      product_type=self.product_type)
     wrong_product_task = TaskFactory(process_type=self.process_type,
                                      product_type=ProductTypeFactory())
     deleted_task = TaskFactory(process_type=self.process_type,
                                product_type=self.product_type,
                                is_trashed=True)
     other_team = TeamFactory(name='other-team')
     ItemFactory(creating_task=wrong_process_task)
     ItemFactory(creating_task=wrong_product_task)
     ItemFactory(creating_task=deleted_task)
     other_team_item = ItemFactory(creating_task=self.task)
     other_team_item.team_inventory = other_team
     other_team_item.save()
     response = self.client.get(self.url, self.query_params, format='json')
     self.assertEqual(len(response.data), 1)
Beispiel #12
0
 def test_list_tasks(self):
     with mock.patch('django.utils.timezone.now') as mock_now:
         mock_now.return_value = timezone.make_aware(
             datetime.datetime(2018, 1, 10), timezone.utc)
         task1 = TaskFactory(label='Jan-Task')
     with mock.patch('django.utils.timezone.now') as mock_now:
         mock_now.return_value = timezone.make_aware(
             datetime.datetime(2018, 2, 10), timezone.utc)
         task2 = TaskFactory(label='Feb-Task')
     url = reverse('tasks')
     query_params = {
         'start': format_date(datetime.datetime(2018, 1, 5)),
         'end': format_date(datetime.datetime(2018, 1, 15))
     }
     response = self.client.get(url, query_params, format='json')
     self.assertEqual(len(response.data), 1)
     self.assertEqual(response.data[0]['label'], 'Jan-Task')
Beispiel #13
0
 def test_date_filter(self):
     with mock.patch('django.utils.timezone.now') as mock_now:
         mock_now.return_value = timezone.make_aware(
             datetime.datetime(2018, 1, 10), timezone.utc)
         task1 = TaskFactory()
     with mock.patch('django.utils.timezone.now') as mock_now:
         mock_now.return_value = timezone.make_aware(
             datetime.datetime(2018, 2, 10), timezone.utc)
         task2 = TaskFactory()
     query_params = {
         'team': self.team.id,
         'start': format_date(datetime.datetime(2018, 1, 5)),
         'end': format_date(datetime.datetime(2018, 1, 15))
     }
     response = self.client.get(self.url, query_params)
     self.assertEqual(len(response.data), 1)
     self.assertEqual(response.data[0]['process_type']['id'],
                      task1.process_type.id)
Beispiel #14
0
 def setUp(self):
     self.process_type = ProcessTypeFactory()
     self.url = reverse('production_actuals')
     with mock.patch('django.utils.timezone.now') as mock_now:
         mock_now.return_value = timezone.make_aware(
             datetime.datetime(2018, 1, 10), timezone.utc)
         task1 = TaskFactory(label='Jan-Task',
                             process_type=self.process_type)
         ItemFactory.create(creating_task=task1, amount=576)
     with mock.patch('django.utils.timezone.now') as mock_now:
         mock_now.return_value = timezone.make_aware(
             datetime.datetime(2018, 1, 11), timezone.utc)
         task2 = TaskFactory(label='Jan-Task',
                             process_type=self.process_type)
         ItemFactory.create(creating_task=task2, amount=14)
     with mock.patch('django.utils.timezone.now') as mock_now:
         mock_now.return_value = timezone.make_aware(
             datetime.datetime(2018, 2, 10), timezone.utc)
         task3 = TaskFactory(label='Feb-Task',
                             process_type=self.process_type)
         ItemFactory.create(creating_task=task3, amount=819)
Beispiel #15
0
 def setUp(self):
     self.process_type = ProcessTypeFactory(name='process-name',
                                            code='process-code',
                                            unit='process-unit')
     self.product_type = ProductTypeFactory(name='product-name',
                                            code='product-code')
     self.url = reverse('inventories')
     self.query_params = {'team': self.process_type.team_created_by.id}
     self.past_time = timezone.make_aware(datetime.datetime(2018, 1, 10),
                                          timezone.utc)
     self.task = TaskFactory(process_type=self.process_type,
                             product_type=self.product_type)
Beispiel #16
0
 def test_activity_list(self):
     process_type = ProcessTypeFactory(icon='someicon.png',
                                       name='process-type-name',
                                       code='ptc',
                                       unit='kg')
     task1 = TaskFactory(process_type=process_type)
     task2 = TaskFactory(process_type=process_type)
     ItemFactory(creating_task=task1, amount=29.7)
     response = self.client.get(self.url, self.query_params)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(response.data), 2)
     row = response.data[0]
     self.assertEqual(row['runs'], 1)
     self.assertEqual(row['process_type']['id'], process_type.id)
     self.assertEqual(row['process_type']['name'], process_type.name)
     self.assertEqual(row['process_type']['code'], process_type.code)
     self.assertEqual(row['process_type']['unit'], process_type.unit)
     self.assertEqual(row['process_type']['icon'], process_type.icon)
     self.assertEqual(len(row['product_types']), 1)
     self.assertEqual(row['product_types'][0]['id'], task1.product_type.id)
     self.assertEqual(row['amount'], Decimal('29.700'))
Beispiel #17
0
    def test_team_filter(self):
        item = ItemFactory(creating_task=self.task, amount=3)

        other_team = TeamFactory(name='other-team')
        other_team_process_type = ProcessTypeFactory(
            team_created_by=other_team)
        other_team_product_type = ProductTypeFactory(
            team_created_by=other_team)
        other_team_task = TaskFactory(process_type=other_team_process_type,
                                      product_type=other_team_product_type)
        other_team_item = ItemFactory(creating_task=other_team_task, amount=34)

        response = self.client.get(self.url, self.query_params, format='json')
        self.assertEqual(len(response.data['results']), 1)
 def setUp(self):
     self.task = TaskFactory.create()
     self.attribute = AttributeFactory()
Beispiel #19
0
	def setUp(self):
		self.process_type = ProcessTypeFactory()
		task = TaskFactory(process_type=self.process_type)
		self.url = reverse('task_detail', args=[task.id])