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))
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")
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))
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)
def test_save(self): app = Addon() self.assertEqual(app.save(), app) self.assertIsNotNone(app.id, None)
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()])