当前位置: 首页>>代码示例>>Python>>正文


Python RecipeFactory.canonical_json方法代码示例

本文整理汇总了Python中normandy.recipes.tests.RecipeFactory.canonical_json方法的典型用法代码示例。如果您正苦于以下问题:Python RecipeFactory.canonical_json方法的具体用法?Python RecipeFactory.canonical_json怎么用?Python RecipeFactory.canonical_json使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在normandy.recipes.tests.RecipeFactory的用法示例。


在下文中一共展示了RecipeFactory.canonical_json方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_setting_signature_doesnt_change_canonical_json

# 需要导入模块: from normandy.recipes.tests import RecipeFactory [as 别名]
# 或者: from normandy.recipes.tests.RecipeFactory import canonical_json [as 别名]
 def test_setting_signature_doesnt_change_canonical_json(self):
     recipe = RecipeFactory(name='unchanged', signed=False)
     serialized = recipe.canonical_json()
     recipe.signature = SignatureFactory()
     recipe.save()
     assert recipe.signature is not None
     assert recipe.canonical_json() == serialized
开发者ID:chartjes,项目名称:normandy,代码行数:9,代码来源:test_models.py

示例2: test_only_signed_when_approved_and_enabled

# 需要导入模块: from normandy.recipes.tests import RecipeFactory [as 别名]
# 或者: from normandy.recipes.tests.RecipeFactory import canonical_json [as 别名]
    def test_only_signed_when_approved_and_enabled(self, mocked_autograph):
        sign_data_mock = mocked_autograph.return_value.sign_data
        # This uses the signer, so do it first
        action = ActionFactory()
        sign_data_mock.reset_mock()

        sign_data_mock.side_effect = Exception("Can't sign yet")
        recipe = RecipeFactory(name="unchanged", action=action)
        assert not recipe.enabled
        assert not recipe.is_approved
        assert recipe.signature is None

        # Updating does not generate a signature
        recipe.revise(name="changed")
        assert recipe.signature is None

        # Approving does not sign the recipe
        rev = recipe.latest_revision
        approval_request = rev.request_approval(UserFactory())
        approval_request.approve(UserFactory(), "r+")
        recipe.refresh_from_db()
        assert recipe.signature is None
        mocked_autograph.return_value.sign_data.assert_not_called()

        # Enabling signs the recipe
        mocked_autograph.return_value.sign_data.side_effect = fake_sign
        rev.enable(UserFactory())
        recipe.refresh_from_db()
        expected_sig = fake_sign([recipe.canonical_json()])[0]["signature"]
        assert recipe.signature.signature == expected_sig
        assert mocked_autograph.return_value.sign_data.called_once()
开发者ID:rehandalal,项目名称:normandy,代码行数:33,代码来源:test_models.py

示例3: test_canonical_json

# 需要导入模块: from normandy.recipes.tests import RecipeFactory [as 别名]
# 或者: from normandy.recipes.tests.RecipeFactory import canonical_json [as 别名]
 def test_canonical_json(self):
     recipe = RecipeFactory(
         action=ActionFactory(name="action"),
         arguments_json='{"foo": 1, "bar": 2}',
         extra_filter_expression="2 + 2 == 4",
         name="canonical",
         filter_object_json=None,
     )
     # Yes, this is really ugly, but we really do need to compare an exact
     # byte sequence, since this is used for hashing and signing
     filter_expression = "2 + 2 == 4"
     expected = (
         "{"
         '"action":"action",'
         '"arguments":{"bar":2,"foo":1},'
         '"filter_expression":"%(filter_expression)s",'
         '"id":%(id)s,'
         '"name":"canonical",'
         '"revision_id":"%(revision_id)s"'
         "}"
     ) % {
         "id": recipe.id,
         "revision_id": recipe.revision_id,
         "filter_expression": filter_expression,
     }
     expected = expected.encode()
     assert recipe.canonical_json() == expected
开发者ID:rehandalal,项目名称:normandy,代码行数:29,代码来源:test_models.py

示例4: test_signatures_update_correctly_on_enable

# 需要导入模块: from normandy.recipes.tests import RecipeFactory [as 别名]
# 或者: from normandy.recipes.tests.RecipeFactory import canonical_json [as 别名]
    def test_signatures_update_correctly_on_enable(self, mocked_autograph):
        recipe = RecipeFactory(signed=False, approver=UserFactory())
        recipe.approved_revision.enable(user=UserFactory())
        recipe.refresh_from_db()

        assert recipe.signature is not None
        assert recipe.signature.signature == fake_sign([recipe.canonical_json()])[0]["signature"]
开发者ID:rehandalal,项目名称:normandy,代码行数:9,代码来源:test_models.py

示例5: test_signature_is_updated_if_autograph_available

# 需要导入模块: from normandy.recipes.tests import RecipeFactory [as 别名]
# 或者: from normandy.recipes.tests.RecipeFactory import canonical_json [as 别名]
    def test_signature_is_updated_if_autograph_available(self, mocked_autograph):
        recipe = RecipeFactory(name="unchanged", approver=UserFactory(), enabler=UserFactory())
        original_signature = recipe.signature
        assert original_signature is not None

        recipe.revise(name="changed")

        assert recipe.latest_revision.name == "changed"
        assert recipe.signature is not original_signature
        expected_sig = fake_sign([recipe.canonical_json()])[0]["signature"]
        assert recipe.signature.signature == expected_sig
开发者ID:rehandalal,项目名称:normandy,代码行数:13,代码来源:test_models.py

示例6: test_enabled_updates_signatures

# 需要导入模块: from normandy.recipes.tests import RecipeFactory [as 别名]
# 或者: from normandy.recipes.tests.RecipeFactory import canonical_json [as 别名]
    def test_enabled_updates_signatures(self, mocked_autograph):
        recipe = RecipeFactory(name="first")
        ar = recipe.latest_revision.request_approval(UserFactory())
        ar.approve(approver=UserFactory(), comment="r+")
        recipe = Recipe.objects.get()
        recipe.approved_revision.enable(UserFactory())

        recipe.refresh_from_db()
        data_to_sign = recipe.canonical_json()
        signature_of_data = fake_sign([data_to_sign])[0]["signature"]
        signature_in_db = recipe.signature.signature
        assert signature_of_data == signature_in_db
开发者ID:rehandalal,项目名称:normandy,代码行数:14,代码来源:test_models.py

示例7: test_signature_is_updated_if_autograph_available

# 需要导入模块: from normandy.recipes.tests import RecipeFactory [as 别名]
# 或者: from normandy.recipes.tests.RecipeFactory import canonical_json [as 别名]
    def test_signature_is_updated_if_autograph_available(self, mocked_autograph):
        recipe = RecipeFactory(name='unchanged')
        original_signature = recipe.signature
        assert original_signature is not None

        recipe.name = 'changed'
        recipe.save()

        assert recipe.name == 'changed'
        assert recipe.signature is not original_signature
        expected_sig = hashlib.sha256(recipe.canonical_json()).hexdigest()
        assert recipe.signature.signature == expected_sig
开发者ID:mythmon,项目名称:normandy,代码行数:14,代码来源:test_models.py

示例8: test_signatures_update_correctly_on_enable

# 需要导入模块: from normandy.recipes.tests import RecipeFactory [as 别名]
# 或者: from normandy.recipes.tests.RecipeFactory import canonical_json [as 别名]
    def test_signatures_update_correctly_on_enable(self, mocker):
        mock_autograph = mocker.patch('normandy.recipes.models.Autographer')

        def fake_sign(datas):
            sigs = []
            for d in datas:
                sigs.append({'signature': hashlib.sha256(d).hexdigest()})
            return sigs

        mock_autograph.return_value.sign_data.side_effect = fake_sign

        recipe = RecipeFactory(enabled=False, signed=False)
        recipe.enabled = True
        recipe.save()
        recipe.refresh_from_db()

        assert recipe.signature is not None
        assert recipe.signature.signature == hashlib.sha256(recipe.canonical_json()).hexdigest()
开发者ID:chartjes,项目名称:normandy,代码行数:20,代码来源:test_models.py

示例9: test_signature_is_correct_on_creation_if_autograph_available

# 需要导入模块: from normandy.recipes.tests import RecipeFactory [as 别名]
# 或者: from normandy.recipes.tests.RecipeFactory import canonical_json [as 别名]
 def test_signature_is_correct_on_creation_if_autograph_available(self, mocked_autograph):
     recipe = RecipeFactory(approver=UserFactory(), enabler=UserFactory())
     expected_sig = fake_sign([recipe.canonical_json()])[0]["signature"]
     assert recipe.signature.signature == expected_sig
开发者ID:rehandalal,项目名称:normandy,代码行数:6,代码来源:test_models.py

示例10: test_signed_true

# 需要导入模块: from normandy.recipes.tests import RecipeFactory [as 别名]
# 或者: from normandy.recipes.tests.RecipeFactory import canonical_json [as 别名]
 def test_signed_true(self):
     r = RecipeFactory(signed=True)
     assert r.signature is not None
     assert r.signature.signature == hashlib.sha256(r.canonical_json()).hexdigest()
     assert isinstance(r.signature.timestamp, datetime)
开发者ID:mythmon,项目名称:normandy,代码行数:7,代码来源:test_factories.py

示例11: test_signature_is_correct_on_creation_if_autograph_available

# 需要导入模块: from normandy.recipes.tests import RecipeFactory [as 别名]
# 或者: from normandy.recipes.tests.RecipeFactory import canonical_json [as 别名]
 def test_signature_is_correct_on_creation_if_autograph_available(self, mocked_autograph):
     recipe = RecipeFactory()
     expected_sig = hashlib.sha256(recipe.canonical_json()).hexdigest()
     assert recipe.signature.signature == expected_sig
开发者ID:mythmon,项目名称:normandy,代码行数:6,代码来源:test_models.py


注:本文中的normandy.recipes.tests.RecipeFactory.canonical_json方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。