def retrieve(self, request, pk=None): try: strategy = self.strategies_index[pk] except KeyError: raise Http404 serializer = StrategySerializer(strategy, context={'request': request}) return Response(serializer.data)
def test_handles_infinite_memory_depth_in_params(self): self.strategy.params = {'memory_depth': float('inf')} serializer = StrategySerializer(self.strategy, context={'request': self.request}) self.assertEqual({'memory_depth': -1}, serializer.data['params'])
def test_handles_infinite_memory_depth(self): self.strategy.classifier['memory_depth'] = float('inf') serializer = StrategySerializer(self.strategy, context={'request': self.request}) self.assertEqual(-1, serializer.data['classifier']['memory_depth'])
def test_generates_correct_params(self): serializer = StrategySerializer(self.strategy, context={'request': self.request}) self.assertEqual({'rate': 0.5}, serializer.data['params'])
def test_generates_correct_url(self): serializer = StrategySerializer(self.strategy, context={'request': self.request}) self.assertEqual('http://testserver/strategies/teststrategy/', serializer.data['url'])
def test_has_correct_fields(self): serializer = StrategySerializer(self.strategy, context={'request': self.request}) for key in ['url', 'id', 'name', 'description', 'classifier', 'params']: self.assertIn(key, serializer.data)
def list(self, request): serializer = StrategySerializer(filter_strategies(request), many=True, context={'request': request}) return Response(serializer.data)