Esempio n. 1
0
    def test_crud(self):
        service = client.connect(**self.opts.kwargs)

        appname = "sdk-test-app"

        testlib.delete_app(service, appname)
        self.assertFalse(appname in service.apps)

        kwargs = {
            'author': "Me",
            'description': "Test app description",
            'label': "SDK Test",
            'manageable': False,
            'template': "barebones",
            'visible': True,
        }
        service.apps.create(appname, **kwargs)
        self.assertTrue(appname in service.apps)
        app = service.apps[appname]
        self.assertEqual(app['author'], "Me")
        self.assertEqual(app['label'], "SDK Test")
        self.assertEqual(app['manageable'], "0")
        self.assertEqual(app['visible'], "1")

        kwargs = {
            'author': "SDK",
            'visible': False,
        }
        app = service.apps[appname]
        app.update(**kwargs)
        app.refresh()
        self.assertEqual(app['author'], "SDK")
        self.assertEqual(app['label'], "SDK Test")
        self.assertEqual(app['manageable'], "0")
        self.assertEqual(app['visible'], "0")

        testlib.delete_app(service, appname)
        self.assertFalse(appname in service.apps)
Esempio n. 2
0
    def test_crud(self):
        service = client.connect(**self.opts.kwargs)

        # There is no way to delete a conf file via the REST API, so we 
        # create a test app to use as the context fo the conf test and then 
        # we cleanup by deleting the app.

        app_name = "sdk-test-app"

        # Delete any lingering test app
        testlib.delete_app(service, app_name)
        self.assertFalse(app_name in service.apps)

        # Create a fresh test app
        service.apps.create(app_name)
        self.assertTrue(app_name in service.apps)

        # Connect using the test app context
        kwargs = self.opts.kwargs.copy()
        kwargs['app'] = app_name
        kwargs['owner'] = "nobody"
        kwargs['sharing'] = "app"
        service = client.connect(**kwargs)

        conf_name = "sdk-test-conf"

        confs = service.confs
        self.assertFalse(conf_name in confs)

        conf = confs.create(conf_name)
        self.assertTrue(conf_name in confs)
        self.assertEqual(conf.name, conf_name)

        stanzas = conf.list()
        self.assertEqual(len(stanzas), 0)

        conf.create("stanza1")
        self.assertEqual(len(conf.list()), 1)
        self.assertTrue("stanza1" in conf)
        self.assertFalse("stanza2" in conf)
        self.assertFalse("stanza3" in conf)

        conf.create("stanza2")
        self.assertEqual(len(conf.list()), 2)
        self.assertTrue("stanza1" in conf)
        self.assertTrue("stanza2" in conf)
        self.assertFalse("stanza3" in conf)

        conf.create("stanza3")
        self.assertEqual(len(conf.list()), 3)
        self.assertTrue("stanza1" in conf)
        self.assertTrue("stanza2" in conf)
        self.assertTrue("stanza3" in conf)

        stanza1 = conf['stanza1']
        self.assertFalse('key1' in stanza1.content)
        self.assertFalse('key2' in stanza1.content)
        self.assertFalse('key3' in stanza1.content)

        stanza1.update(key1="value1")
        stanza1.refresh()
        self.assertTrue('key1' in stanza1.content)
        self.assertFalse('key2' in stanza1.content)
        self.assertFalse('key3' in stanza1.content)
        self.check_content(stanza1, key1="value1")

        stanza1.update(key2="value2")
        stanza1.refresh()
        self.assertTrue('key1' in stanza1.content)
        self.assertTrue('key2' in stanza1.content)
        self.assertFalse('key3' in stanza1.content)
        self.check_content(stanza1, key1="value1", key2="value2")

        stanza1.update(key3=42)
        stanza1.refresh()
        self.assertTrue('key1' in stanza1.content)
        self.assertTrue('key2' in stanza1.content)
        self.assertTrue('key3' in stanza1.content)
        self.check_content(stanza1, key1="value1", key2="value2", key3=42)

        conf.delete("stanza3")
        self.assertEqual(len(conf.list()), 2)
        self.assertTrue("stanza1" in conf)
        self.assertTrue("stanza2" in conf)
        self.assertFalse("stanza3" in conf)

        conf.delete("stanza2")
        self.assertEqual(len(conf.list()), 1)
        self.assertTrue("stanza1" in conf)
        self.assertFalse("stanza2" in conf)
        self.assertFalse("stanza3" in conf)

        conf.delete("stanza1")
        self.assertEqual(len(conf.list()), 0)
        self.assertFalse("stanza1" in conf)
        self.assertFalse("stanza2" in conf)
        self.assertFalse("stanza3" in conf)

        # Reconnect using original context so we can cleaup the test app
        service = client.connect(**self.opts.kwargs)
        testlib.delete_app(service, app_name)
        self.assertFalse(app_name in service.apps)
Esempio n. 3
0
    def test_namespaces(self):
        kwargs = self.opts.kwargs.copy()

        # Verify connect with no namespace
        service = client.connect(**kwargs)
        service.apps()

        # Verify namespace permutations using standard app & owner args 
        kwargs.update({ 'app': "search", 'owner': None })
        service_ns = client.connect(**kwargs)
        service_ns.apps()

        kwargs.update({ 'app': "search", 'owner': "-" })
        service_ns = client.connect(**kwargs)
        service_ns.apps()

        kwargs.update({ 'app': None, 'owner': "admin" })
        service_ns = client.connect(**kwargs)
        service_ns.apps()

        kwargs.update({ 'app': "-", 'owner': "admin" })
        service_ns = client.connect(**kwargs)
        service_ns.apps()

        kwargs.update({ 'app': "search", 'owner': "admin" })
        service_ns = client.connect(**kwargs)
        service_ns.apps()

        appname = "sdk-test-app"
        username = "******"
        testlib.delete_app(service, appname)
        if username in service.users: service.users.delete(username)
        self.assertFalse(service.apps.contains(appname))
        self.assertFalse(service.users.contains(username))

        # App & owner dont exist, verify that the following errors
        kwargs.update({ 'app': appname, 'owner': username })
        with self.assertRaises(HTTPError):
            service_ns = client.connect(**kwargs)
            service_ns.apps()

        # Validate namespace permutations with new app & user
        service.apps.create(appname)
        service.users.create(username, password="******", roles="power")

        kwargs.update({ 'app': appname, 'owner': None })
        service_ns = client.connect(**kwargs)
        service_ns.apps()

        kwargs.update({ 'app': appname, 'owner': "-" })
        service_ns = client.connect(**kwargs)
        service_ns.apps()

        kwargs.update({ 'app': None, 'owner': username })
        service_ns = client.connect(**kwargs)
        service_ns.apps()

        kwargs.update({ 'app': "-", 'owner': username })
        service_ns = client.connect(**kwargs)
        service_ns.apps()

        kwargs.update({ 'app': appname, 'owner': username })
        service_ns = client.connect(**kwargs)
        service_ns.apps()

        # Cleanup
        testlib.delete_app(service, appname)
        service.users.delete(username)

        self.assertFalse(service.apps.contains(appname))
        self.assertFalse(service.users.contains(username))