예제 #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))
예제 #2
0
 def test_scopes_as_string(self):
     app = Addon()
     with mock.patch('hipchat.models.Addon.scopes_as_list', lambda x: []):
         self.assertEqual(app.scopes_as_string(), "")
     with mock.patch('hipchat.models.Addon.scopes_as_list', lambda x: ['x']):
         self.assertEqual(app.scopes_as_string(), "x")
     with mock.patch('hipchat.models.Addon.scopes_as_list', lambda x: ['x', 'y']):
         self.assertEqual(app.scopes_as_string(), "x y")
예제 #3
0
 def test_install_url(self):
     app = Addon()
     self.assertIsNone(app.install_url())
     app.save()
     url = reverse('hipchat:install', kwargs={'app_id': app.id})
     self.assertEqual(app.install_url(), get_full_url(url))
예제 #4
0
 def test_descriptor_url(self):
     app = Addon()
     self.assertIsNone(app.descriptor_url())
     app.save()
     url = get_full_url(app.get_absolute_url())
     self.assertEqual(app.descriptor_url(), url)
예제 #5
0
 def test_save(self):
     app = Addon()
     self.assertEqual(app.save(), app)
     self.assertIsNotNone(app.id, None)
예제 #6
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()])