Пример #1
0
    def test_it_works_with_no_signature(self, rf):
        recipe = RecipeFactory(signed=False)
        action = recipe.action
        serializer = SignedRecipeSerializer(instance=recipe,
                                            context={'request': rf.get('/')})

        assert serializer.data == {
            'signature': None,
            'recipe': {
                'name': recipe.name,
                'id': recipe.id,
                'enabled': recipe.enabled,
                'extra_filter_expression': recipe.extra_filter_expression,
                'filter_expression': recipe.filter_expression,
                'revision_id': recipe.revision_id,
                'action': action.name,
                'arguments': recipe.arguments,
                'last_updated': Whatever(),
                'channels': [],
                'countries': [],
                'locales': [],
                'is_approved': False,
                'latest_revision_id': recipe.latest_revision.id,
                'approved_revision_id': recipe.approved_revision_id,
                'approval_request': None,
            }
        }
Пример #2
0
    def test_it_works_with_signature(self, rf):
        recipe = RecipeFactory(signed=True)
        context = {'request': rf.get('/')}
        combined_serializer = SignedRecipeSerializer(instance=recipe,
                                                     context=context)
        recipe_serializer = RecipeSerializer(instance=recipe, context=context)

        # Testing for shape of data, not contents
        assert combined_serializer.data == {
            'signature': {
                'signature': Whatever(),
                'timestamp': Whatever(),
                'x5u': Whatever(),
                'public_key': Whatever(),
            },
            'recipe': recipe_serializer.data,
        }
Пример #3
0
 def signed(self, request, pk=None):
     recipes = self.filter_queryset(
         self.get_queryset()).exclude(signature=None)
     serializer = SignedRecipeSerializer(recipes, many=True)
     return Response(serializer.data)