示例#1
0
    def test_calls_view_if_flag_active(self):
        """Test that the wrapped view is caleld if the feature flag is active."""
        FeatureFlagFactory(code='test-feature-flag', is_active=True)

        mock = Mock()
        feature_flagged_view('test-feature-flag')(mock)()
        mock.assert_called_once()
    def test_add_adviser_link_existence(
        self,
        permission_codenames,
        enable_feature_flag,
        should_link_exist,
    ):
        """
        Test that there is a link to add an adviser from SSO if the user has the correct
        permissions and the feature flag is enabled.
        """
        if enable_feature_flag:
            FeatureFlagFactory(code=ADMIN_ADD_ADVISER_FROM_SSO_FEATURE_FLAG)

        user = create_test_user(
            permission_codenames=permission_codenames,
            password=self.PASSWORD,
            is_staff=True,
        )

        client = self.create_client(user)
        response = client.get(changelist_url)
        assert response.status_code == status.HTTP_200_OK

        assert (add_from_sso_url
                in response.rendered_content) == should_link_exist
示例#3
0
 def test_makes_api_call_to_consent_service(
     self,
     data_flow_api_client,
     consent_get_many_mock,
 ):
     """
     Test that if consent feature flag is enabled then call is made to
     the consent service and values from that are in the response.
     """
     FeatureFlagFactory(code=GET_CONSENT_FROM_CONSENT_SERVICE,
                        is_active=True)
     contact1 = ContactFactory(email='[email protected]')
     contact2 = ContactFactory(email='[email protected]')
     contact3 = ContactFactory(email='[email protected]')
     consent_get_many_mock.return_value = {
         contact1.email: True,
         contact2.email: False,
     }
     response = data_flow_api_client.get(self.view_url)
     assert response.status_code == status.HTTP_200_OK
     consent_get_many_mock.assert_called_once_with(
         [contact1.email, contact2.email, contact3.email], )
     response_results = response.json()['results']
     assert response_results[0]['accepts_dit_email_marketing']
     assert not response_results[1]['accepts_dit_email_marketing']
     assert not response_results[2]['accepts_dit_email_marketing']
def test_notify_new_dnb_investigation(monkeypatch):
    """
    Test notify_new_dnb_investigation triggers a call to the expected notification helper function.
    """
    FeatureFlagFactory(code=NOTIFY_DNB_INVESTIGATION_FEATURE_FLAG,
                       is_active=True)
    mocked_notify_by_email = mock.Mock()
    notification_recipients = ['*****@*****.**', '*****@*****.**']
    company = CompanyFactory(
        dnb_investigation_data={'telephone_number': '12345678'})
    monkeypatch.setattr(
        'datahub.notification.notify.notify_by_email',
        mocked_notify_by_email,
    )
    with override_settings(
            DNB_INVESTIGATION_NOTIFICATION_RECIPIENTS=notification_recipients,
    ):
        notify_new_dnb_investigation(company)
    mocked_calls = mocked_notify_by_email.call_args_list
    for email, call_args in zip(notification_recipients, mocked_calls):
        assert call_args[0] == email
        assert call_args[1] == Template.request_new_business_record.value
        assert call_args[2]['business_name'] == company.name
        expected_phone_number = company.dnb_investigation_data[
            'telephone_number']
        assert call_args[2]['contact_number'] == expected_phone_number
        assert call_args[3] == NotifyServiceName.dnb_investigation
        mocked_notify_by_email.call_count == 2
示例#5
0
def test_is_feature_flag(code, is_active, lookup, expected):
    """Tests if is_feature_flag returns correct state of feature flag."""
    if code != '':
        FeatureFlagFactory(code=code, is_active=is_active)

    result = is_feature_flag_active(lookup)
    assert result is expected
示例#6
0
def set_streamlined_flow_feature_flag_as_inactive():
    """Creates the streamlined flow feature flag."""
    yield FeatureFlagFactory(
        code=FEATURE_FLAG_STREAMLINED_FLOW,
        is_active=False,
        description='description of feature',
    )
示例#7
0
    def test_raises_404_is_flag_inactive(self):
        """Test that an Http404 is raised if the feature flag is inactive."""
        FeatureFlagFactory(code='test-feature-flag', is_active=False)

        mock = Mock()
        with pytest.raises(Http404):
            feature_flagged_view('test-feature-flag')(mock)()
        mock.assert_not_called()
示例#8
0
def use_notification_app(request):
    """
    Fixture determining whether or not to use omis' notification package or
    datahub's new datahub.notification django app.

    By using the pytest.fixture params kwarg, we ensure that every test case
    using this fixture is run once with the feature flag active (using the
    notification app) and once with the feature flag inactive (using omis' notify
    client).
    """
    use_notification_app = request.param
    if use_notification_app:
        FeatureFlagFactory(code=OMIS_USE_NOTIFICATION_APP_FEATURE_FLAG_NAME)
        return True
    return False
示例#9
0
def end_to_end_notify(monkeypatch, settings):
    """
    A fixture for a notify client which uses the new datahub.notification app
    under the hood and calls through to the GOVUK notify service (with
    settings.OMIS_NOTIFICATION_TEST_API_KEY).

    By contrast, our other test cases will use mocked clients so that no actual
    web requests are made to GOVUK notify.
    """
    with override_settings(OMIS_NOTIFICATION_API_KEY=settings.OMIS_NOTIFICATION_TEST_API_KEY):
        monkeypatch.setattr(
            'datahub.notification.tasks.notify_gateway',
            NotifyGateway(),
        )
        FeatureFlagFactory(code=OMIS_USE_NOTIFICATION_APP_FEATURE_FLAG_NAME)
        yield Notify()
    def test_can_list_feature_flags(self):
        """List feature flags."""
        feature_flags = FeatureFlagFactory.create_batch(10)
        url = reverse('api-v3:feature-flag:collection')
        response = self.api_client.get(url)

        assert response.status_code == status.HTTP_200_OK

        response_data = response.json()

        expected_feature_flags = sorted(
            ({
                'code': feature_flag.code,
                'is_active': feature_flag.is_active,
            } for feature_flag in feature_flags),
            key=lambda item: item['code'],
        )
        assert response_data == expected_feature_flags
def interaction_importer_feature_flag():
    """Creates the import interactions tool feature flag."""
    yield FeatureFlagFactory(code=INTERACTION_IMPORTER_FEATURE_FLAG_NAME)
示例#12
0
def set_streamlined_flow_feature_flag_active():
    """Creates the streamlined flow feature flag."""
    yield FeatureFlagFactory(code=FEATURE_FLAG_STREAMLINED_FLOW,
                             is_active=True)
示例#13
0
 def _get_dnb_investigation_notify_client(self):
     FeatureFlagFactory(code=NOTIFY_DNB_INVESTIGATION_FEATURE_FLAG,
                        is_active=True)
     client = notify_gateway.clients['dnb_investigation']
     client.reset_mock()
     return client
示例#14
0
def automatic_company_archive_feature_flag():
    """
    Creates the automatic company archive feature flag.
    """
    yield FeatureFlagFactory(code=AUTOMATIC_COMPANY_ARCHIVE_FEATURE_FLAG)
示例#15
0
def dnb_company_updates_feature_flag():
    """
    Creates the DNB company updates feature flag.
    """
    yield FeatureFlagFactory(code=FEATURE_FLAG_DNB_COMPANY_UPDATES)
def interaction_email_notification_feature_flag():
    """
    Creates the email ingestion feature flag.
    """
    yield FeatureFlagFactory(code=INTERACTION_EMAIL_NOTIFICATION_FEATURE_FLAG_NAME)
示例#17
0
def update_consent_service_feature_flag():
    """
    Creates the consent service feature flag.
    """
    yield FeatureFlagFactory(code=UPDATE_CONSENT_SERVICE_FEATURE_FLAG)
示例#18
0
def mailbox_ingestion_feature_flag():
    """
    Creates the email ingestion feature flag.
    """
    yield FeatureFlagFactory(code=MAILBOX_INGESTION_FEATURE_FLAG_NAME)