Exemplo n.º 1
0
 def test_scopes_as_list(self):
     app = Addon().save()
     scopes = random.sample(list(Scope.objects.all()), 3)
     for scope in scopes:
         app.scopes.add(scope)
     scopes_list = [s.name for s in scopes]
     self.assertEqual(app.scopes_as_list(), sorted(scopes_list))
Exemplo n.º 2
0
    def test_descriptor(self):
        app = Addon()
        app.key = "key"
        app.name = "name"
        app.description = "description"
        app.vendor_name = "ACME"
        app.vendor_url = "example.com"
        app.allow_global = True
        app.allow_room = True
        # before saving we have no URLs to call back to
        # so the descriptor is null
        self.assertEqual(app.descriptor(), None)

        app.save()

        expected = {
            "key": "key",
            "name": "name",
            "description": "description",
            "vendor": {
                "name": "ACME",
                "url": "example.com"
            },
            "links": {
                "self": app.descriptor_url(),
            },
            "capabilities": {
                "hipchatApiConsumer": {
                    "scopes": []
                },
                "installable": {
                    "callbackUrl": app.install_url(),
                    "allowGlobal": True,
                    "allowRoom": True
                },
            },
            # "glance": [g.descriptor() for g in self.glances.all()]
        }
        self.assertEqual(app.descriptor(), expected)

        app.scopes.add(Scope.objects.first())
        scopes = app.descriptor()['capabilities']['hipchatApiConsumer']['scopes']
        self.assertEqual(scopes, app.scopes_as_list())

        glance = Glance(app=app, key='key').save()
        app.glances.add(glance)
        capabilities = app.descriptor()['capabilities']
        self.assertEqual(capabilities['glance'], [glance.descriptor()])