Пример #1
0
 def test_it_sends_metrics(self, settings, mocked_autograph):
     ActionFactory.create_batch(3, signed=False)
     with MetricsMock() as mm:
         call_command("update_action_signatures")
         mm.print_records()
         assert mm.has_record(GAUGE,
                              stat="normandy.signing.actions.signed",
                              value=3)
Пример #2
0
    def test_update_signatures(self, mocker, mock_logger):
        # Make sure the test environment is clean. This test is invalid otherwise.
        assert Action.objects.all().count() == 0

        # Mock the Autographer
        mock_autograph = mocker.patch('normandy.recipes.models.Autographer')
        mock_autograph.return_value.sign_data.return_value = [
            {
                'signature': 'fake signature 1'
            },
            {
                'signature': 'fake signature 2'
            },
        ]

        # Make and sign two actions
        (action1, action2) = ActionFactory.create_batch(2)
        Action.objects.all().update_signatures()

        # Assert that the signature update is logged.
        mock_logger.info.assert_called_with(
            Whatever.contains(action1.name, action2.name),
            extra={
                'code': INFO_REQUESTING_ACTION_SIGNATURES,
                'action_names': Whatever.contains(action1.name, action2.name),
            })

        # Assert the autographer was used as expected
        assert mock_autograph.called
        assert mock_autograph.return_value.sign_data.called_with(
            [Whatever(), Whatever()])
        signatures = list(Action.objects.all().values_list(
            'signature__signature', flat=True))
        assert signatures == ['fake signature 1', 'fake signature 2']