def setUp(self): self.mgr = KBaseWSNotebookManager()
class NarrBaseTestCase(unittest.TestCase): # Before test: # - Log in (for tests that require login) # also sets the token in the environment variable so the manager can get to it. @classmethod def setUpClass(self): self.user_id = test_user_id self.pwd = getpass("Password for {}: ".format(test_user_id)) self.token = biokbase.auth.Token(user_id=self.user_id, password=self.pwd) # by default, user's left logged out @classmethod def setUp(self): self.mgr = KBaseWSNotebookManager() @classmethod def tearDown(self): self.logout() pass @classmethod def tearDownClass(self): pass @classmethod def login(self): biokbase.auth.set_environ_token(self.token.token) @classmethod def logout(self): biokbase.auth.set_environ_token(None) def test_manager_instantiated(self): self.assertIsInstance( self.mgr, biokbase.narrative.kbasewsmanager.KBaseWSNotebookManager) # test get_userid() def test_user_id_loggedin(self): self.login() self.assertEquals(self.mgr.get_userid(), self.user_id) # test get_userid() def test_user_id_loggedout(self): self.assertEquals(self.mgr.get_userid(), None) # test wsclient() def test_wsclient(self): self.assertIsInstance(self.mgr.wsclient(), Workspace) # test info_string (just make sure it's a string) def test_info_string(self): self.assertIsInstance(self.mgr.info_string(), basestring) # test list notebooks while logged in returns a list of strings def test_list_notebooks_loggedin(self): self.login() self.test_list_notebooks() def test_list_notebooks_loggedout(self): self.test_list_notebooks() def test_list_notebooks(self): nb_list = self.mgr.list_notebooks() # assert we actually get something self.assertIsInstance(nb_list, list) # assert it's a list of formatted dicts format_failure = self.check_nb_list_format(nb_list) self.assertIsNone(format_failure) def check_nb_list_format(self, nb_list): for nb_info in nb_list: if not 'name' in nb_info: return 'Missing a "name" key!' if not 'notebook_id' in nb_info: return 'Missing a "notebook_id key!' if not name_regex.match(nb_info['name']): return 'Incorrect format for "name" key: {}'.format( nb_info['name']) if not obj_regex.match(nb_info['notebook_id']): return 'Incorrect format for "notebook_id" key: {}'.format( nb_info['notebook_id']) # If we make it this far, don't return anything! Hooray! return None def test_clean_id(self): spacey_str = 'test test test test test' unspacey_str = 'test_test__test_test___test' self.assertEquals(self.mgr._clean_id(spacey_str), unspacey_str)
class NarrBaseTestCase(unittest.TestCase): # Before test: # - Log in (for tests that require login) # also sets the token in the environment variable so the manager can get to it. @classmethod def setUpClass(self): self.user_id = test_user_id self.pwd = getpass("Password for {}: ".format(test_user_id)) self.token = biokbase.auth.Token(user_id=self.user_id, password=self.pwd) # by default, user's left logged out @classmethod def setUp(self): self.mgr = KBaseWSNotebookManager() @classmethod def tearDown(self): self.logout() pass @classmethod def tearDownClass(self): pass @classmethod def login(self): biokbase.auth.set_environ_token(self.token.token) @classmethod def logout(self): biokbase.auth.set_environ_token(None) def test_manager_instantiated(self): self.assertIsInstance(self.mgr, biokbase.narrative.kbasewsmanager.KBaseWSNotebookManager) # test get_userid() def test_user_id_loggedin(self): self.login() self.assertEquals(self.mgr.get_userid(), self.user_id) # test get_userid() def test_user_id_loggedout(self): self.assertEquals(self.mgr.get_userid(), None) # test wsclient() def test_wsclient(self): self.assertIsInstance(self.mgr.wsclient(), Workspace) # test info_string (just make sure it's a string) def test_info_string(self): self.assertIsInstance(self.mgr.info_string(), basestring) # test list notebooks while logged in returns a list of strings def test_list_notebooks_loggedin(self): self.login() self.test_list_notebooks() def test_list_notebooks_loggedout(self): self.test_list_notebooks() def test_list_notebooks(self): nb_list = self.mgr.list_notebooks() # assert we actually get something self.assertIsInstance(nb_list, list) # assert it's a list of formatted dicts format_failure = self.check_nb_list_format(nb_list) self.assertIsNone(format_failure) def check_nb_list_format(self, nb_list): for nb_info in nb_list: if not 'name' in nb_info: return 'Missing a "name" key!' if not 'notebook_id' in nb_info: return 'Missing a "notebook_id key!' if not name_regex.match(nb_info['name']): return 'Incorrect format for "name" key: {}'.format(nb_info['name']) if not obj_regex.match(nb_info['notebook_id']): return 'Incorrect format for "notebook_id" key: {}'.format(nb_info['notebook_id']) # If we make it this far, don't return anything! Hooray! return None def test_clean_id(self): spacey_str = 'test test test test test' unspacey_str = 'test_test__test_test___test' self.assertEquals(self.mgr._clean_id(spacey_str), unspacey_str)