def main(suites, test_config_dir=None): config = setup(TEST_CONFIG, TEST_ADMIN_ID, TEST_ADMIN_PKEY_PATH, testdir=test_config_dir) if len(suites) == 0: # run all suites suite_funcs = get_test_suites() suites = [sf.name for sf in suite_funcs] if suites[0] == "list_suites": suite_funcs = get_test_suites() print "All test suites:" print "\n".join( [" " + s.name + "\n " + s.description for s in suite_funcs]) sys.exit(0) else: # run the suites suite_funcs = get_test_suites(suites) log.info("Run tests %s" % [sf.name for sf in suite_funcs]) for sf in suite_funcs: sf()
def test_read_users(): # admin can read all users try: log.info("Read user as admin") ret = test( "read_user", "*****@*****.**" ) check_result_present( ret, USER_ATTRS ) except Exception, e: abort("Admin failed to read user [email protected]", exception=e )
def test_create_users(): # make a normal user try: log.info("Create normal user") ret = test( "create_user", "*****@*****.**", "http://www.vicci.org/id/[email protected]", "MAKE_SIGNING_KEY" ) check_result_present( ret, USER_ATTRS ) except Exception, e: abort("Failed to create [email protected]", exception=e )
def test_create_user_bad_args(): # test no arguments try: log.info("Create user: Missing arguments") ret = test( "create_user", "*****@*****.**" ) abort("Created user with missing arguments") except Exception, e: result( e.message ) pass
def test_read_users(): # admin can read all users try: log.info("Read user as admin") ret = test("read_user", "*****@*****.**") check_result_present(ret, USER_ATTRS) except Exception, e: abort("Admin failed to read user [email protected]", exception=e)
def test_create_user_bad_args(): # test no arguments try: log.info("Create user: Missing arguments") ret = test("create_user", "*****@*****.**") abort("Created user with missing arguments") except Exception, e: result(e.message) pass
def test( method_name, *args, **kw ): syntool_args = ['-c', CONFIG_PATH] if kw.has_key("syntool_args"): syntool_args.append( kw['syntool_args'] ) argv = ['syntool.py'] + syntool_args + [method_name] + build_argv( *args, **kw ) log.info( "Test '%s" % " ".join(argv) ) return syntool.main( argv )
def test_delete_users(): # user can't delete an admin try: log.info("Delete admin with user account") ret = test( "delete_user", "*****@*****.**", syntool_args=['-u', '*****@*****.**'] ) abort("Unprivileged user deleted an admin") except Exception, e: log.info(e.message) pass
def test(method_name, *args, **kw): syntool_args = ['-c', CONFIG_PATH] if kw.has_key("syntool_args"): syntool_args.append(kw['syntool_args']) argv = ['syntool.py'] + syntool_args + [method_name] + build_argv( *args, **kw) log.info("Test '%s" % " ".join(argv)) return syntool.main(argv)
def test_create_users(): # make a normal user try: log.info("Create normal user") ret = test("create_user", "*****@*****.**", "http://www.vicci.org/id/[email protected]", "MAKE_SIGNING_KEY") check_result_present(ret, USER_ATTRS) except Exception, e: abort("Failed to create [email protected]", exception=e)
def test_delete_users(): # user can't delete an admin try: log.info("Delete admin with user account") ret = test("delete_user", "*****@*****.**", syntool_args=['-u', '*****@*****.**']) abort("Unprivileged user deleted an admin") except Exception, e: log.info(e.message) pass
def setup( test_config_text, test_user_id, test_user_pkey_path, testdir=None ): global CONFIG_PATH # set up a test directory if testdir == None: testdir = os.tempnam( "/tmp", "test-syntool-" ) os.mkdir( testdir ) write_config( testdir, test_config_text ) log.info("Test config in %s" % testdir ) config_path = os.path.join( testdir, "syndicate.conf" ) config = load_config( config_path ) # copy over our test admin key shutil.copyfile( test_user_pkey_path, conf.object_signing_key_filename( config, "user", test_user_id ) ) CONFIG_PATH = config_path return config
def main( suites, test_config_dir=None ): config = setup( TEST_CONFIG, TEST_ADMIN_ID, TEST_ADMIN_PKEY_PATH, testdir=test_config_dir ) if len(suites) == 0: # run all suites suite_funcs = get_test_suites() suites = [sf.name for sf in suite_funcs] if suites[0] == "list_suites": suite_funcs = get_test_suites() print "All test suites:" print "\n".join( [" " + s.name + "\n " + s.description for s in suite_funcs] ) sys.exit(0) else: # run the suites suite_funcs = get_test_suites( suites ) log.info("Run tests %s" % [sf.name for sf in suite_funcs]) for sf in suite_funcs: sf()
def setup(test_config_text, test_user_id, test_user_pkey_path, testdir=None): global CONFIG_PATH # set up a test directory if testdir == None: testdir = os.tempnam("/tmp", "test-syntool-") os.mkdir(testdir) write_config(testdir, test_config_text) log.info("Test config in %s" % testdir) config_path = os.path.join(testdir, "syndicate.conf") config = load_config(config_path) # copy over our test admin key shutil.copyfile( test_user_pkey_path, conf.object_signing_key_filename(config, "user", test_user_id)) CONFIG_PATH = config_path return config
def inner(*args, **kw): log.info("--- Suite: %s ---" % self.name) return func(*args, **kw)
@Suite("create_user_bad_args", "Test creating users with missing or invalid arguments") def test_create_user_bad_args(): # test no arguments try: log.info("Create user: Missing arguments") ret = test( "create_user", "*****@*****.**" ) abort("Created user with missing arguments") except Exception, e: result( e.message ) pass print "" # test invalid arguments try: log.info("Create user: Invalid arguments") ret = test( "create_user", "not an email", "http://www.vicci.org/id/foo", "MAKE_SIGNING_KEY" ) abort("Created user with invalid email address") except Exception, e: result( e.message ) pass print "" return True #------------------------------- @Suite("create_users", "Try creating admins and regular users, ensuring that admins can create users; users cannot create admins; duplicate users are forbidden.") def test_create_users(): # make a normal user
"Test creating users with missing or invalid arguments") def test_create_user_bad_args(): # test no arguments try: log.info("Create user: Missing arguments") ret = test("create_user", "*****@*****.**") abort("Created user with missing arguments") except Exception, e: result(e.message) pass print "" # test invalid arguments try: log.info("Create user: Invalid arguments") ret = test("create_user", "not an email", "http://www.vicci.org/id/foo", "MAKE_SIGNING_KEY") abort("Created user with invalid email address") except Exception, e: result(e.message) pass print "" return True #------------------------------- @Suite( "create_users",