def test_fakeserver_getComment(): s = FakeConfluenceServer() aid = '917540' comment = s.getComment(aid) assert isinstance(comment , dict ) assert len(comment) > 0 assert 'id' in comment
def test_fakeserver_getAttachments(): s = FakeConfluenceServer() pid = '917518' attachments = s.getAttachments(pid) assert isinstance(attachments , list ) assert len(attachments) > 0 assert 'fileSize' in attachments[0]
def test_fakeserver_getComments(): s = FakeConfluenceServer() pid = '917518' comments = s.getComments(pid) assert isinstance(comments, list) assert len(comments) > 0 assert 'id' in comments[0]
def test_fakeserver_getComment(): s = FakeConfluenceServer() aid = '917540' comment = s.getComment(aid) assert isinstance(comment, dict) assert len(comment) > 0 assert 'id' in comment
def test_fakeserver_getAttachmentData(): s = FakeConfluenceServer() pid = '917518' fn = 'testdata.pdf' data = s.getAttachmentData(pid, fn) assert hasattr(data, 'data') assert len(data.data) == 3144
def test_fakeserver_getComments(): s = FakeConfluenceServer() pid = '917518' comments = s.getComments(pid) assert isinstance(comments , list ) assert len(comments) > 0 assert 'id' in comments[0]
def test_fakeserver_getAttachments(): s = FakeConfluenceServer() pid = '917518' attachments = s.getAttachments(pid) assert isinstance(attachments, list) assert len(attachments) > 0 assert 'fileSize' in attachments[0]
def test_fakeserver_moveAttachment(): s = FakeConfluenceServer() pid = '917518' fn = '2013-11-15 12.00.32_2.jpg' newpid = '917519' newfn = 'testdata2.pdf' success = s.moveAttachment(pid, fn, newpid, newfn) assert success == True
def test_fakeserver_removeComment(): s = FakeConfluenceServer() aid = '917540' comment = s.getComment(aid) assert isinstance(comment , dict ) assert s.removeComment(aid) == True assert s.getComment(aid) == None assert s.removeComment(aid) == False
def test_fakeserver_addAttachment(): s = FakeConfluenceServer() pid = '917518' fn = 'testdata.pdf' binary_testfile = Binary("test string") struct = dict(fileName=fn, contentType='text/csv') attachment = s.addAttachment(pid, struct, binary_testfile) assert set(attachment.keys()) == {'id', 'pageId', 'title', 'fileName', 'fileSize', 'contentType', 'created', 'creator', 'url', 'comment'}
def test_fakeserver_getAttachment(): s = FakeConfluenceServer() #aid = '1081345' pid = '917518' fileName = '2013-11-15 12.00.32_2.jpg' attachment = s.getAttachment(pid, fileName) assert isinstance(attachment , dict ) assert len(attachment) > 0 assert 'fileSize' in attachment
def test_fakeserver_getAttachment(): s = FakeConfluenceServer() #aid = '1081345' pid = '917518' fileName = '2013-11-15 12.00.32_2.jpg' attachment = s.getAttachment(pid, fileName) assert isinstance(attachment, dict) assert len(attachment) > 0 assert 'fileSize' in attachment
def test_fakeserver_getpage(): s = FakeConfluenceServer() pid = '524296' p = s.getPage(pid) assert p['id'] == pid assert p['content'] == '' assert p['creator'] == 'scholer' p2 = s.getPage(pageTitle="2013_Aarhus", spaceKey="~scholer") assert p2['id'] == '524308' assert p2['creator'] == 'admin'
def test_fakeserver_addAttachment(): s = FakeConfluenceServer() pid = '917518' fn = 'testdata.pdf' binary_testfile = Binary("test string") struct = dict(fileName=fn, contentType='text/csv') attachment = s.addAttachment(pid, struct, binary_testfile) assert set(attachment.keys()) == { 'id', 'pageId', 'title', 'fileName', 'fileSize', 'contentType', 'created', 'creator', 'url', 'comment' }
def test_fakeserver_editComment(): s = FakeConfluenceServer() aid = '917540' comment = s.getComment(aid) assert isinstance(comment, dict) c2 = copy.deepcopy(comment) new_comment = dict(c2, content="Edited content moy bueno.") updated = s.editComment(new_comment) assert updated['content'] == "Edited content moy bueno." assert updated['id'] == '917540' assert updated['creator'] == 'scholer'
def test_fakeserver_editComment(): s = FakeConfluenceServer() aid = '917540' comment = s.getComment(aid) assert isinstance(comment , dict ) c2 = copy.deepcopy(comment) new_comment = dict(c2, content= "Edited content moy bueno.") updated = s.editComment(new_comment) assert updated['content'] == "Edited content moy bueno." assert updated['id'] == '917540' assert updated['creator'] == 'scholer'
def test_fakeserver_removepage(): """ This is not yet complete, I need to define what happens when removing a non-existing page... """ s = FakeConfluenceServer() pid = '524296' p = s.getPage(pid) assert p['id'] == pid #assert s.removePage(pid) == None assert s.removePage(pid) == True assert s.getPage(pid) == None assert s.removePage(pid) == False
def test_fakeserver_updatePage(): s = FakeConfluenceServer() # Updating an existing page: pid = '524296' p1 = s.getPage(pid) p1_org = copy.deepcopy(p1) p2 = copy.deepcopy(p1) assert p2['id'] == pid p2['content'] = "New content" p3 = s.storePage(p2) assert p3['content'] == "New content" assert p3['modifier'] == s.Username assert int(p3['version']) == int(p1_org['version']) + 1
def ch_with_server_and_manager(): ch = FakeConfighandler() server = FakeConfluenceServer(confighandler=ch) ch.Singletons.setdefault('server', server) em = ExperimentManager(ch) ch.Singletons.setdefault('experimentmanager', em) return ch
def em_with_ch_with_fakeserver(): confighandler = ExpConfigHandler(pathscheme='test1') server = FakeConfluenceServer(autologin=True, ui=None, confighandler=confighandler) confighandler.Singletons['server'] = server em = ExperimentManager(confighandler=confighandler) return em, confighandler, server
def test_fakeserver_storePage(): s = FakeConfluenceServer() # Updating an existing page: pid = '524296' p1 = s.getPage(pid) p1_org = copy.deepcopy(p1) p2 = copy.deepcopy(p1) assert p2['id'] == pid p2['content'] = "New content" p3 = s.storePage(p2) assert p3['content'] == "New content" assert p3['creator'] == p1_org['creator'] assert p3['modifier'] == s.Username assert int(p3['version']) == int(p1_org['version']) + 1 ## Adding a new page: new_page = dict(content="new page content", space="~scholer", title="New testing page") ret_page = s.storePage(new_page) assert ret_page['content'] == "new page content" assert ret_page['creator'] == s.Username assert ret_page['modifier'] == s.Username assert ret_page['version'] == str(1)
def test_fakeserver_removeComment(): s = FakeConfluenceServer() aid = '917540' comment = s.getComment(aid) assert isinstance(comment, dict) assert s.removeComment(aid) == True assert s.getComment(aid) == None assert s.removeComment(aid) == False
def em_with_fake_ch_and_patched_server(monkeypatch): """ Returns em, confighandler, server where em is an experimentmanager with fake confighandler and fake server, and where the fake server has patched: - getChildren """ confighandler = ExpConfigHandler(pathscheme='test1') server = FakeConfluenceServer(autologin=True, ui=None, confighandler=confighandler) confighandler.Singletons['server'] = server em = ExperimentManager(confighandler=confighandler) def test_pagesummaries(self): summaries = [ { 'id': '01', 'space': '~scholer', 'parentId': '524296', 'title': 'RS001 Testpage01', 'url': None, 'permissions': 0 }, { 'id': '02', 'space': '~scholer', 'parentId': '524296', 'title': 'Testpage02', 'url': None, 'permissions': 0 }, { 'id': '03', 'space': '~scholer', 'parentId': '524296', 'title': 'RS003 Testpage03', 'url': None, 'permissions': 0 }, ] return summaries monkeypatch.setattr(server, 'getChildren', test_pagesummaries) return em, confighandler, server
def test_fakeserver_removeAttachment(): s = FakeConfluenceServer() pid = '917518' fn = '2013-11-15 12.00.32_2.jpg' success = s.removeAttachment(pid, fn) assert success == True
def test_fakeserver_updatePage(): s = FakeConfluenceServer() s.getAttachment
def test_fakeserver_basics(): s = FakeConfluenceServer() assert isinstance(s.getServerInfo(), dict) assert isinstance(s.getSpaces(), list) assert isinstance(s.getPages('~scholer'), list)
def test_fakeserver_basics(): s = FakeConfluenceServer() assert isinstance(s.getServerInfo(), dict) assert isinstance( s.getSpaces(), list ) assert isinstance( s.getPages('~scholer'), list )
logging.getLogger("model.server").setLevel(logging.DEBUG) logging.getLogger("model.limspage").setLevel(logging.DEBUG) logging.getLogger("model.page").setLevel(logging.DEBUG) logging.getLogger("model.model_testdoubles.fake_confighandler").setLevel(logging.DEBUG) logging.getLogger("model.model_testdoubles.fake_server").setLevel(logging.DEBUG) logging.getLogger("tkui.lims_app").setLevel(logging.DEBUG) logging.getLogger("tkui.lims_tkroot").setLevel(logging.DEBUG) #logging.getLogger("tkui.views.lims_frame").setLevel(logging.DEBUG) logging.getLogger(__name__).setLevel(logging.DEBUG) logger.debug("Loggers setting to debug level...") pathscheme = argsns.pathscheme or 'test1' logger.info( "Enabling testing environment..." ) confighandler = FakeConfighandler(pathscheme=pathscheme) # set basedir for exp: confighandler.ConfigPaths['exp'] = os.path.join('tests', 'test_data', 'test_filestructure', 'labfluence_data_testsetup', '.labfluence.yml') server = FakeConfluenceServer(confighandler=confighandler) else: logger.debug(">>>>>> Initiating real confighandler and server... >>>>>>") pathscheme = argsns.pathscheme or 'default1' confighandler = ExpConfigHandler(pathscheme=argsns.pathscheme) logger.debug("<<<<< Confighandler instantiated, Initiating server... >>>>>") # setting autologin=False during init should defer login attempt... server = ConfluenceXmlRpcServer(autologin=False, confighandler=confighandler) server._autologin = True # Init server and application: confighandler.Singletons['server'] = server logger.debug("<<<<< Server instantiated, starting LimsApp... >>>>>") limsapp = LimsApp(confighandler) logger.debug("LimsApp instantiated, adding files: %s", argsns.files) limsapp.FilesToAdd = argsns.files
logging.getLogger("model.server").setLevel(logging.DEBUG) logging.getLogger("model.model_testdoubles.fake_confighandler").setLevel(logging.DEBUG) logging.getLogger("model.model_testdoubles.fake_server").setLevel(logging.DEBUG) logging.getLogger("tkui.labfluence_tkapp").setLevel(logging.DEBUG) logging.getLogger("tkui.labfluence_tkroot").setLevel(logging.DEBUG) logging.getLogger("tkui.mainframe").setLevel(logging.DEBUG) logging.getLogger(__name__).setLevel(logging.DEBUG) logger.debug("Loggers setting to debug level...") pathscheme = argsns.pathscheme or 'test1' logger.info( "Enabling testing environment..." ) confighandler = FakeConfighandler(pathscheme=pathscheme) # set basedir for exp: confighandler.ConfigPaths['exp'] = os.path.join('tests', 'test_data', 'test_filestructure', 'labfluence_data_testsetup', '.labfluence.yml') server = FakeConfluenceServer(confighandler=confighandler) else: logger.debug(" >>>>>> Initiating real confighandler and server... >>>>>>") pathscheme = argsns.pathscheme or 'default1' confighandler = ExpConfigHandler(pathscheme='default1') try: logger.debug("Confighandler instantiated, Initiating server... >>>>>>") # setting autologin=False during init should defer login attempt... server = ConfluenceXmlRpcServer(autologin=False, confighandler=confighandler) server._autologin = True except socket.error as e: logger.error( "Socket error during server init ('%s'). This should not happen; autologin is shielded by try-clause.", e) server = None confighandler.Singletons['server'] = server
def fakeconfighandler(): ch = FakeConfighandler(pathscheme='test1') server = FakeConfluenceServer(autologin=True, ui=None, confighandler=ch) ch.Singletons['server'] = server return ch
def fakeserver(fakeconfighandler): return FakeConfluenceServer(fakeconfighandler)
def main(): ############################## ###### Parse arguments: ###### ############################## #argsns = parser.parse_args() # produces a namespace, not a dict. argsns = parse_args() ####################################### ### Set up standard logging system #### ####################################### loghandlers = init_logging(argsns, prefix="labfluence_cmd") ############################ #### Set up logging: #### ############################ #logfmt = "%(levelname)s %(name)s:%(lineno)s %(funcName)s() > %(message)s" #try: # loglevel = int(argsns.loglevel) #except ValueError: # loglevel = argsns.loglevel.upper() ##logfmt = "%(levelname)s:%(name)s: %(funcName)s() :: %(message)s" #if argsns.debug is None: # #and 'all' in argsns.debug: # logging.basicConfig(level=loglevel, format=logfmt) ## argsns.debug is a list (possibly empty) #elif argsns.debug: ## argsns.debug is a non-empty list # logging.basicConfig(level=loglevel, format=logfmt) # for mod in argsns.debug: # logger.info("Enabling logging debug messages for module: %s", mod) # logging.getLogger(mod).setLevel(logging.DEBUG) #else: # # argsns.debug is an empty list # logging.basicConfig(level=min(logging.DEBUG, loglevel), format=logfmt) #logging.getLogger("__main__").setLevel(logging.DEBUG) # #if argsns.logtofile or True: # always log for now... # # based on http://docs.python.org/2/howto/logging-cookbook.html # if not os.path.exists('logs'): # os.mkdir('logs') # if argsns.testing: # fh = logging.FileHandler('logs/labfluence_cmd_testing.log') # else: # fh = logging.FileHandler('logs/labfluence_cmd_debug.log') # fh.setLevel(logging.DEBUG) # formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') # fh.setFormatter(formatter) # logging.getLogger('').addHandler(fh) # logging.root == logging.getLogger('') #################################################################################### # Set up confighandler, etc (depending on whether testing mode is requested...) #### #################################################################################### if argsns.testing: logging.getLogger( "model.model_testdoubles.fake_confighandler").setLevel( logging.DEBUG) logging.getLogger("model.model_testdoubles.fake_server").setLevel( logging.DEBUG) logging.getLogger(__name__).setLevel(logging.DEBUG) pathscheme = argsns.pathscheme or 'test1' logger.info("Enabling testing environment...:") confighandler = FakeConfighandler(pathscheme=pathscheme) # set basedir for exp: confighandler.ConfigPaths['exp'] = os.path.join( 'tests', 'test_data', 'test_filestructure', 'labfluence_data_testsetup', '.labfluence.yml') confserver = FakeConfluenceServer(confighandler=confighandler) else: pathscheme = argsns.pathscheme or 'default1' confighandler = ExpConfigHandler(pathscheme=pathscheme) try: confserver = ConfluenceXmlRpcServer(autologin=True, confighandler=confighandler) except socket.error: print "This should not happen; autologin is shielded by try-clause. Perhaps network issues?" exit(1) confighandler.Singletons['server'] = confserver # Test if default func is defined after parsing: func = getattr(argsns, 'func', None) if func: logger.debug("Executing function %s with argsns %s", func, argsns) ret = func(argsns) else: logger.error("No func specified...?")