def test_create_order_event_failed_twice(mock_callback_api, client, default_outcome_transaction): trx = Transaction(**default_outcome_transaction) trx.stp_id = DEFAULT_ORDEN_ID trx.save() id_trx = trx.id data = dict(id=DEFAULT_ORDEN_ID, Estado='DEVOLUCION', Detalle="0") resp = client.post('/orden_events', json=data) assert resp.status_code == 200 assert resp.data == "got it!".encode() trx = Transaction.objects.get(id=id_trx) assert trx.estado is Estado.failed num_events = len(trx.events) data = dict(id=DEFAULT_ORDEN_ID, Estado='DEVOLUCION', Detalle="0") resp = client.post('/orden_events', json=data) assert resp.status_code == 200 assert resp.data == "got it!".encode() trx = Transaction.objects.get(id=id_trx) assert trx.estado is Estado.failed assert len(trx.events) == num_events trx.delete() trx.delete()
def test_transaction_constraints(): transaction_data = dict( concepto_pago='PRUEBA', institucion_ordenante='646', cuenta_beneficiario='072691004495711499', institucion_beneficiaria='072', monto=1020, nombre_beneficiario='Rogelio Lopez', nombre_ordenante='BANCO', cuenta_ordenante='646180157000000004', rfc_curp_ordenante='ND', speid_id='speid_id', fecha_operacion=datetime.today(), clave_rastreo='abc123', ) transaction = Transaction(**transaction_data) transaction.save() assert transaction.id is not None assert transaction.compound_key is not None # Unique-Spare Index skip documents that not contains compound_key # and not allow saving duplicated values second_transaction = Transaction(**transaction_data) with pytest.raises(NotUniqueError): second_transaction.save() assert second_transaction.compound_key == transaction.compound_key assert second_transaction.id is None transaction.delete()
def test_send_order(create_account): transaction = Transaction( concepto_pago='PRUEBA', institucion_ordenante='90646', cuenta_beneficiario='072691004495711499', institucion_beneficiaria='40072', monto=1020, nombre_beneficiario='Ricardo Sánchez Castillo de la Mancha S.A. de CV', nombre_ordenante=' Ricardo Sánchez Castillo de la Mancha S.A. de CV', cuenta_ordenante='646180157000000004', rfc_curp_ordenante='ND', speid_id='speid_id', tipo_cuenta_beneficiario=40, ) order = transaction.create_order() assert order.institucionOperante == transaction.institucion_ordenante assert order.institucionContraparte == transaction.institucion_beneficiaria assert order.monto == 10.20 assert transaction.clave_rastreo == order.claveRastreo assert transaction.tipo_cuenta_beneficiario == order.tipoCuentaBeneficiario assert transaction.rfc_curp_beneficiario == order.rfcCurpBeneficiario assert transaction.referencia_numerica == order.referenciaNumerica assert order.nombreBeneficiario == ('Ricardo Sanchez Castillo de la Mancha' ' S') assert order.nombreOrdenante == 'Ricardo Sanchez Castillo de la Mancha S' assert len(order.nombreBeneficiario) == 39 assert len(order.nombreOrdenante) == 39 order = transaction.create_order() assert transaction.stp_id == order.id transaction.delete()
def test_event(): received = Event(type=EventType.received) completed = Event(type=EventType.completed) transaction = Transaction(events=[received, completed]) transaction.save() id_trx = transaction.id transaction = Transaction.objects.get(id=id_trx) assert len(transaction.events) == 2 assert transaction.events[0].type == received.type assert transaction.events[1].type == completed.type transaction.delete()
def test_invalid_id_order_event(client, default_outcome_transaction): trx = Transaction(**default_outcome_transaction) trx.stp_id = DEFAULT_ORDEN_ID trx.save() id_trx = trx.id data = dict(id='9', Estado='LIQUIDACION', Detalle="0") resp = client.post('/orden_events', json=data) assert resp.status_code == 200 assert resp.data == "got it!".encode() trx = Transaction.objects.get(id=id_trx) assert trx.estado is Estado.submitted trx.delete()
def test_reverse_transaction(client, default_outcome_transaction, mock_callback_api): trx = Transaction(**default_outcome_transaction) trx.stp_id = DEFAULT_ORDEN_ID trx.save() assert trx.estado is Estado.submitted resp = client.get('/transactions?' 'status=submitted&prefix_ordenante=6461801570') assert resp.status_code == 200 resp = client.patch(f'/transactions/{resp.json[0]["_id"]["$oid"]}/reverse') assert resp.status_code == 201 trx = Transaction.objects.get(id=resp.json["_id"]["$oid"]) assert trx.estado is Estado.failed trx.delete()
def test_process_transaction(client, default_outcome_transaction): trx = Transaction(**default_outcome_transaction) trx.stp_id = DEFAULT_ORDEN_ID trx.save() assert trx.estado is Estado.submitted resp = client.get('/transactions?' 'status=submitted&prefix_ordenante=6461801570') assert resp.status_code == 200 resp = client.patch(f'/transactions/{resp.json[0]["_id"]["$oid"]}/process') assert resp.status_code == 201 trx = Transaction.objects.get(id=resp.json["_id"]["$oid"]) assert trx.estado is Estado.submitted assert trx.stp_id is not None trx.delete()
def transaction(): transaction = Transaction( concepto_pago='PRUEBA', institucion_ordenante='90646', cuenta_beneficiario='072691004495711499', institucion_beneficiaria='40072', monto=1020, nombre_beneficiario='Ricardo Sánchez', nombre_ordenante='BANCO', cuenta_ordenante='646180157000000004', rfc_curp_ordenante='ND', speid_id='speid_id', ) transaction.save() yield transaction transaction.delete()
def outcome_transaction() -> Generator[Transaction, None, None]: transaction = Transaction( stp_id=2456305, concepto_pago='PRUEBA', institucion_ordenante='90646', cuenta_beneficiario='072691004495711499', institucion_beneficiaria='40072', monto=2511, nombre_beneficiario='Ricardo Sánchez', tipo_cuenta_beneficiario=40, nombre_ordenante='BANCO', cuenta_ordenante='646180157000000004', rfc_curp_ordenante='ND', speid_id='go' + datetime.now().strftime('%m%d%H%M%S'), version=1, ) transaction.save() yield transaction transaction.delete()
def test_order_event_duplicated(client, default_outcome_transaction, mock_callback_api): trx = Transaction(**default_outcome_transaction) trx.stp_id = DEFAULT_ORDEN_ID trx.save() id_trx = trx.id data = dict(id=DEFAULT_ORDEN_ID, Estado='LIQUIDACION', Detalle="0") resp = client.post('/orden_events', json=data) assert resp.status_code == 200 assert resp.data == "got it!".encode() data = dict(id=DEFAULT_ORDEN_ID, Estado='DEVOLUCION', Detalle="0") resp = client.post('/orden_events', json=data) assert resp.status_code == 200 assert resp.data == "got it!".encode() trx = Transaction.objects.get(id=id_trx) assert trx.estado is Estado.failed trx.delete()
def test_fail_send_order_no_account_registered(): transaction = Transaction( concepto_pago='PRUEBA', institucion_ordenante='90646', cuenta_beneficiario='072691004495711499', institucion_beneficiaria='40072', monto=1020, nombre_beneficiario='Ricardo Sánchez Castillo de la Mancha S.A. de CV', nombre_ordenante=' Ricardo Sánchez Castillo de la Mancha S.A. de CV', cuenta_ordenante='646180157000000004', rfc_curp_ordenante='ND', speid_id='speid_id', tipo_cuenta_beneficiario=40, ) transaction_id = transaction.save().id with pytest.raises(MalformedOrderException): transaction.create_order() transaction = Transaction.objects.get(id=transaction_id) assert transaction.estado is Estado.error transaction.delete()
def test_transaction(): transaction = Transaction( concepto_pago='PRUEBA', institucion_ordenante='646', cuenta_beneficiario='072691004495711499', institucion_beneficiaria='072', monto=1020, nombre_beneficiario='Ricardo Sánchez', nombre_ordenante='BANCO', cuenta_ordenante='646180157000000004', rfc_curp_ordenante='ND', speid_id='speid_id', ) transaction.events.append(Event(type=EventType.created)) transaction.events.append(Event(type=EventType.received)) transaction.events.append(Event(type=EventType.retry)) transaction.events.append(Event(type=EventType.retry)) transaction.events.append(Event(type=EventType.error)) transaction.events.append(Event(type=EventType.completed)) transaction.save() trx_saved = Transaction.objects.get(id=transaction.id) assert transaction.concepto_pago == trx_saved.concepto_pago assert transaction.institucion_beneficiaria == ( trx_saved.institucion_beneficiaria) assert transaction.cuenta_beneficiario == trx_saved.cuenta_beneficiario assert transaction.institucion_beneficiaria == ( trx_saved.institucion_beneficiaria) assert transaction.monto == trx_saved.monto assert transaction.nombre_beneficiario == trx_saved.nombre_beneficiario assert transaction.nombre_ordenante == trx_saved.nombre_ordenante assert transaction.cuenta_ordenante == trx_saved.cuenta_ordenante assert transaction.rfc_curp_ordenante == trx_saved.rfc_curp_ordenante assert transaction.speid_id == trx_saved.speid_id assert len(trx_saved.events) == 6 transaction.delete()