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
def test_valid_ip(self): self.assertEqual(get_country_by_ip("213.127.165.114"), "Netherlands")
def test_invalid_ip(self): with self.assertRaises(InvalidIpError): get_country_by_ip("123abc")
def test_no_ip(self): self.assertEqual(get_country_by_ip(), None)