コード例 #1
0
ファイル: tests.py プロジェクト: charliephairoj/backend
class LogTestCase(APITestCase):
    def setUp(self):
        """
        Set up for log tests
        """
        self.fabric = Fabric(pattern="Max", color="Grey", quantity="12", units="yd", description="Max Col: Grey")
        self.fabric.save()
        self.log = Log.objects.create(
            message="Reserved 5yd", acknowledgement_id=1002, action="RESERVE", quantity=10, supply=self.fabric
        )

    def test_cut_fabric(self):

        data = {
            "id": 1,
            "message": "Reserve 5yd",
            "action": "CUT",
            "quantity": 8,
            "supply": {"id": 1, "image": {"id": 100}},
        }
        resp = self.client.put("/api/v1/log/1/", data=data, format="json")

        self.assertEqual(resp.status_code, 200, msg=resp)

        log_data = resp.data

        self.assertEqual(log_data["id"], 1)
        self.assertEqual(log_data["message"], "8yd of Max Col: Grey cut for Ack #1002")
        self.assertEqual(Decimal(log_data["quantity"]), Decimal("8"))
        self.assertEqual(log_data["acknowledgement_id"], "1002")
        self.assertEqual(log_data["action"], "SUBTRACT")

        fabric = Fabric.objects.get(pk=1)
        self.assertEqual(fabric.quantity, 4)

    def test_cancel_fabric_reservation(self):

        data = {
            "id": 1,
            "message": "Reserve 5yd",
            "action": "CANCEL",
            "quantity": 10,
            "supply": {"id": 1, "image": {"id": 100}},
        }
        resp = self.client.put("/api/v1/log/1/", data=data, format="json")

        self.assertEqual(resp.status_code, 200, msg=resp)

        log_data = resp.data

        self.assertEqual(log_data["id"], 1)
        self.assertEqual(log_data["message"], "Cancelled reservation of Max Col: Grey for Ack #1002")
        self.assertEqual(Decimal(log_data["quantity"]), Decimal("10"))
        self.assertEqual(log_data["acknowledgement_id"], "1002")
        self.assertEqual(log_data["action"], "CANCELLED")

        fabric = Fabric.objects.get(pk=1)
        self.assertEqual(fabric.quantity, 12)
コード例 #2
0
 
 supplier = Supplier.objects.get(pk=76)
 
 for f in fabrics:
     try:
         fabric = Fabric.objects.get(pattern=f['pattern'], color=f['color'])
     except Fabric.DoesNotExist:
         fabric = Fabric(pattern=f['pattern'], color=f['color'])
     
     fabric.content = f['composition']
     fabric.handling = f['handling']
     fabric.grade = f['grade']
     fabric.repeat = f['repeat']
     fabric.units = 'yd'
     fabric.type = 'fabric'
     fabric.save()
     
     filename = "{0} Col: {1}".format(fabric.pattern, fabric.color)
     fabric.description = filename
     fabric.save()
     
     print fabric.id, fabric.description
     
     try:
         product = Product.objects.get(supply=fabric, supplier=supplier)
     except Product.DoesNotExist:
         product = Product(supply=fabric, supplier=supplier)
         
     product.purchasing_units = 'yd'
     try:
         product.cost = Decimal(fabric.grade) * Decimal('1.10')
コード例 #3
0
    supplier = Supplier.objects.get(pk=76)

    for f in fabrics:
        try:
            fabric = Fabric.objects.get(pattern=f['pattern'], color=f['color'])
        except Fabric.DoesNotExist:
            fabric = Fabric(pattern=f['pattern'], color=f['color'])

        fabric.content = f['composition']
        fabric.handling = f['handling']
        fabric.grade = f['grade']
        fabric.repeat = f['repeat']
        fabric.units = 'yd'
        fabric.type = 'fabric'
        fabric.save()

        filename = "{0} Col: {1}".format(fabric.pattern, fabric.color)
        fabric.description = filename
        fabric.save()

        print fabric.id, fabric.description

        try:
            product = Product.objects.get(supply=fabric, supplier=supplier)
        except Product.DoesNotExist:
            product = Product(supply=fabric, supplier=supplier)

        product.purchasing_units = 'yd'
        try:
            product.cost = Decimal(fabric.grade) * Decimal('1.10')
コード例 #4
0
ファイル: tests.py プロジェクト: charliephairoj/backend
class LogTestCase(APITestCase):
    def setUp(self):
        """
        Set up for log tests
        """
        self.fabric = Fabric(pattern="Max",
                             color="Grey",
                             quantity="12",
                             units='yd',
                             description="Max Col: Grey")
        self.fabric.save()
        self.log = Log.objects.create(message="Reserved 5yd",
                                      acknowledgement_id=1002,
                                      action="RESERVE",
                                      quantity=10,
                                      supply=self.fabric)

    def test_cut_fabric(self):

        data = {
            'id': 1,
            'message': 'Reserve 5yd',
            'action': "CUT",
            'quantity': 8,
            'supply': {
                'id': 1,
                'image': {
                    'id': 100
                }
            }
        }
        resp = self.client.put('/api/v1/log/1/', data=data, format='json')

        self.assertEqual(resp.status_code, 200, msg=resp)

        log_data = resp.data

        self.assertEqual(log_data['id'], 1)
        self.assertEqual(log_data['message'],
                         "8yd of Max Col: Grey cut for Ack #1002")
        self.assertEqual(Decimal(log_data['quantity']), Decimal('8'))
        self.assertEqual(log_data['acknowledgement_id'], '1002')
        self.assertEqual(log_data['action'], "SUBTRACT")

        fabric = Fabric.objects.get(pk=1)
        self.assertEqual(fabric.quantity, 4)

    def test_cancel_fabric_reservation(self):

        data = {
            'id': 1,
            'message': 'Reserve 5yd',
            'action': "CANCEL",
            'quantity': 10,
            'supply': {
                'id': 1,
                'image': {
                    'id': 100
                }
            }
        }
        resp = self.client.put('/api/v1/log/1/', data=data, format='json')

        self.assertEqual(resp.status_code, 200, msg=resp)

        log_data = resp.data

        self.assertEqual(log_data['id'], 1)
        self.assertEqual(
            log_data['message'],
            "Cancelled reservation of Max Col: Grey for Ack #1002")
        self.assertEqual(Decimal(log_data['quantity']), Decimal('10'))
        self.assertEqual(log_data['acknowledgement_id'], '1002')
        self.assertEqual(log_data['action'], "CANCELLED")

        fabric = Fabric.objects.get(pk=1)
        self.assertEqual(fabric.quantity, 12)
コード例 #5
0
ファイル: tests.py プロジェクト: charliephairoj/backend
class LogTestCase(APITestCase):
    
    def setUp(self):
        """
        Set up for log tests
        """
        self.fabric = Fabric(pattern="Max", color="Grey", quantity="12", units='yd',
                             description="Max Col: Grey")
        self.fabric.save()
        self.log = Log.objects.create(message="Reserved 5yd", acknowledgement_id=1002, 
                                      action="RESERVE", quantity=10, supply=self.fabric)
                                      
    def test_cut_fabric(self):
        
        data = {'id': 1, 'message': 'Reserve 5yd', 'action': "CUT", 'quantity': 8,
                'supply': {'id': 1, 'image': {'id': 100}}}
        resp = self.client.put('/api/v1/log/1/', data=data, format='json')
        
        self.assertEqual(resp.status_code, 200, msg=resp)
        
        log_data = resp.data
        
        self.assertEqual(log_data['id'], 1)
        self.assertEqual(log_data['message'], "8yd of Max Col: Grey cut for Ack #1002")
        self.assertEqual(Decimal(log_data['quantity']), Decimal('8'))
        self.assertEqual(log_data['acknowledgement_id'], '1002')
        self.assertEqual(log_data['action'], "SUBTRACT")
        
        fabric = Fabric.objects.get(pk=1)
        self.assertEqual(fabric.quantity, 4)
        
    def test_cancel_fabric_reservation(self):
        
        data = {'id': 1, 'message': 'Reserve 5yd', 'action': "CANCEL", 'quantity': 10,
                'supply': {'id': 1, 'image': {'id': 100}}}
        resp = self.client.put('/api/v1/log/1/', data=data, format='json')
        
        self.assertEqual(resp.status_code, 200, msg=resp)
        
        log_data = resp.data
        
        self.assertEqual(log_data['id'], 1)
        self.assertEqual(log_data['message'], "Cancelled reservation of Max Col: Grey for Ack #1002")
        self.assertEqual(Decimal(log_data['quantity']), Decimal('10'))
        self.assertEqual(log_data['acknowledgement_id'], '1002')
        self.assertEqual(log_data['action'], "CANCELLED")
        
        fabric = Fabric.objects.get(pk=1)
        self.assertEqual(fabric.quantity, 12)