Exemplo n.º 1
0
def _get_extension_bundles(extension_manager_key, context, bundle_attr,
                           renderer):
    """Returns media bundles that can be rendered on the current page.

    This will look through all enabled extensions and find any with static
    media bundles that should be included on the current page, as indicated
    by the context.

    All bundles marked "default" will be included, as will any with an
    ``apply_to`` field containing a URL name matching the current page.
    """
    request = context['request']

    if not getattr(request, 'resolver_match', None):
        return

    requested_url_name = request.resolver_match.url_name

    for manager in get_extension_managers():
        if manager.key != extension_manager_key:
            continue

        for extension in manager.get_enabled_extensions():
            bundles = getattr(extension, bundle_attr, {})

            for bundle_name, bundle in six.iteritems(bundles):
                if (bundle_name == 'default' or
                    requested_url_name in bundles.get('apply_to', [])):
                    yield renderer(context, extension, bundle_name)

        break
Exemplo n.º 2
0
    def setUp(self):
        class TestExtension(Extension):
            """An empty, dummy extension for testing"""
            css_bundles = {
                'default': {
                    'source_filenames': ['test.css'],
                }
            }

            js_bundles = {
                'default': {
                    'source_filenames': ['test.js'],
                }
            }

        self.key = 'test_key'
        self.extension_class = TestExtension
        self.manager = ExtensionManager(self.key)
        self.fake_entrypoint = Mock()
        self.fake_entrypoint.load = Mock(return_value=self.extension_class)
        self.fake_entrypoint.dist = Mock()

        self.test_author = 'Test author lorem ipsum'
        self.test_description = 'Test description lorem ipsum'
        self.test_email = 'Test [email protected]'
        self.test_home_page = 'http://www.example.com'
        self.test_license = 'Test License MIT GPL Apache Drivers'
        self.test_module_name = 'testextension.dummy.dummy'
        self.test_module_to_app = 'testextension.dummy'
        self.test_project_name = 'TestProjectName'
        self.test_summary = 'Test summary lorem ipsum'
        self.test_version = '1.0'

        self.test_htdocs_path = os.path.join(settings.EXTENSIONS_STATIC_ROOT,
                                             self.test_project_name)

        self.test_metadata = {
            'Name': self.test_project_name,
            'Version': self.test_version,
            'Summary': self.test_summary,
            'Description': self.test_description,
            'Author': self.test_author,
            'Author-email': self.test_email,
            'License': self.test_license,
            'Home-page': self.test_home_page,
        }

        self.fake_entrypoint.dist.get_metadata_lines = Mock(
            return_value=[
                "%s: %s" % (key, value)
                for key, value in six.iteritems(self.test_metadata)
            ])

        self.fake_entrypoint.dist.project_name = self.test_project_name
        self.fake_entrypoint.dist.version = self.test_version

        self.manager._entrypoint_iterator = Mock(
            return_value=[self.fake_entrypoint]
        )
        self.manager.load()
Exemplo n.º 3
0
    def full_clean(self):
        cache_type = self['cache_type'].data or self['cache_type'].initial

        for iter_cache_type, field in six.iteritems(self.CACHE_LOCATION_FIELD_MAP):
            self.fields[field].required = (cache_type == iter_cache_type)

        return super(GeneralSettingsForm, self).full_clean()
Exemplo n.º 4
0
def build_query_string(request, params):
    """Builds a query string that includes the specified parameters along
    with those that were passed to the page.

    params is a dictionary.
    """
    query_parts = []

    for key, value in six.iteritems(request.GET):
        if key not in params:
            query_parts.append(urlencode({key: value}))

    for key, value in six.iteritems(params):
        if value is not None:
            query_parts.append(urlencode({key: value}))

    return '?' + '&'.join(query_parts)
Exemplo n.º 5
0
    def test_custom_metadata(self):
        """Testing ExtensionInfo metadata from Extension.metadata"""
        entrypoint = Mock()
        entrypoint.dist = Mock()

        test_author = 'Test author lorem ipsum'
        test_description = 'Test description lorem ipsum'
        test_email = 'Test [email protected]'
        test_home_page = 'http://www.example.com'
        test_license = 'Test License MIT GPL Apache Drivers'
        test_module_name = 'testextension.dummy.dummy'
        test_module_to_app = 'testextension.dummy'
        test_project_name = 'TestProjectName'
        test_summary = 'Test summary lorem ipsum'
        test_version = '1.0'

        test_htdocs_path = os.path.join(settings.EXTENSIONS_STATIC_ROOT,
                                        'Dummy')

        test_metadata = {
            'Name': test_project_name,
            'Version': test_version,
            'Summary': test_summary,
            'Description': test_description,
            'Author': test_author,
            'Author-email': test_email,
            'License': test_license,
            'Home-page': test_home_page,
        }

        entrypoint.dist.get_metadata_lines = Mock(
            return_value=[
                "%s: %s" % (key, 'Dummy')
                for key, value in six.iteritems(test_metadata)
            ])

        entrypoint.dist.project_name = 'Dummy'
        entrypoint.dist.version = 'Dummy'

        ext_class = Mock()
        ext_class.__module__ = test_module_name
        ext_class.metadata = test_metadata

        extension_info = ExtensionInfo(entrypoint, ext_class)

        self.assertEqual(extension_info.app_name, test_module_to_app)
        self.assertEqual(extension_info.author, test_author)
        self.assertEqual(extension_info.author_email, test_email)
        self.assertEqual(extension_info.description, test_description)
        self.assertFalse(extension_info.enabled)
        self.assertEqual(extension_info.installed_htdocs_path, test_htdocs_path)
        self.assertFalse(extension_info.installed)
        self.assertEqual(extension_info.license, test_license)
        self.assertEqual(extension_info.metadata, test_metadata)
        self.assertEqual(extension_info.name, test_project_name)
        self.assertEqual(extension_info.summary, test_summary)
        self.assertEqual(extension_info.url, test_home_page)
        self.assertEqual(extension_info.version, test_version)
Exemplo n.º 6
0
def get_hosting_services():
    """Gets the list of hosting services.

    This will return an iterator for iterating over each hosting service.
    """
    _populate_hosting_services()

    for name, cls in six.iteritems(_hosting_services):
        yield name, cls
Exemplo n.º 7
0
def get_hosting_services():
    """Gets the list of hosting services.

    This will return an iterator for iterating over each hosting service.
    """
    _populate_hosting_services()

    for name, cls in six.iteritems(_hosting_services):
        yield name, cls
Exemplo n.º 8
0
    def test_custom_metadata(self):
        """Testing ExtensionInfo metadata from Extension.metadata"""
        entrypoint = Mock()
        entrypoint.dist = Mock()

        test_author = "Test author lorem ipsum"
        test_description = "Test description lorem ipsum"
        test_email = "Test [email protected]"
        test_home_page = "http://www.example.com"
        test_license = "Test License MIT GPL Apache Drivers"
        test_module_name = "testextension.dummy.dummy"
        test_module_to_app = "testextension.dummy"
        test_project_name = "TestProjectName"
        test_summary = "Test summary lorem ipsum"
        test_version = "1.0"

        test_htdocs_path = os.path.join(settings.EXTENSIONS_STATIC_ROOT, "Dummy")

        test_metadata = {
            "Name": test_project_name,
            "Version": test_version,
            "Summary": test_summary,
            "Description": test_description,
            "Author": test_author,
            "Author-email": test_email,
            "License": test_license,
            "Home-page": test_home_page,
        }

        entrypoint.dist.get_metadata_lines = Mock(
            return_value=["%s: %s" % (key, "Dummy") for key, value in six.iteritems(test_metadata)]
        )

        entrypoint.dist.project_name = "Dummy"
        entrypoint.dist.version = "Dummy"

        ext_class = Mock()
        ext_class.__module__ = test_module_name
        ext_class.metadata = test_metadata

        extension_info = ExtensionInfo(entrypoint, ext_class)

        self.assertEqual(extension_info.app_name, test_module_to_app)
        self.assertEqual(extension_info.author, test_author)
        self.assertEqual(extension_info.author_email, test_email)
        self.assertEqual(extension_info.description, test_description)
        self.assertFalse(extension_info.enabled)
        self.assertEqual(extension_info.installed_htdocs_path, test_htdocs_path)
        self.assertFalse(extension_info.installed)
        self.assertEqual(extension_info.license, test_license)
        self.assertEqual(extension_info.metadata, test_metadata)
        self.assertEqual(extension_info.name, test_project_name)
        self.assertEqual(extension_info.summary, test_summary)
        self.assertEqual(extension_info.url, test_home_page)
        self.assertEqual(extension_info.version, test_version)
Exemplo n.º 9
0
 def get_url_params_except(self, *params):
     """
     Utility function to return a string containing URL parameters to
     this page with the specified parameter filtered out.
     """
     result = urlencode([
         (key, value)
         for key, value in six.iteritems(self.datagrid.request.GET)
         if key not in params
     ])
     return result + '&'
Exemplo n.º 10
0
def build_query_string(request, params):
    """Builds a query string that includes the specified parameters along
    with those that were passed to the page.

    params is a dictionary.
    """
    query_parts = []

    for key, value in six.iteritems(request.GET):
        if key not in params:
            query_parts.append(urlencode({
                key: value
            }))

    for key, value in six.iteritems(params):
        if value is not None:
            query_parts.append(urlencode({
                key: value
            }))

    return '?' + '&'.join(query_parts)
Exemplo n.º 11
0
    def setUp(self):
        class TestExtension(Extension):
            """An empty, dummy extension for testing"""

            css_bundles = {"default": {"source_filenames": ["test.css"]}}

            js_bundles = {"default": {"source_filenames": ["test.js"]}}

        self.key = "test_key"
        self.extension_class = TestExtension
        self.manager = ExtensionManager(self.key)
        self.fake_entrypoint = Mock()
        self.fake_entrypoint.load = Mock(return_value=self.extension_class)
        self.fake_entrypoint.dist = Mock()

        self.test_author = "Test author lorem ipsum"
        self.test_description = "Test description lorem ipsum"
        self.test_email = "Test [email protected]"
        self.test_home_page = "http://www.example.com"
        self.test_license = "Test License MIT GPL Apache Drivers"
        self.test_module_name = "testextension.dummy.dummy"
        self.test_module_to_app = "testextension.dummy"
        self.test_project_name = "TestProjectName"
        self.test_summary = "Test summary lorem ipsum"
        self.test_version = "1.0"

        self.test_htdocs_path = os.path.join(settings.EXTENSIONS_STATIC_ROOT, self.test_project_name)

        self.test_metadata = {
            "Name": self.test_project_name,
            "Version": self.test_version,
            "Summary": self.test_summary,
            "Description": self.test_description,
            "Author": self.test_author,
            "Author-email": self.test_email,
            "License": self.test_license,
            "Home-page": self.test_home_page,
        }

        self.fake_entrypoint.dist.get_metadata_lines = Mock(
            return_value=["%s: %s" % (key, value) for key, value in six.iteritems(self.test_metadata)]
        )

        self.fake_entrypoint.dist.project_name = self.test_project_name
        self.fake_entrypoint.dist.version = self.test_version

        self.manager._entrypoint_iterator = Mock(return_value=[self.fake_entrypoint])
        self.manager.load()
Exemplo n.º 12
0
    def _verify_repository_info(self, rsp, repo_name, repo_path, data):
        self.assertEqual(rsp['stat'], 'ok')
        self.assertTrue('repository' in rsp)

        repository = Repository.objects.get(pk=rsp['repository']['id'])

        self.assertEqual(rsp['repository']['path'], repo_path)
        self.assertEqual(repository.path, repo_path)

        if not data.get('archive_name', False):
            self.assertEqual(rsp['repository']['name'], repo_name)
            self.assertEqual(repository.name, repo_name)

        for key, value in six.iteritems(data):
            if hasattr(repository, key):
                self.assertEqual(getattr(repository, key), value)
Exemplo n.º 13
0
    def _verify_repository_info(self, rsp, repo_name, repo_path, data):
        self.assertEqual(rsp['stat'], 'ok')
        self.assertTrue('repository' in rsp)

        repository = Repository.objects.get(pk=rsp['repository']['id'])

        self.assertEqual(rsp['repository']['path'], repo_path)
        self.assertEqual(repository.path, repo_path)

        if not data.get('archive_name', False):
            self.assertEqual(rsp['repository']['name'], repo_name)
            self.assertEqual(repository.name, repo_name)

        for key, value in six.iteritems(data):
            if hasattr(repository, key):
                self.assertEqual(getattr(repository, key), value)
Exemplo n.º 14
0
    def _verify_repository_info(self, rsp, repo_name, repo_path, data):
        self.assertEqual(rsp["stat"], "ok")
        self.assertTrue("repository" in rsp)

        repository = Repository.objects.get(pk=rsp["repository"]["id"])

        self.assertEqual(rsp["repository"]["path"], repo_path)
        self.assertEqual(repository.path, repo_path)

        if not data.get("archive_name", False):
            self.assertEqual(rsp["repository"]["name"], repo_name)
            self.assertEqual(repository.name, repo_name)

        for key, value in six.iteritems(data):
            if hasattr(repository, key):
                self.assertEqual(getattr(repository, key), value)
Exemplo n.º 15
0
    def get_repository_fields(cls, username, hosting_url, plan, tool_name,
                              field_vars):
        if not cls.supports_repositories:
            raise NotImplementedError

        # Grab the list of fields for population below. We have to do this
        # differently depending on whether or not this hosting service has
        # different repository plans.
        fields = cls._get_field(plan, 'repository_fields')

        new_vars = field_vars.copy()
        new_vars['hosting_account_username'] = username

        if cls.self_hosted:
            new_vars['hosting_url'] = hosting_url
            new_vars['hosting_domain'] = urlparse(hosting_url)[1]

        results = {}

        assert tool_name in fields

        for field, value in six.iteritems(fields[tool_name]):
            try:
                results[field] = value % new_vars
            except KeyError as e:
                logging.error('Failed to generate %s field for hosting '
                              'service %s using %s and %r: Missing key %s'
                              % (field, six.text_type(cls.name), value,
                                 new_vars, e),
                              exc_info=1)
                raise KeyError(
                    _('Internal error when generating %(field)s field '
                      '(Missing key "%(key)s"). Please report this.') % {
                          'field': field,
                          'key': e,
                      })

        return results
Exemplo n.º 16
0
    def get_repository_fields(cls, username, hosting_url, plan, tool_name,
                              field_vars):
        if not cls.supports_repositories:
            raise NotImplementedError

        # Grab the list of fields for population below. We have to do this
        # differently depending on whether or not this hosting service has
        # different repository plans.
        fields = cls._get_field(plan, 'repository_fields')

        new_vars = field_vars.copy()
        new_vars['hosting_account_username'] = username

        if cls.self_hosted:
            new_vars['hosting_url'] = hosting_url
            new_vars['hosting_domain'] = urlparse(hosting_url)[1]

        results = {}

        for field, value in six.iteritems(fields[tool_name]):
            try:
                results[field] = value % new_vars
            except KeyError as e:
                logging.error(
                    'Failed to generate %s field for hosting '
                    'service %s using %s and %r: Missing key %s' %
                    (field, six.text_type(cls.name), value, new_vars, e),
                    exc_info=1)
                raise KeyError(
                    _('Internal error when generating %(field)s field '
                      '(Missing key "%(key)s"). Please report this.') % {
                          'field': field,
                          'key': e,
                      })

        return results