Exemplo n.º 1
0
    def test_capabilities_are_sorted(self, rf):
        # the extra_capabilities passed here are purposefully out of order
        recipe = RecipeFactory(arguments={"foo": "bar"},
                               extra_capabilities=["b", "a"])
        serializer = MinimalRecipeSerializer(recipe,
                                             context={"request": rf.get("/")})

        capabilities = serializer.data["capabilities"]
        assert capabilities == sorted(capabilities)
        assert "a" in capabilities
        assert "b" in capabilities
Exemplo n.º 2
0
def recipe_as_record(recipe):
    """
    Transform a recipe to a dict with the minimum amount of fields needed for clients
    to verify and execute recipes.

    :param recipe: a recipe ready to be exported.
    :returns: a dict to be posted on Remote Settings.
    """
    from normandy.recipes.api.v1.serializers import (
        MinimalRecipeSerializer, )  # avoid circular imports

    serializer = MinimalRecipeSerializer(recipe)
    record = serializer.data
    record["id"] = str(recipe.id)
    return record
Exemplo n.º 3
0
    def test_it_works(self, rf):
        recipe = RecipeFactory(approver=UserFactory(), arguments={"foo": "bar"})
        action = recipe.approved_revision.action
        serializer = MinimalRecipeSerializer(recipe, context={"request": rf.get("/")})

        assert serializer.data == {
            "name": recipe.approved_revision.name,
            "id": recipe.id,
            "filter_expression": recipe.approved_revision.filter_expression,
            "revision_id": str(recipe.approved_revision.id),
            "action": action.name,
            "arguments": {"foo": "bar"},
            "capabilities": sorted(recipe.approved_revision.capabilities),
            "uses_only_baseline_capabilities": False,
        }
Exemplo n.º 4
0
    def test_it_works_with_signature(self, rf):
        recipe = RecipeFactory(approver=UserFactory(), signed=True)
        context = {"request": rf.get("/")}
        combined_serializer = SignedRecipeSerializer(instance=recipe, context=context)
        recipe_serializer = MinimalRecipeSerializer(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,
        }
Exemplo n.º 5
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 = MinimalRecipeSerializer(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,
        }
Exemplo n.º 6
0
 def canonical_json(self):
     # Avoid circular import
     from normandy.recipes.api.v1.serializers import MinimalRecipeSerializer
     data = MinimalRecipeSerializer(self).data
     return CanonicalJSONRenderer().render(data)