Exemple #1
0
 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)
Exemple #2
0
 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'])
Exemple #3
0
 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'])
Exemple #4
0
 def test_generates_correct_params(self):
     serializer = StrategySerializer(self.strategy, context={'request': self.request})
     self.assertEqual({'rate': 0.5}, serializer.data['params'])
Exemple #5
0
 def test_generates_correct_url(self):
     serializer = StrategySerializer(self.strategy, context={'request': self.request})
     self.assertEqual('http://testserver/strategies/teststrategy/', serializer.data['url'])
Exemple #6
0
 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)
Exemple #7
0
 def list(self, request):
     serializer = StrategySerializer(filter_strategies(request),
                                     many=True,
                                     context={'request': request})
     return Response(serializer.data)