def test_get_preview_image_url_failure_none_value(self) -> None:
        with patch.object(requests, 'get') as mock_get:
            mock_get.return_value.json.return_value = {
                'web_preview_image': None
            }

            preview = ModePreview(access_token='token',
                                  password='******',
                                  organization='foo')
            mode_dashboard_uri = 'mode_dashboard://gold.dg/d_id'
            self.assertRaises(FileNotFoundError,
                              preview._get_preview_image_url,
                              uri=mode_dashboard_uri)
Example #2
0
 def test_auth_disabled(self) -> None:
     preview = ModePreview(access_token='token',
                           password='******',
                           organization='foo')
     self.assertFalse(preview._is_auth_enabled)
Example #3
0
    def test_authorization(self) -> None:
        self.app.config['ACL_ENABLED_DASHBOARD_PREVIEW'] = {'ModePreview'}
        self.app.config['AUTH_USER_METHOD'] = MagicMock()

        with patch(
                'amundsen_application.api.preview.dashboard.dashboard_preview.mode_preview.request_metadata'
        ) as mock_request_metadata:
            mock_request_metadata.return_value.json.return_value = {
                'employee_type': 'teamMember',
                'full_name': 'test_full_name',
                'is_active': 'True',
                'github_username': '******',
                'slack_id': 'test_id',
                'last_name': 'test_last_name',
                'first_name': 'test_first_name',
                'team_name': 'test_team',
                'email': 'test_email',
                'other_key_values': {
                    'mode_user_id': 'foo_mode_user_id'
                }
            }

            preview = ModePreview(access_token='token',
                                  password='******',
                                  organization='foo')
            preview._authorize_access(user_id='test_email')

        with patch(
                'amundsen_application.api.preview.dashboard.dashboard_preview.mode_preview.request_metadata'
        ) as mock_request_metadata:
            mock_request_metadata.return_value.json.return_value = {
                'employee_type': 'teamMember',
                'full_name': 'test_full_name',
                'is_active': 'False',
                'github_username': '******',
                'slack_id': 'test_id',
                'last_name': 'test_last_name',
                'first_name': 'test_first_name',
                'team_name': 'test_team',
                'email': 'test_email',
                'other_key_values': {
                    'mode_user_id': 'foo_mode_user_id'
                }
            }

            preview = ModePreview(access_token='token',
                                  password='******',
                                  organization='foo')
            self.assertRaises(PermissionError,
                              preview._authorize_access,
                              user_id='test_email')

        with patch(
                'amundsen_application.api.preview.dashboard.dashboard_preview.mode_preview.request_metadata'
        ) as mock_request_metadata:
            mock_request_metadata.return_value.json.return_value = {
                'employee_type': 'teamMember',
                'full_name': 'test_full_name',
                'is_active': 'True',
                'github_username': '******',
                'slack_id': 'test_id',
                'last_name': 'test_last_name',
                'first_name': 'test_first_name',
                'team_name': 'test_team',
                'email': 'test_email',
                'other_key_values': {}
            }

            preview = ModePreview(access_token='token',
                                  password='******',
                                  organization='foo')
            self.assertRaises(PermissionError,
                              preview._authorize_access,
                              user_id='test_email')

        with patch(
                'amundsen_application.api.preview.dashboard.dashboard_preview.mode_preview.request_metadata'
        ) as mock_request_metadata:
            mock_request_metadata.return_value.json.return_value = {
                'employee_type': 'teamMember',
                'full_name': 'test_full_name',
                'is_active': 'True',
                'github_username': '******',
                'slack_id': 'test_id',
                'last_name': 'test_last_name',
                'first_name': 'test_first_name',
                'team_name': 'test_team',
                'email': 'test_email',
                'other_key_values': {
                    'foo': 'bar'
                }
            }

            preview = ModePreview(access_token='token',
                                  password='******',
                                  organization='foo')
            self.assertRaises(PermissionError,
                              preview._authorize_access,
                              user_id='test_email')

        with patch(
                'amundsen_application.api.preview.dashboard.dashboard_preview.mode_preview.request_metadata'
        ) as mock_request_metadata:
            mock_request_metadata.return_value.json.return_value = {
                'employee_type': 'teamMember',
                'full_name': 'test_full_name',
                'is_active': 'True',
                'github_username': '******',
                'slack_id': 'test_id',
                'last_name': 'test_last_name',
                'first_name': 'test_first_name',
                'team_name': 'test_team',
                'email': 'test_email',
                'other_key_values': None
            }

            preview = ModePreview(access_token='token',
                                  password='******',
                                  organization='foo')
            self.assertRaises(PermissionError,
                              preview._authorize_access,
                              user_id='test_email')

        with patch(
                'amundsen_application.api.preview.dashboard.dashboard_preview.mode_preview.request_metadata'
        ) as mock_request_metadata:
            mock_request_metadata.return_value.json.return_value = {
                'employee_type': 'teamMember',
                'full_name': 'test_full_name',
                'is_active': 'True',
                'github_username': '******',
                'slack_id': 'test_id',
                'last_name': 'test_last_name',
                'first_name': 'test_first_name',
                'team_name': 'test_team',
                'email': 'test_email',
            }

            preview = ModePreview(access_token='token',
                                  password='******',
                                  organization='foo')
            self.assertRaises(PermissionError,
                              preview._authorize_access,
                              user_id='test_email')
 def __init__(self) -> None:
     # Register preview clients here. Key: product, Value: BasePreview implementation
     self._object_map = {'mode': ModePreview()}
     LOGGER.info('Supported products: {}'.format(
         list(self._object_map.keys())))