コード例 #1
0
ファイル: test_models.py プロジェクト: chartjes/normandy
    def test_skip_last_updated(self):
        # set last_updated to avoid timestamp precision problems
        recipe = RecipeFactory(name='one', last_updated=datetime.now() - timedelta(30))
        last_updated_1 = recipe.last_updated

        recipe.name = 'two'
        recipe.save()
        last_updated_2 = recipe.last_updated

        recipe.name = 'three'
        recipe.save(skip_last_updated=True)
        last_updated_3 = recipe.last_updated

        assert last_updated_1 != last_updated_2
        assert last_updated_2 == last_updated_3
コード例 #2
0
ファイル: test_models.py プロジェクト: chartjes/normandy
 def test_cant_change_signature_and_other_fields(self):
     recipe = RecipeFactory(name='unchanged', signed=False)
     recipe.signature = SignatureFactory()
     recipe.name = 'changed'
     with pytest.raises(ValidationError) as exc_info:
         recipe.save()
     assert exc_info.value.message == 'Signatures must change alone'
コード例 #3
0
ファイル: test_api.py プロジェクト: amitkumarj441/normandy
    def test_history(self, api_client):
        with reversion.create_revision():
            recipe = RecipeFactory(name='version 1')

        with reversion.create_revision():
            recipe.name = 'version 2'
            recipe.save()

        with reversion.create_revision():
            recipe.name = 'version 3'
            recipe.save()

        res = api_client.get('/api/v1/recipe/%s/history/' % recipe.id)

        assert res.data[0]['recipe']['name'] == 'version 3'
        assert res.data[1]['recipe']['name'] == 'version 2'
        assert res.data[2]['recipe']['name'] == 'version 1'
コード例 #4
0
ファイル: test_models.py プロジェクト: chartjes/normandy
    def test_signature_is_cleared_if_autograph_unavailable(self, mocker):
        # Mock the Autographer
        mock_autograph = mocker.patch('normandy.recipes.models.Autographer')
        mock_autograph.return_value.sign_data.side_effect = ImproperlyConfigured

        recipe = RecipeFactory(name='unchanged', signed=True)
        original_signature = recipe.signature
        recipe.name = 'changed'
        recipe.save()
        assert recipe.name == 'changed'
        assert recipe.signature is not original_signature
        assert recipe.signature is None
コード例 #5
0
ファイル: test_models.py プロジェクト: mythmon/normandy
    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
コード例 #6
0
ファイル: test_models.py プロジェクト: chartjes/normandy
    def test_signature_is_updated_if_autograph_available(self, mocker):
        # Mock the Autographer
        mock_autograph = mocker.patch('normandy.recipes.models.Autographer')
        mock_autograph.return_value.sign_data.return_value = [
            {'signature': 'fake signature'},
        ]

        recipe = RecipeFactory(name='unchanged', signed=True)
        original_signature = recipe.signature
        recipe.name = 'changed'
        recipe.save()
        assert recipe.name == 'changed'
        assert recipe.signature is not original_signature
        assert recipe.signature.signature == 'fake signature'