class DashboardTestCase(unittest.TestCase): def setUp(self): self._tmp_dir = tempfile.mkdtemp() self.project = init_project('dashboard-test-project', root=self._tmp_dir, make_dir=False) # Set up some fake jobs for a in range(3): for b in range(2): job = self.project.open_job({'a': a, 'b': b}) with job: job.document['sum'] = a + b self.config = {} self.modules = [] self.dashboard = Dashboard(config=self.config, project=self.project, modules=self.modules) self.dashboard.prepare() self.test_client = self.dashboard.app.test_client() self.addCleanup(shutil.rmtree, self._tmp_dir) def tearDown(self): pass def test_get_jobs(self): rv = self.test_client.get('/jobs', follow_redirects=True) response = str(rv.get_data()) assert 'dashboard-test-project' in response def test_job_count(self): rv = self.test_client.get('/jobs', follow_redirects=True) response = str(rv.get_data()) assert '{} jobs'.format(self.project.num_jobs()) in response def test_sp_search(self): dictquery = {'a': 0} true_num_jobs = len(list(self.project.find_jobs(dictquery))) query = urlquote(json.dumps(dictquery)) rv = self.test_client.get('/search?q={}'.format(query), follow_redirects=True) response = str(rv.get_data()) assert '{} jobs'.format(true_num_jobs) in response def test_doc_search(self): dictquery = {'sum': 1} true_num_jobs = len(list(self.project.find_jobs(doc_filter=dictquery))) query = urlquote('doc:' + json.dumps(dictquery)) rv = self.test_client.get('/search?q={}'.format(query), follow_redirects=True) response = str(rv.get_data()) assert '{} jobs'.format(true_num_jobs) in response
def setUp(self): self._tmp_dir = tempfile.mkdtemp() self.project = init_project('dashboard-test-project', root=self._tmp_dir, make_dir=False) # Set up some fake jobs for a in range(3): for b in range(2): job = self.project.open_job({'a': a, 'b': b}) with job: job.document['sum'] = a + b self.config = {} self.modules = [] self.dashboard = Dashboard(config=self.config, project=self.project, modules=self.modules) self.dashboard._prepare() self.test_client = self.dashboard.app.test_client() self.addCleanup(shutil.rmtree, self._tmp_dir)
class AllModulesTestCase(DashboardTestCase): def setUp(self): self._tmp_dir = tempfile.mkdtemp() self.project = init_project('dashboard-test-project', root=self._tmp_dir, make_dir=False) # Set up some fake jobs for a in range(3): for b in range(2): job = self.project.open_job({'a': a, 'b': b}) with job: job.document['sum'] = a + b self.config = {} modules = [] for m in signac_dashboard.modules.__all__: modules.append(getattr(signac_dashboard.modules, m)()) self.modules = modules self.dashboard = Dashboard(config=self.config, project=self.project, modules=self.modules) self.dashboard._prepare() self.test_client = self.dashboard.app.test_client() self.addCleanup(shutil.rmtree, self._tmp_dir)
def test_modules(self): modules = [] for m in signac_dashboard.modules.__all__: modules.append(getattr(signac_dashboard.modules, m).__call__()) json_modules_before = json.dumps(modules, cls=ModuleEncoder, sort_keys=True, indent=4) parsed_modules = Dashboard.decode_modules(json_modules_before) json_modules_after = json.dumps(parsed_modules, cls=ModuleEncoder, sort_keys=True, indent=4) assert json_modules_before == json_modules_after
class DashboardTestCase(unittest.TestCase): def setUp(self): self._tmp_dir = tempfile.mkdtemp() self.project = init_project('dashboard-test-project', root=self._tmp_dir, make_dir=False) # Set up some fake jobs for a in range(3): for b in range(2): job = self.project.open_job({'a': a, 'b': b}) with job: job.document['sum'] = a + b self.config = {} self.modules = [] self.dashboard = Dashboard(config=self.config, project=self.project, modules=self.modules) self.dashboard._prepare() self.test_client = self.dashboard.app.test_client() self.addCleanup(shutil.rmtree, self._tmp_dir) def test_get_jobs(self): rv = self.test_client.get('/jobs', follow_redirects=True) response = str(rv.get_data()) assert 'dashboard-test-project' in response def test_job_count(self): rv = self.test_client.get('/jobs', follow_redirects=True) response = str(rv.get_data()) assert '{} jobs'.format(self.project.num_jobs()) in response def test_sp_search(self): dictquery = {'a': 0} true_num_jobs = len(list(self.project.find_jobs(dictquery))) query = urlquote(json.dumps(dictquery)) rv = self.test_client.get('/search?q={}'.format(query), follow_redirects=True) response = str(rv.get_data()) assert '{} jobs'.format(true_num_jobs) in response def test_doc_search(self): dictquery = {'sum': 1} true_num_jobs = len(list(self.project.find_jobs(doc_filter=dictquery))) query = urlquote('doc:' + json.dumps(dictquery)) rv = self.test_client.get('/search?q={}'.format(query), follow_redirects=True) response = str(rv.get_data()) assert '{} jobs'.format(true_num_jobs) in response def test_allow_where_search(self): dictquery = {'sum': 1} true_num_jobs = len(list(self.project.find_jobs(doc_filter=dictquery))) query = urlquote('doc:sum.$where "lambda x: x == 1"') self.dashboard.config['ALLOW_WHERE'] = False rv = self.test_client.get('/search?q={}'.format(query), follow_redirects=True) response = str(rv.get_data()) assert 'ALLOW_WHERE must be enabled for this query.' in response self.dashboard.config['ALLOW_WHERE'] = True rv = self.test_client.get('/search?q={}'.format(query), follow_redirects=True) response = str(rv.get_data()) assert '{} jobs'.format(true_num_jobs) in response def test_update_cache(self): rv = self.test_client.get('/jobs', follow_redirects=True) response = str(rv.get_data()) assert '{} jobs'.format(self.project.num_jobs()) in response # Create a new job. Because the project has been cached, the response # will be wrong until the cache is cleared. self.project.open_job({'a': 'test-cache'}).init() rv = self.test_client.get('/jobs', follow_redirects=True) response = str(rv.get_data()) assert '{} jobs'.format(self.project.num_jobs()) not in response # Clear cache and try again. self.dashboard.update_cache() rv = self.test_client.get('/jobs', follow_redirects=True) response = str(rv.get_data()) assert '{} jobs'.format(self.project.num_jobs()) in response
#!/usr/bin/env python3 # Copyright (c) 2019 The Regents of the University of Michigan # All rights reserved. # This software is licensed under the BSD 3-Clause License. from signac_dashboard import Dashboard import signac_dashboard.modules import signac if __name__ == '__main__': project = signac.init_project('dashboard-test-project') if len(project) == 0: for a in range(10): for b in range(10): project.open_job({'a': a, 'b': b}).init() modules = [] if 'dashboard' not in project.document: # Initialize a new Dashboard using all modules with default settings for m in signac_dashboard.modules.__all__: modules.append(getattr(signac_dashboard.modules, m).__call__()) Dashboard(modules=modules).main()
#!/usr/bin/env python3 # Copyright (c) 2019 The Regents of the University of Michigan # All rights reserved. # This software is licensed under the BSD 3-Clause License. from signac_dashboard import Dashboard from signac_dashboard.modules import StatepointList # To use multiple workers, a single shared key must be used. By default, the # secret key is randomly generated at runtime by each worker. Using a provided # shared key allows sessions to be shared across workers. This key was # generated with os.urandom(16) config = { 'SECRET_KEY': b"\x99o\x90'/\rK\xf5\x10\xed\x8bC\xaa\x03\x9d\x99" } modules = [ StatepointList(), ] # The dashboard instance must be importable by the WSGI server. dashboard = Dashboard(config=config, modules=modules)
#!/usr/bin/env python3 # Copyright (c) 2019 The Regents of the University of Michigan # All rights reserved. # This software is licensed under the BSD 3-Clause License. from signac_dashboard import Dashboard from signac import init_project if __name__ == '__main__': project = init_project('dashboard-test-project') for a in range(10): for b in range(10): project.open_job({'a': a, 'b': b}).init() Dashboard().main()
#!/usr/bin/env python3 """Create a dashboard for viewing job status and outputs.""" from signac_dashboard import Dashboard from signac_dashboard.modules import DocumentList, FileList, ImageViewer, StatepointList if __name__ == "__main__": Dashboard( modules=[ImageViewer(), DocumentList(), StatepointList(), FileList()]).main()
#!/usr/bin/env python3 # Copyright (c) 2018 The Regents of the University of Michigan # All rights reserved. # This software is licensed under the BSD 3-Clause License. from signac_dashboard import Dashboard from signac import init_project if __name__ == '__main__': project = init_project('dashboard-test-project') config = {} modules = [] dashboard = Dashboard(config=config, project=project, modules=modules) dashboard.run(host='localhost', port=8888)