示例#1
0
    def _actions(self):
        """
        Gets the list of actions in an appropriately SIREN format

        :return: The list of actions
        :rtype: list
        """
        actions = []
        for endpoint, options in six.iteritems(
                self.resource.endpoint_dictionary()):
            options = options[0]
            all_methods = options.get('methods', ('GET', ))
            meth = all_methods[0] if all_methods else 'GET'
            base_route = options.get('route', self.resource.base_url)
            route = create_url(base_route, **self.resource.properties)
            route = self.combine_base_url_with_resource_url(route)
            fields = self.generate_fields_for_endpoint_funct(
                options.get('endpoint_func'))
            actn = dict(name=endpoint,
                        title=titlize_endpoint(endpoint),
                        method=meth,
                        href=route,
                        fields=fields)
            actions.append(actn)
        return actions
示例#2
0
    def test_titlelize_endpoint(self):
        """
        Tests whether an underscored function name
        is properly converted into a title
        """
        name = "some_name_or_something"
        expected = "Some Name Or Something"
        updated = titlize_endpoint(name)
        self.assertEqual(updated, expected)

        name = '_some_name_or_something'
        updated = titlize_endpoint(name)
        self.assertEqual(updated, expected)

        name = 'some_name_or_something_'
        updated = titlize_endpoint(name)
        self.assertEqual(updated, expected)
示例#3
0
    def test_titlelize_endpoint(self):
        """
        Tests whether an underscored function name
        is properly converted into a title
        """
        name = "some_name_or_something"
        expected = "Some Name Or Something"
        updated = titlize_endpoint(name)
        self.assertEqual(updated, expected)

        name = '_some_name_or_something'
        updated = titlize_endpoint(name)
        self.assertEqual(updated, expected)

        name = 'some_name_or_something_'
        updated = titlize_endpoint(name)
        self.assertEqual(updated, expected)
 def _actions(self):
     actions = []
     for endpoint, options in six.iteritems(self.resource.endpoint_dictionary()):
         options = options[0]
         all_methods = options.get('methods', ('GET',))
         meth = all_methods[0] if all_methods else 'GET'
         base_route = options.get('route', self.resource.base_url)
         route = create_url(base_route, **self.resource.properties)
         route = self.combine_base_url_with_resource_url(route)
         fields = self.generate_fields_for_endpoint_funct(options.get('endpoint_func'))
         actn = dict(name=endpoint, title=titlize_endpoint(endpoint),
                     method=meth, href=route, fields=fields)
         actions.append(actn)
     return actions