Exemplo n.º 1
0
    def test_passing_api(self):
        """
        Check that api objects are passed on to new resources when given
        """

        class DummyAPI(object):
            def post(self, *a, **k): pass

            def get(self, *a, **k): pass

        api = DummyAPI()

        # Conversion
        resource = Resource({'name': 'testing', }, api=api)
        assert resource.api == api
        convert_ret = resource.convert('test', {})
        assert convert_ret.api == api

        class TestResource(Find, List, Post):
            path = '/'

        # Find
        find = TestResource.find('resourceid', api=api)
        assert find.api == api

        # List
        list_ = TestResource.all(api=api)
        assert list_.api == api

        # Post
        post = TestResource({'id': 'id'}, api=api)
        post_ret = post.post('test')
        assert post_ret.api == api
Exemplo n.º 2
0
 def test_to_dict(self):
     data = {
         "intent": "sale",
         "payer": {
             "payment_method": "credit_card",
             "funding_instruments": [{
                 "credit_card": {
                     "type": "visa",
                     "number": "4417119669820331",
                     "expire_month": "11",
                     "expire_year": "2018",
                     "cvv2": "874",
                     "first_name": "Joe",
                     "last_name": "Shopper"
                 }
             }]
         }, "transactions": [{
             "item_list": {
                 "items": [{
                     "name": "item",
                     "sku": "item",
                     "price": "1.00",
                     "currency": "USD",
                     "quantity": 1
                 }]
             }, "amount": {
                 "total": "1.00",
                 "currency": "USD"
             }, "description": "This is the payment transaction description."
         }]
     }
     resource = Resource(data)
     assert resource.to_dict() == data
Exemplo n.º 3
0
 def test_http_headers(self):
     data = {
         'name': 'testing',
         'header': {'My-Header': 'testing'}
     }
     resource = Resource(data)
     assert resource.header == {'My-Header': 'testing'}
     assert resource.http_headers() == {'My-Header': 'testing'}
Exemplo n.º 4
0
 def list_bank_accounts(self):
     # /customers/<CUSTOMER-ID>/bank_accounts
     endpoint = util.join_url(self.path, str(self['id']), 'bank_accounts')
     response = self.api.get(endpoint)
     try:
         return Resource(response, api=self.api)
     except AttributeError:
         # To handle the case when response is JSON Array
         if isinstance(response, list):
             new_resp = [Resource(elem, api=self.api) for elem in response]
             return new_resp
Exemplo n.º 5
0
 def test_setter(self):
     data = {'name': 'testing'}
     resource = Resource(data)
     assert resource.name == 'testing'
     resource.name = 'changed'
     assert resource.name == 'changed'
     resource['name'] = 'again-changed'
     assert resource.name == 'again-changed'
     resource.transaction = {'description': 'testing'}
     assert resource.transaction.__class__ == Resource
     assert resource.transaction.description == 'testing'
Exemplo n.º 6
0
    def test_default_resource(self):
        from besepa import api
        original = api.__api__

        class DummyAPI(object):
            def post(self, *a, **k): pass

            def get(self, *a, **k): pass

        # Make default api object a dummy api object
        default = api.__api__ = DummyAPI()

        resource = Resource({})
        assert resource.api == default

        class TestResource(Find, List, Post):
            path = '/'

        # Find
        find = TestResource.find('resourceid')
        assert find.api == default

        # List
        list_ = TestResource.all()
        assert list_.api == default

        api.__api__ = original  # Restore original api object
Exemplo n.º 7
0
 def test_getter(self):
     data = {
         'name': 'testing',
         'amount': 10.0,
         'transaction': {'description': 'testing'},
         'items': [{'name': 'testing'}]
     }
     resource = Resource(data)
     assert resource.name == 'testing'
     assert resource['name'] == 'testing'
     assert resource.amount == 10.0
     assert resource.items[0].__class__ == Resource
     assert resource.items[0].name == 'testing'
     assert resource.items[0]['name'] == 'testing'
     assert resource.unknown is None
     with pytest.raises(KeyError):
         resource['unknown']
Exemplo n.º 8
0
 def test_success(self):
     resource = Resource()
     assert resource.success() is True
     resource.error = 'Error'
     assert resource.success() is False
Exemplo n.º 9
0
 def test_representation(self):
     assert str(Resource({'name': 'testing'})) == str({'name': 'testing'})
     assert repr(Resource({'name': 'testing'})) == str({'name': 'testing'})
Exemplo n.º 10
0
 def test_contains(self):
     resource = Resource({'name': 'testing'})
     assert True == ('name' in resource)
     assert False == ('testing' in resource)