Beispiel #1
0
    def get(self, request, *args, **kwargs):
        ip = get_ip(request)
        if ip == '127.0.0.1':
            country = 'all' #get_payment_methods returns all methods when 'all' is specified
        else:
            country = get_country_by_ip(ip)

        # TODO: 1) Determine available methods based on GET params (amount).
        #       2) Re-enable country-based filtering when front-end can handle
        #          manually setting the country. For now send all methods.
        methods = get_payment_methods('all', 500)

        result = {'country': country, 'results': methods}
        response = Response(result, status=status.HTTP_200_OK)
        return response
Beispiel #2
0
 def test_valid_ip(self):
 	self.assertEqual(get_country_by_ip("213.127.165.114"), "Netherlands")
Beispiel #3
0
 def test_invalid_ip(self):
 	with self.assertRaises(InvalidIpError):
 		get_country_by_ip("123abc")
Beispiel #4
0
 def test_no_ip(self):
 	self.assertEqual(get_country_by_ip(), None)
Beispiel #5
0
 def test_no_ip(self):
     self.assertEqual(get_country_by_ip(), None)
Beispiel #6
0
 def test_valid_ip(self):
     self.assertEqual(get_country_by_ip("213.127.165.114"), "Netherlands")
Beispiel #7
0
 def test_invalid_ip(self):
     with self.assertRaises(InvalidIpError):
         get_country_by_ip("123abc")