Skip to content

Commit

Permalink
Reverse cambios change STP status lookup to a dict (#56) (#72)
Browse files Browse the repository at this point in the history
Se envía Liquidación a toda respuesta hacia stp
  • Loading branch information
pachCode authored Apr 6, 2019
1 parent 9ee706e commit 1b397bb
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 13 deletions.
28 changes: 28 additions & 0 deletions migrations/versions/4e043705435c_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""empty message
Revision ID: 4e043705435c
Revises: 2773ca239148
Create Date: 2019-04-06 01:00:59.333771
"""
import sqlalchemy as sa
from alembic import op


# revision identifiers, used by Alembic.
revision = '4e043705435c'
down_revision = '2773ca239148'
branch_labels = None
depends_on = None


def upgrade():

op.drop_constraint(
'transactions_orden_id_key', 'transactions', type_='unique')


def downgrade():

op.create_unique_constraint(
'transactions_orden_id_key', 'transactions', ['orden_id'])
2 changes: 1 addition & 1 deletion speid/tables/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
transactions = db.Table(
'transactions',
cols.id('tr'), cols.created_at(), cols.updated_at(),
Column('orden_id', Integer, unique=True), # STP Ordenes.clave
Column('orden_id', Integer, unique=False), # STP Ordenes.clave
Column('fecha_operacion', Date, nullable=False),
Column('institucion_ordenante', String, nullable=False),
Column('institucion_beneficiaria', String, nullable=False),
Expand Down
22 changes: 12 additions & 10 deletions speid/tables/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class HttpRequestMethod(Enum):

class State(Enum):
created = 'CREATE' # When a transaction has been received
retry = 'RETRY' # When the transaction has been retry
retry = 'RETRY' # When the transaction has been retry
completed = 'COMPLETE' # The request was processed with no errors
error = 'ERROR' # Something happened when the response was obtained
received = 'RECEIVED' # When we get the response from a transaction made
Expand All @@ -22,14 +22,16 @@ class Estado(Enum):

@classmethod
def get_state_from_stp(cls, stp_state):
status_from_stp = dict(
LIQUIDACION=cls.succeeded,
DEVOLUCION=cls.failed)
return status_from_stp.get(stp_state, cls.error)
if stp_state == 'LIQUIDACION':
return cls.succeeded
if stp_state == 'DEVOLUCION':
return cls.failed
return cls.error

@classmethod
def convert_to_stp_state(cls, status):
status_to_stp = dict(
(cls.succeeded, 'LIQUIDACION'),
(cls.failed, 'DEVOLUCION'))
return status_to_stp.get(status, 'DEVOLUCION')
def convert_to_stp_state(cls, state):
if state == cls.succeeded:
return 'LIQUIDACION'
if state == cls.failed:
return 'DEVOLUCION'
return 'DEVOLUCION'
4 changes: 3 additions & 1 deletion speid/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ def create_orden():
r = request.json
r['estado'] = Estado.convert_to_stp_state(Estado(response['status']))
except Exception as exc:
r = dict(estado='DEVOLUCION')
r = dict(estado='LIQUIDACION')
transaction.type = State.error
db.session.commit()
capture_exception(exc)
return make_response(jsonify(r), 201)

Expand Down
2 changes: 1 addition & 1 deletion test/cassettes/test_create_order.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interactions:
method: POST
uri: https://testapi/set
response:
body: {string: '{"status": "success"}'}
body: {string: '{"status": "succeeded"}'}
headers:
Connection: [keep-alive]
Content-Encoding: [application/x-www-form-urlencoded]
Expand Down
28 changes: 28 additions & 0 deletions test/test_receive_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,31 @@ def test_create_order_without_ordenante(self, app):
content_type='application/json')

assert res.status_code == 201

def test_create_fail_orden(self, app):
thread = ConsumerThread()
thread.start()
data = dict(
Clave=123123233,
FechaOperacion=20190129,
InstitucionOrdenante=40102,
InstitucionBeneficiaria=90646,
ClaveRastreo='MANU-00000295251',
Monto=1000,
NombreOrdenante='null',
TipoCuentaOrdenante=0,
CuentaOrdenante='null',
RFCCurpOrdenante='null',
NombreBeneficiario='JESUS ADOLFO ORTEGA TURRUBIATES',
TipoCuentaBeneficiario=40,
CuentaBeneficiario='646180157020812599',
RFCCurpBeneficiario='ND',
ConceptoPago='FONDEO',
ReferenciaNumerica=1232134,
Empresa='TAMIZI'
)
res = app.post('/ordenes', data=json.dumps(data),
content_type='application/json')

assert res.status_code == 201
assert res.json['estado'] == 'LIQUIDACION'

0 comments on commit 1b397bb

Please sign in to comment.