示例#1
0
 def setUp(self):
     """
     Runs before each test.
     """
     self.c = ResourceClient('http://localhost:8000/resources',
                             'sharrock_resource_example', '1.0',
                             'meresource')
示例#2
0
文件: client.py 项目: Python3pkg/Dox
def _get_resource(app,resource,library=True):
    """
    Gets a resource client.
    """
    cfg = get_cfg()
    apikey_setting = 'library_key' if library else 'api_key'
    return ResourceClient('%s/api/resource' % cfg.get('Connection','endpoint'),app,'beta3',resource,auth_user=cfg.get('Connection',apikey_setting))
示例#3
0
class ResourceClientTests(unittest.TestCase):
    """
    Tests for resource client.
    """
    def setUp(self):
        """
        Runs before each test.
        """
        self.c = ResourceClient('http://localhost:8000/resources',
                                'sharrock_resource_example', '1.0',
                                'meresource')

    def tearDown(self):
        """
        Runs after each test.
        """
        self.c = None

    def test_get(self):
        """
        Tests the GET op.
        """
        response = self.c.get()
        self.assertEquals('Get Method executed!', response)

    def test_post(self):
        """
        Tests the POST op.
        """
        response = self.c.post(params={'name': 'posttest'})
        self.assertEquals('Posted posttest', response)

    def test_put(self):
        """
        Tests the PUT op.
        """
        response = self.c.put(params={'name': 'puttest'})
        self.assertEquals('Put this:puttest', response)

    def test_delete(self):
        """
        Tests the delete op.
        """
        response = self.c.delete()
        self.assertEquals('Aaaarrrggghhhh!  I\'m meeelllltttiiinnnngggg!',
                          response)
示例#4
0
文件: tests.py 项目: Axilent/sharrock
class ResourceClientTests(unittest.TestCase):
    """
    Tests for resource client.
    """
    def setUp(self):
        """
        Runs before each test.
        """
        self.c = ResourceClient('http://localhost:8000/resources','sharrock_resource_example','1.0','meresource')
    
    def tearDown(self):
        """
        Runs after each test.
        """
        self.c = None
    
    def test_get(self):
        """
        Tests the GET op.
        """
        response = self.c.get()
        self.assertEquals('Get Method executed!',response)
    
    def test_post(self):
        """
        Tests the POST op.
        """
        response = self.c.post(params={'name':'posttest'})
        self.assertEquals('Posted posttest',response)
    
    def test_put(self):
        """
        Tests the PUT op.
        """
        response = self.c.put(params={'name':'puttest'})
        self.assertEquals('Put this:puttest',response)
    
    def test_delete(self):
        """
        Tests the delete op.
        """
        response = self.c.delete()
        self.assertEquals('Aaaarrrggghhhh!  I\'m meeelllltttiiinnnngggg!',response)
示例#5
0
from sharrock.client import HttpClient, ResourceClient
from django.shortcuts import render_to_response
from django.template import RequestContext
from sharrock.client import HttpClient, ResourceClient
from django.conf import settings
from django.http import HttpResponseRedirect

axl = HttpClient('%s/api' % settings.AXILENT_ENDPOINT,
                 'axilent.content',
                 'beta3',
                 auth_user=settings.AXILENT_API_KEY)
content_resource = ResourceClient('%s/api/resource' %
                                  settings.AXILENT_ENDPOINT,
                                  'axilent.content',
                                  'beta3',
                                  'content',
                                  auth_user=settings.AXILENT_API_KEY)
triggers = HttpClient('%s/api' % settings.AXILENT_ENDPOINT,
                      'axilent.triggers',
                      'beta3',
                      auth_user=settings.AXILENT_API_KEY)


def home(request, whiskey_slug=None):
    """
    Mobile home page.
    """
    featured_whiskey = None
    if whiskey_slug:
        featured_whiskey = axl.getcontentbyuniquefield(
            content_type='Whiskey',
示例#6
0
    def handle(self, *args, **options):
        """
        Handler method.
        """
        # create content type
        content_type = ResourceClient(
            settings.SAASPIRE_RESOURCE_API,
            "saaspire.content",
            "0.1dev",
            "contenttyperesource",
            auth_user=settings.SAASPIRE_API_KEY,
        )
        content_type.post(
            data={
                "name": "Whiskey",
                "slug": "whiskey",
                "content_fields": [
                    {"name": "name", "salience": 99},
                    {"name": "herbs_spice", "salience": 40},
                    {"name": "flowers", "salience": 40},
                    {"name": "fruit", "salience": 40},
                    {"name": "candy", "salience": 70},
                    {"name": "wood", "salience": 50},
                    {"name": "length_of_finish", "salience": 60},
                    {"name": "complexity", "salience": 80},
                    {"name": "smoothness", "salience": 90},
                ],
            }
        )

        # Add whiskey
        content = ResourceClient(
            settings.SAASPIRE_RESOURCE_API,
            "saaspire.content",
            "0.1dev",
            "contentresource",
            auth_user=settings.SAASPIRE_API_KEY,
        )

        for whiskey in Whiskey.objects.all():
            whiskey.saaspire_key = content.post(
                data={
                    "content_type_slug": "whiskey",
                    "content": {
                        "name": whiskey.name,
                        "herbs_spice": unicode(whiskey.herbs_spice),
                        "flowers": unicode(whiskey.flowers),
                        "fruit": unicode(whiskey.fruit),
                        "candy": unicode(whiskey.candy),
                        "wood": unicode(whiskey.wood),
                        "length_of_finish": unicode(whiskey.length_of_finish),
                        "complexity": unicode(whiskey.complexity),
                        "smoothness": unicode(whiskey.smoothness),
                    },
                }
            )

            whiskey.save()

        # create related whiskey policy
        policy = ResourceClient(
            settings.SAASPIRE_RESOURCE_API,
            "saaspire.content",
            "0.1dev",
            "contentpolicyresource",
            auth_user=settings.SAASPIRE_API_KEY,
        )

        policy.post(
            data={
                "name": "Related Whiskey",
                "slug": "related-whiskey",
                "total_return": 3,
                "params": {"content_type_slug": "whiskey"},
                "generators": [{"generator_type": "Related Via Metadata", "weight": 1}],
            }
        )

        # create personalized whiskey policy
        policy.post(
            data={
                "name": "Personalized Whiskey",
                "slug": "personalized-whiskey",
                "total_return": 3,
                "params": {"content_type_slug": "whiskey"},
                "generators": [{"generator_type": "Personalized", "weight": 1}],
            }
        )

        # Add reactor and inferences to graphstack
        reactor = ResourceClient(
            settings.SAASPIRE_RESOURCE_API,
            "saaspire.reactor",
            "0.1dev",
            "reactorresource",
            auth_user=settings.SAASPIRE_API_KEY,
        )
        reactor.post(params={"reactor_type_name": "editorial"})

        inference = ResourceClient(
            settings.SAASPIRE_RESOURCE_API,
            "saaspire.reactor",
            "0.1dev",
            "inferenceresource",
            auth_user=settings.SAASPIRE_API_KEY,
        )

        # Add affinity inference for endorsement triggers
        inference.post(
            data={
                "reactor_type_name": "editorial",
                "name": "Endorsement Inference",
                "inference_type": "Affinity",
                "listeners": [{"category": "whiskey", "action": "endorsement"}],
                "params": {"content_key_param": "whiskey", "content_type": "whiskey", "correlation": 80},
            }
        )

        # Add negative inference for disendorsement triggers
        inference.post(
            data={
                "reactor_type_name": "editorial",
                "name": "Disendorsement Inference",
                "inference_type": "Ban",
                "listeners": [{"category": "whiskey", "action": "disendorsement"}],
                "params": {"content_key_param": "whiskey", "content_type": "whiskey"},
            }
        )
示例#7
0
    def handle(self, *args, **options):
        """
        Handler method.
        """
        # create content type
        content_type = ResourceClient(settings.SAASPIRE_RESOURCE_API,
                                      'saaspire.content',
                                      '0.1dev',
                                      'contenttyperesource',
                                      auth_user=settings.SAASPIRE_API_KEY)
        content_type.post(
            data={
                'name':
                'Whiskey',
                'slug':
                'whiskey',
                'content_fields': [{
                    'name': 'name',
                    'salience': 99
                }, {
                    'name': 'herbs_spice',
                    'salience': 40
                }, {
                    'name': 'flowers',
                    'salience': 40
                }, {
                    'name': 'fruit',
                    'salience': 40
                }, {
                    'name': 'candy',
                    'salience': 70
                }, {
                    'name': 'wood',
                    'salience': 50
                }, {
                    'name': 'length_of_finish',
                    'salience': 60
                }, {
                    'name': 'complexity',
                    'salience': 80
                }, {
                    'name': 'smoothness',
                    'salience': 90
                }]
            })

        # Add whiskey
        content = ResourceClient(settings.SAASPIRE_RESOURCE_API,
                                 'saaspire.content',
                                 '0.1dev',
                                 'contentresource',
                                 auth_user=settings.SAASPIRE_API_KEY)

        for whiskey in Whiskey.objects.all():
            whiskey.saaspire_key = content.post(
                data={
                    'content_type_slug': 'whiskey',
                    'content': {
                        'name': whiskey.name,
                        'herbs_spice': unicode(whiskey.herbs_spice),
                        'flowers': unicode(whiskey.flowers),
                        'fruit': unicode(whiskey.fruit),
                        'candy': unicode(whiskey.candy),
                        'wood': unicode(whiskey.wood),
                        'length_of_finish': unicode(whiskey.length_of_finish),
                        'complexity': unicode(whiskey.complexity),
                        'smoothness': unicode(whiskey.smoothness)
                    }
                })

            whiskey.save()

        # create related whiskey policy
        policy = ResourceClient(settings.SAASPIRE_RESOURCE_API,
                                'saaspire.content',
                                '0.1dev',
                                'contentpolicyresource',
                                auth_user=settings.SAASPIRE_API_KEY)

        policy.post(
            data={
                'name':
                'Related Whiskey',
                'slug':
                'related-whiskey',
                'total_return':
                3,
                'params': {
                    'content_type_slug': 'whiskey'
                },
                'generators': [{
                    'generator_type': 'Related Via Metadata',
                    'weight': 1
                }]
            })

        # create personalized whiskey policy
        policy.post(
            data={
                'name': 'Personalized Whiskey',
                'slug': 'personalized-whiskey',
                'total_return': 3,
                'params': {
                    'content_type_slug': 'whiskey'
                },
                'generators': [{
                    'generator_type': 'Personalized',
                    'weight': 1
                }]
            })

        # Add reactor and inferences to graphstack
        reactor = ResourceClient(settings.SAASPIRE_RESOURCE_API,
                                 'saaspire.reactor',
                                 '0.1dev',
                                 'reactorresource',
                                 auth_user=settings.SAASPIRE_API_KEY)
        reactor.post(params={'reactor_type_name': 'editorial'})

        inference = ResourceClient(settings.SAASPIRE_RESOURCE_API,
                                   'saaspire.reactor',
                                   '0.1dev',
                                   'inferenceresource',
                                   auth_user=settings.SAASPIRE_API_KEY)

        # Add affinity inference for endorsement triggers
        inference.post(
            data={
                'reactor_type_name': 'editorial',
                'name': 'Endorsement Inference',
                'inference_type': 'Affinity',
                'listeners': [{
                    'category': 'whiskey',
                    'action': 'endorsement'
                }],
                'params': {
                    'content_key_param': 'whiskey',
                    'content_type': 'whiskey',
                    'correlation': 80
                }
            })

        # Add negative inference for disendorsement triggers
        inference.post(
            data={
                'reactor_type_name': 'editorial',
                'name': 'Disendorsement Inference',
                'inference_type': 'Ban',
                'listeners': [{
                    'category': 'whiskey',
                    'action': 'disendorsement'
                }],
                'params': {
                    'content_key_param': 'whiskey',
                    'content_type': 'whiskey'
                }
            })
示例#8
0
def resource(axilent_app,resource):
    """
    Gets a resource client.
    """
    return ResourceClient('%s%s' % (end_point,resource_path),axilent_app,api_version,resource,auth_user=api_key)
示例#9
0
文件: tests.py 项目: Axilent/sharrock
 def setUp(self):
     """
     Runs before each test.
     """
     self.c = ResourceClient('http://localhost:8000/resources','sharrock_resource_example','1.0','meresource')