예제 #1
0
 def test_valid_doc_status_value(self, process_transaction_mock):
     xml = b"""<?xml version="1.0" encoding="windows-1251"?>
                 <root method_name="PRTrans">
                   <record>
                     <ref>1</ref>
                     <doc_sq>18.44</doc_sq>
                     <doc_datd>2020-05-11T00:00:00+02:00</doc_datd>
                     <doc_nam_a>Test</doc_nam_a>
                     <doc_iban_a>UA678201720355110002000080850</doc_iban_a>
                     <doc_nam_b>Test</doc_nam_b>
                     <doc_iban_b>UA098201720355179002000014715</doc_iban_b>
                     <msrprd_date>2020-03-11T00:00:00+02:00</msrprd_date>
                     <id_contract>11C2E7D03AF649668BF9FFB1D0EF767D</id_contract>
                     <doc_status>222222222</doc_status>
                   </record>
                 </root>"""
     response = self.client.post(
         '/treasury',
         data=prepare_request(xml),
         headers={"Content-Type": "application/xml"})
     self.assertEqual(
         response.data, b'<?xml version="1.0" encoding="UTF-8"?>'
         b"<Body><Response>"
         b"<ResultCode>30</ResultCode>"
         b"<ResultMessage>'doc_status' should be 0 or -1</ResultMessage>"
         b"</Response></Body>")
     self.assertEqual(response.status_code, 400)
     process_transaction_mock.assert_not_called()
예제 #2
0
 def test_incorrect_fields_type(self, db_insert_one_mock):
     xml = b"""<?xml version="1.0" encoding="windows-1251"?>
                 <root method_name="Obligation">
                       <record id="124">
                         <pmt_date>2020-03-05T17:37:23+02:00</pmt_date>
                         <pmt_status>0</pmt_status>
                         <pmt_sum>1161960</pmt_sum>
                         <contractId>11C2E7D03AF649668BF9FFB1D0EF767D</contractId>
                         </record>
                     <record id="125">
                         <pmt_date>NOT DATE</pmt_date>
                         <pmt_status>1</pmt_status>
                         <pmt_sum>1161960.00</pmt_sum>
                         <contractId>11C2E7D03AF649668BF9FFB1D0EF767D</contractId>
                     </record>
                 </root>"""
     response = self.client.post(
         '/treasury',
         data=prepare_request(xml,
                              method_name='Obligation',
                              should_compress=False),
         headers={"Content-Type": "application/xml"})
     self.assertEqual(
         response.data, b'<?xml version="1.0" encoding="windows-1251"?>'
         b'<root>'
         b'<record id="124" result_code="0"/>'
         b'<record id="125" result_code="30" '
         b'result_text="pmt_date has incorrect data type"/>'
         b'</root>')
     self.assertEqual(response.status_code, 200)
     db_insert_one_mock.assert_called_once()
예제 #3
0
 def test_invalid_password(self, process_transaction_mock):
     response = self.client.post(
         '/treasury',
         data=prepare_request(b"", password="******"),
         headers={"Content-Type": "application/xml"})
     self.assertEqual(
         response.data, b'<?xml version="1.0" encoding="UTF-8"?>'
         b'<Body><Response>'
         b'<ResultCode>10</ResultCode>'
         b'<ResultMessage>Invalid login or password</ResultMessage></Response>'
         b'</Body>')
     self.assertEqual(response.status_code, 403)
     process_transaction_mock.assert_not_called()
예제 #4
0
 def test_invalid_bas64(self, process_transaction_mock):
     xml = b"abc"
     response = self.client.post(
         '/treasury',
         data=prepare_request(xml, should_encode=False, should_compress=False),
         headers={"Content-Type": "application/xml"}
     )
     self.assertEqual(
         response.data,
         b'<?xml version="1.0" encoding="UTF-8"?>'
         b'<Body><Response>'
         b'<ResultCode>80</ResultCode>'
         b'<ResultMessage>Data base64 error: Incorrect padding</ResultMessage>'
         b'</Response></Body>'
     )
     self.assertEqual(response.status_code, 400)
     process_transaction_mock.assert_not_called()
예제 #5
0
 def test_invalid_xml(self, process_transaction_mock):
     xml = b"<test>Hello, xml!<test>"
     response = self.client.post(
         '/treasury',
         data=prepare_request(xml),
         headers={"Content-Type": "application/xml"}
     )
     self.assertEqual(
         response.data,
         b'<?xml version="1.0" encoding="UTF-8"?>'
         b"<Body><Response>"
         b"<ResultCode>80</ResultCode>"
         b"<ResultMessage>Invalid request xml: EndTag: '&lt;/' not found, line 1,"
         b" column 24 (&lt;string&gt;, line 1)</ResultMessage>"
         b"</Response></Body>"
     )
     self.assertEqual(response.status_code, 400)
     process_transaction_mock.assert_not_called()
예제 #6
0
    def test_parse_empty_transaction_xml(self, process_transaction_mock):
        xml = b"""<?xml version="1.0" encoding="windows-1251"?>
            <root method_name="PRTrans">
            </root>"""

        response = self.client.post(
            '/treasury',
            data=prepare_request(xml),
            headers={"Content-Type": "application/xml"})

        self.assertEqual(
            response.data, b'<?xml version="1.0" encoding="UTF-8"?>'
            b"<Body><Response>"
            b"<ResultCode>80</ResultCode>"
            b"<ResultMessage>Empty PRTrans Data xml</ResultMessage>"
            b"</Response></Body>")
        self.assertEqual(response.status_code, 400)
        process_transaction_mock.assert_not_called()
예제 #7
0
 def test_incorrect_record_id_type(self, db_insert_one_mock):
     xml = b"""<?xml version="1.0" encoding="windows-1251"?>
                 <root method_name="Obligation">
                     <record id="ABC_STRING001">
                         <pmt_date>2020-03-05T17:37:23+02:00</pmt_date>
                         <pmt_status>0</pmt_status>
                         <pmt_sum>1161960</pmt_sum>
                         <contractId>11C2E7D03AF649668BF9FFB1D0EF767D</contractId>
                     </record>
                 </root>"""
     response = self.client.post(
         '/treasury',
         data=prepare_request(xml,
                              method_name='Obligation',
                              should_compress=False),
         headers={"Content-Type": "application/xml"})
     self.assertEqual(
         response.data, b'<?xml version="1.0" encoding="UTF-8"?>'
         b'<Body><Response>'
         b'<ResultCode>30</ResultCode><ResultMessage>Record id has incorrect data type</ResultMessage>'
         b'</Response></Body>')
     self.assertEqual(response.status_code, 400)
     db_insert_one_mock.assert_not_called()