Esempio n. 1
0
 def test_invalid_currency(self):
     """Test failure while handling invalid cost_type."""
     currency = "invalid"
     serializer = CostModelSerializer(data=self.ocp_data,
                                      context=self.request_context)
     with self.assertRaises(serializers.ValidationError):
         serializer.validate_currency(currency)
Esempio n. 2
0
 def currency_filter(self, qs, name, values):
     """Filter currency if a valid currency is passed in"""
     serializer = CostModelSerializer(qs)
     if serializer.validate_currency(values[0]):
         lookup = "__".join([name, "iexact"])
         queries = [Q(**{lookup: val}) for val in values]
         return qs.filter(reduce(and_, queries))