Skip to content

Commit

Permalink
Merge pull request #7 from yoomoney/release/v2.1.3
Browse files Browse the repository at this point in the history
Release/2.1.3
  • Loading branch information
tonchik-tm authored Sep 10, 2021
2 parents 3aa313f + 0c374a5 commit 09fdb34
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 12 deletions.
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
language: python
python:
- "3.4"
- "3.5"
- "3.6"
- "3.7"
- "3.9"
- "3.8"
- "3.7"
- "3.6"
- "3.5"
- "3.4"
matrix:
include:
- python: 2.7
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### v2.1.3 от 10.09.2021
* Добавлена обработка metadata в transfers

### v2.1.2 от 04.06.2021
* Поправлена валидация чека

Expand Down
2 changes: 1 addition & 1 deletion src/yookassa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@

__author__ = "YooMoney"
__email__ = '[email protected]'
__version__ = '2.1.2'
__version__ = '2.1.3'
11 changes: 11 additions & 0 deletions src/yookassa/domain/models/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Transfer(BaseObject):

__platform_fee_amount = None

__metadata = None

@property
def account_id(self):
return self.__account_id
Expand Down Expand Up @@ -48,3 +50,12 @@ def platform_fee_amount(self, value):
self.__platform_fee_amount = value
else:
raise TypeError('Invalid transfer.platform_fee_amount value type')

@property
def metadata(self):
return self.__metadata

@metadata.setter
def metadata(self, value):
if type(value) is dict:
self.__metadata = value
11 changes: 11 additions & 0 deletions src/yookassa/domain/response/transfer_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class TransferResponse(BaseObject):

__status = None

__metadata = None

@property
def account_id(self):
return self.__account_id
Expand Down Expand Up @@ -59,6 +61,15 @@ def status(self):
def status(self, value):
self.__status = str(value)

@property
def metadata(self):
return self.__metadata

@metadata.setter
def metadata(self, value):
if type(value) is dict:
self.__metadata = value


class TransferStatus(object):
"""
Expand Down
6 changes: 5 additions & 1 deletion test/unit/test_any_list_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ def test_response_cast_payment(self):
"value": 100.01,
"currency": "RUB"
},
"status": "succeeded"
"status": "succeeded",
"metadata": {
"meta1": 'metatest 1',
"meta2": 'metatest 2'
}
}
],
"income_amount": {
Expand Down
28 changes: 27 additions & 1 deletion test/unit/test_payment_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ def test_request_cast(self):
"platform_fee_amount": {
"value": 10.01,
"currency": Currency.RUB
},
"metadata": {
"meta1": 'metatest 1',
"meta2": 'metatest 2'
}
}))

Expand Down Expand Up @@ -152,6 +156,10 @@ def test_request_cast(self):
"platform_fee_amount": {
"value": 10.01,
"currency": Currency.RUB
},
"metadata": {
"meta1": 'metatest 1',
"meta2": 'metatest 2'
}
}
]
Expand Down Expand Up @@ -211,6 +219,23 @@ def test_request_setters(self):
}
]
},
'transfers': [
{
'account_id': '79990000000',
"amount": {
"value": 100.01,
"currency": Currency.RUB
},
"platform_fee_amount": Amount({
"value": 10.01,
"currency": Currency.RUB
}),
"metadata": {
"meta1": 'metatest 1',
"meta2": 'metatest 2'
}
}
],
'metadata': {'key': 'value'}
})

Expand All @@ -220,6 +245,7 @@ def test_request_setters(self):
self.assertIsInstance(request.recipient, Recipient)
self.assertIsInstance(request.payment_method_data, PaymentData)
self.assertIsInstance(request.airline, Airline)
self.assertIsInstance(request.transfers, list)

with self.assertRaises(TypeError):
request.receipt = 'invalid receipt'
Expand Down Expand Up @@ -247,7 +273,7 @@ def test_request_setters(self):
request.airline = 'Invalid airline'

with self.assertRaises(TypeError):
request.transfers = 'Invalid airline'
request.transfers = 'Invalid transfers'

def test_request_validate(self):
request = PaymentRequest()
Expand Down
8 changes: 8 additions & 0 deletions test/unit/test_payment_request_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ def test_build_object(self):
"platform_fee_amount": {
"value": 10.01,
"currency": Currency.RUB
},
"metadata": {
"meta1": 'metatest 1',
"meta2": 'metatest 2'
}
}
])
Expand Down Expand Up @@ -109,6 +113,10 @@ def test_build_object(self):
"platform_fee_amount": {
"value": 10.01,
"currency": Currency.RUB
},
"metadata": {
"meta1": 'metatest 1',
"meta2": 'metatest 2'
}
}]
}, dict(request))
12 changes: 10 additions & 2 deletions test/unit/test_payment_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ def test_response_cast(self):
"value": 10.01,
"currency": Currency.RUB
},
"status": "succeeded"
"status": "succeeded",
"metadata": {
"meta1": 'metatest 1',
"meta2": 'metatest 2'
}
}
],
"income_amount": {
Expand Down Expand Up @@ -140,7 +144,11 @@ def test_response_cast(self):
"value": 10.01,
"currency": Currency.RUB
},
"status": TransferStatus.SUCCEEDED
"status": TransferStatus.SUCCEEDED,
"metadata": {
"meta1": 'metatest 1',
"meta2": 'metatest 2'
}
}))

response.transfers = None
Expand Down
9 changes: 9 additions & 0 deletions test/unit/test_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,28 @@ def test_receipt_cast(self):
"value": '100.01',
"currency": Currency.RUB
})
transfer.metadata = {
"meta1": 'metatest 1',
"meta2": 'metatest 2'
}

self.assertEqual({
'account_id': '79990000000',
"amount": {
"value": 100.01,
"currency": Currency.RUB
},
"metadata": {
"meta1": 'metatest 1',
"meta2": 'metatest 2'
}
}, dict(transfer))

self.assertEqual('79990000000', transfer.account_id)

self.assertEqual({"value": 100.01, "currency": Currency.RUB}, dict(transfer.amount))
self.assertEqual(float(transfer.amount.value), 100.01)
self.assertEqual({"meta1": 'metatest 1', "meta2": 'metatest 2'}, dict(transfer.metadata))

with self.assertRaises(TypeError):
transfer.amount = 'invalid type'
24 changes: 21 additions & 3 deletions test/unit/test_transfer_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,30 @@ def test_transfer_cast(self):
"value": '100.01',
"currency": Currency.RUB
})
transfer.metadata = {
"meta1": 'metatest 1',
"meta2": 'metatest 2'
}

self.assertEqual({
"account_id": "79990000000",
"amount": {
"value": 100.01,
"currency": Currency.RUB
},
"status": TransferStatus.SUCCEEDED
"status": TransferStatus.SUCCEEDED,
"metadata": {
"meta1": 'metatest 1',
"meta2": 'metatest 2'
}
}, dict(transfer))

self.assertEqual('79990000000', transfer.account_id)
self.assertEqual(TransferStatus.SUCCEEDED, transfer.status)

self.assertEqual({"value": 100.01, "currency": Currency.RUB}, dict(transfer.amount))
self.assertEqual(float(transfer.amount.value), 100.01)
self.assertEqual({"meta1": 'metatest 1', "meta2": 'metatest 2'}, dict(transfer.metadata))

with self.assertRaises(TypeError):
transfer.amount = 'invalid type'
Expand All @@ -43,7 +52,11 @@ def test_transfer_value(self):
"value": 100.01,
"currency": Currency.RUB
},
"status": TransferStatus.SUCCEEDED
"status": TransferStatus.SUCCEEDED,
"metadata": {
"meta1": 'metatest 1',
"meta2": 'metatest 2'
}
})

self.assertEqual({
Expand All @@ -52,11 +65,16 @@ def test_transfer_value(self):
"value": 100.01,
"currency": Currency.RUB
},
"status": TransferStatus.SUCCEEDED
"status": TransferStatus.SUCCEEDED,
"metadata": {
"meta1": 'metatest 1',
"meta2": 'metatest 2'
}
}, dict(transfer))

self.assertEqual('79990000000', transfer.account_id)
self.assertEqual(TransferStatus.SUCCEEDED, transfer.status)

self.assertEqual({"value": 100.01, "currency": Currency.RUB}, dict(transfer.amount))
self.assertEqual(float(transfer.amount.value), 100.01)
self.assertEqual({"meta1": 'metatest 1', "meta2": 'metatest 2'}, dict(transfer.metadata))

0 comments on commit 09fdb34

Please sign in to comment.