class TestQPClient(object):
    def setup(self):
        self.client = QPClient('foobar')
        self.api = self.client.api
        self.api.perform = MagicMock()

    def test_api_instance(self):
        assert isinstance(self.client.api, QPApi)

    def test_get_delegation(self):
        self.client.get("/dummy")
        self.api.perform.assert_called_once_with("get", "/dummy")

    def test_post_delegation(self):
        self.client.post("/dummy")
        self.api.perform.assert_called_once_with("post", "/dummy")

    def test_delete_delegation(self):
        self.client.delete("/dummy")
        self.api.perform.assert_called_once_with("delete", "/dummy")

    def test_put_delegation(self):
        self.client.put("/dummy")
        self.api.perform.assert_called_once_with("put", "/dummy")

    def test_patch_delegation(self):
        self.client.patch("/dummy")
        self.api.perform.assert_called_once_with("patch", "/dummy")

    def test_non_http_method(self):
        assert_raises(AttributeError, self.client.foobar, "/dummy")
Exemple #2
0
    def get_link_url(self, return_url=''):
        if(self.link_url == ''):
            #request only if not already requested
            client = QPClient(":{0}".format(settings.QUICKPAY_API_KEY))

            parent = self.payment.family.get_first_parent()

            address = {'name' : parent.name,
                       'street' : parent.address(),
                       'city' : parent.city,
                       'zip_code' : parent.zipcode,
                       'att' : self.payment.family.email,
                       'country_code' : 'DNK'
                       }

            variables = address.copy()
            variables['family'] = self.payment.family.email
            if(self.payment.person):
                variables['person_name'] = self.payment.person.name
            if(self.payment.activity):
                variables['activity_department'] = self.payment.activity.department.name
                variables['activity_name'] = self.payment.activity.name

            try:
                if(self.transaction_id == None):
                    activity = client.post('/payments', currency='DKK', order_id=self.order_id, variables=variables, invoice_address=address, shipping_address=address)
                    self.transaction_id = activity['id']
                    self.save()

                if(self.transaction_id == None):
                    raise Exception('we did not get a transaction_id')

                link = client.put(
                    '/payments/{0}/link'.format(self.transaction_id),
                    amount=self.payment.amount_ore,
                    id=self.transaction_id,
                    continueurl=return_url,
                    cancelurl=return_url,
                    customer_email=self.payment.family.email,
                    autocapture=True
                    )

                self.link_url = link['url']
                self.save()
            except:
                # Something went wrong talking to quickpay - ask people to come back later
                return reverse('payment_gateway_error_view', kwargs={'unique':self.payment.family.unique})

        return self.link_url