Exemplo n.º 1
0
 def test_invalid_date(self):
     """
     Verify failure with invalid values for date field
     """
     serializer = InvoiceSerializer(
         data={
             'branch_id': str(uuidv4()),
             'vendor': self.get_vendor_data(),
             'invoice_num': self.get_invoice_num(),
             'date': "2020",
             'total_amount': "100.0",
             'items': self.get_items_data(),
             'document_id': str(uuidv4())
         })
     self.assertEqual(False, serializer.is_valid())
Exemplo n.º 2
0
 def test_valid_data(self):
     """
     Verify successful validation of valid input data
     """
     serializer = InvoiceSerializer(
         data={
             'branch_id': str(uuidv4()),
             'vendor': self.get_vendor_data(),
             'invoice_num': self.get_invoice_num(),
             'date': "2020-06-14",
             'total_amount': "100.0",
             'items': self.get_items_data(),
             'document_id': str(uuidv4())
         })
     self.assertEqual(True, serializer.is_valid())
     self.assertEqual(100.0, serializer.validated_data['total_amount'])
Exemplo n.º 3
0
 def test_invalid_branch_id(self):
     """
     the "branch_id" should be a valid uuid. Other values must be treated as invalid values
     """
     serializer = InvoiceSerializer(
         data={
             'vendor': self.get_vendor_data(),
             'invoice_num': self.get_invoice_num(),
             'date': "2020-06-14",
             'total_amount': "100.0",
             'items': self.get_items_data(),
             'document_id': str(uuidv4())
         })
     self.assertEqual(serializer.is_valid(), False)
     self.assertDictEqual(
         serializer.errors, {
             'branch_id': [
                 ErrorDetail(string='This field is required.',
                             code='required')
             ]
         })
Exemplo n.º 4
0
 def test_unknown_fields(self):
     """
     Verify failure with unknown fields
     """
     serializer = InvoiceSerializer(data={'some_field': 'some_value'})
     self.assertEqual(False, serializer.is_valid())
Exemplo n.º 5
0
 def test_empty_data(self):
     """
     Verify failure with empty data
     """
     serializer = InvoiceSerializer(data={})
     self.assertEqual(False, serializer.is_valid())