File: test_merchant_order.py

package info (click to toggle)
python-mercadopago 2.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,104 kB
  • sloc: python: 2,191; makefile: 4
file content (68 lines) | stat: -rw-r--r-- 2,200 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""
    Module: test_merchant_order
"""
import os
import unittest
import uuid
import mercadopago


class TestMerchantOrder(unittest.TestCase):
    """
    Test Module: Merchant Order
    """
    sdk = mercadopago.SDK(os.environ['ACCESS_TOKEN'])

    def test_all(self):
        """
        Test Function: Merchant Order
        """
        preference_object = {
            "items": [
                {
                    "description": "Test Update Success",
                    "id": "5678",
                    "picture_url": "http://product1.image.png",
                    "quantity": 1,
                    "title": "Item 1",
                    "currency_id": "BRL",
                    "unit_price": 20.5
                }
            ]
        }

        preference_saved = self.sdk.preference().create(preference_object)
        merchant_order_object = {
            "preference_id": preference_saved["response"]["id"],
            "site_id": "MLB",
            "notification_url": "https://seller/notification",
            "additional_info": "Aditional info",
            "external_reference": str(uuid.uuid4().int),
            "marketplace": "NONE",
            "items": [{
                "description": "Test Update Success",
                "id": "5678",
                "picture_url": "http://product1.image.png",
                "quantity": 1,
                "title": "Item 1",
                "currency_id": "BRL",
                "unit_price": 20.5
            }]
        }

        merchant_order_created = self.sdk.merchant_order().create(merchant_order_object)
        self.assertEqual(merchant_order_created["status"], 201)

        merchant_order_updated = self.sdk.merchant_order().update(
            merchant_order_created["response"]["id"], {"additional_info": "Info 2"})
        self.assertEqual(merchant_order_updated["status"], 200)

        merchant_order_finded = self.sdk.merchant_order().get(
            merchant_order_created["response"]["id"])
        self.assertEqual(merchant_order_finded["status"], 200)
        self.assertEqual(
            merchant_order_finded["response"]["additional_info"], "Info 2")


if __name__ == "__main__":
    unittest.main()