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'))
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))
def test_list_product_types_exclude_deleted(self): active_product_type = ProductTypeFactory() ProductTypeFactory(is_trashed=True) url = reverse('product_types') response = self.client.get(url, format='json') self.assertEqual(len(response.data), 1) product_type = response.data[0] self.assertEqual(product_type['id'], active_product_type.id)
def setUp(self): self.user_profile = UserProfileFactory() self.process_type = ProcessTypeFactory( created_by=self.user_profile.user) self.product_type1 = ProductTypeFactory( created_by=self.user_profile.user) self.product_type2 = ProductTypeFactory( created_by=self.user_profile.user)
def setUp(self): self.sending_team = TeamFactory(name='sending-team') self.receiving_team = TeamFactory(name='receiving-team') self.process_type = ProcessTypeFactory( team_created_by=self.sending_team) self.product_type = ProductTypeFactory( team_created_by=self.sending_team)
def test_create_adjustment(self): userprofile = UserProfileFactory() process_type = ProcessTypeFactory() product_type = ProductTypeFactory() data = { 'userprofile': userprofile.id, 'process_type': process_type.id, 'product_type': product_type.id, 'amount': 175, 'explanation': 'test-explanation' } url = reverse('adjustments') self.assertEqual(Adjustment.objects.count(), 0) response = self.client.post(url, data, format='json') self.assertEqual(Adjustment.objects.count(), 1) adjustment = Adjustment.objects.get() self.assertEqual(adjustment.userprofile.id, userprofile.id) secondsDiff = abs( (datetime.datetime.today() - adjustment.created_at.replace(tzinfo=None)).total_seconds()) self.assertLess(secondsDiff, 10) self.assertEqual(adjustment.process_type.id, process_type.id) self.assertEqual(adjustment.product_type.id, product_type.id) self.assertEqual(adjustment.amount, 175) self.assertEqual(adjustment.explanation, 'test-explanation')
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)
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)
def test_create_task(self): process_type = ProcessTypeFactory() product_type = ProductTypeFactory() url = reverse('create_task') data = { 'label': 'T1', 'process_type': process_type.id, 'product_type': product_type.id } response = self.client.post(url, data, format='json') self.assertEqual(response.status_code, 201) self.assertEqual(Task.objects.count(), 1) self.assertEqual(Task.objects.get().label, 'T1')
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)
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 test_edit_product_type(self): product_type = ProductTypeFactory(name='old-name') url = reverse('product_type_detail', args=[product_type.id]) data = { 'created_by': product_type.created_by.id, 'team_created_by': product_type.team_created_by.id, 'name': 'new-name', 'code': 'new-code', 'description': 'new-description', } response = self.client.put(url, data, format='json') self.assertEqual(response.status_code, 200) product_type = ProductType.objects.get(id=product_type.id) self.assertEqual(product_type.name, 'new-name') self.assertEqual(product_type.code, 'new-code') self.assertEqual(product_type.description, 'new-description')
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)
def test_list_product_types(self): ProductTypeFactory( created_by=self.user_profile.user, team_created_by=self.user_profile.team, name='product-name', code='product-code', description='Product Description', ) url = reverse('product_types') response = self.client.get(url, format='json') self.assertEqual(response.status_code, 200) self.assertEqual(len(response.data), 1) product_type = response.data[0] self.assertEqual(product_type['created_by'], self.user_profile.user.id) self.assertEqual(product_type['team_created_by'], self.user_profile.team.id) self.assertEqual(product_type['name'], 'product-name') self.assertEqual(product_type['code'], 'product-code') self.assertEqual(product_type['description'], 'Product Description')