def test_report_designs(self): """Test report design view and interaction""" cli = self.client # Test report design auto-save and loading resp = cli.post("/beeswax/report_gen", { 'columns-next_form_id': '1', 'columns-0-_exists': 'True', 'union.conds-next_form_id': '0', 'union.mgmt-next_form_id': '1', 'union.sub0.bool-bool': 'AND', 'union.sub0.conds-next_form_id': '1', 'union.sub0.conds-0-_exists': 'True', 'union.sub0.mgmt-next_form_id': '0', 'button-submit': 'Submit', 'saveform-name': 'reporter', 'saveform-save': 'True', }) # The report above is invalid. But it saves and submit at the same time. design = beeswax.models.SavedQuery.objects.filter(name='reporter')[0] resp2 = cli.get('/beeswax/report_gen/%s' % (design.id,)) assert_similar_pages(resp.content, resp2.content)
def test_report_designs(self): """Test report design view and interaction""" cli = self.client # Test report design auto-save and loading resp = cli.post( "/beeswax/report_gen", { 'columns-next_form_id': '1', 'columns-0-_exists': 'True', 'union.conds-next_form_id': '0', 'union.mgmt-next_form_id': '1', 'union.sub0.bool-bool': 'AND', 'union.sub0.conds-next_form_id': '1', 'union.sub0.conds-0-_exists': 'True', 'union.sub0.mgmt-next_form_id': '0', 'button-submit': 'Submit', 'saveform-name': 'reporter', 'saveform-save': 'True', }) # The report above is invalid. But it saves and submit at the same time. design = beeswax.models.SavedQuery.objects.filter(name='reporter')[0] resp2 = cli.get('/beeswax/report_gen/%s' % (design.id, )) assert_similar_pages(resp.content, resp2.content)
def test_designs(self): """Test design view and interaction""" cli = self.client # An auto hql design should be created, and it should ignore the given name and desc _make_query(self.client, 'SELECT bogus FROM test', name='mydesign', desc='hyatt') resp = cli.get('/beeswax/list_designs') n_designs = len(resp.context['page'].object_list) # Retrieve that design. It's the first one since it's most recent design = beeswax.models.SavedQuery.objects.all()[0] resp = cli.get('/beeswax/execute/%s' % (design.id,)) assert_true('SELECT bogus FROM test' in resp.content) # Make a valid auto hql design resp = _make_query(self.client, 'SELECT * FROM test') wait_for_query_to_finish(self.client, resp, max=60.0) resp = cli.get('/beeswax/list_designs') nplus_designs = len(resp.context['page'].object_list) assert_true(nplus_designs == n_designs, 'Auto design should not show up in list_designs') # Test explicit save query = 'MORE BOGUS JUNKS FROM test' exe_resp = _make_query(self.client, query, name='rubbish', submission_type='Save') assert_true("error_message" not in exe_resp.context) resp = cli.get('/beeswax/list_designs') assert_true('rubbish' in resp.content) nplusplus_designs = len(resp.context['page'].object_list) assert_true(nplusplus_designs > nplus_designs) # Retrieve that design design = beeswax.models.SavedQuery.objects.filter(name='rubbish')[0] resp = cli.get('/beeswax/execute/%s' % (design.id,)) assert_similar_pages(resp.content, exe_resp.content) # Clone the rubbish design len_before = len(beeswax.models.SavedQuery.objects.filter(name__contains='rubbish')) resp = cli.get('/beeswax/clone_design/%s' % (design.id,)) len_after = len(beeswax.models.SavedQuery.objects.filter(name__contains='rubbish')) assert_true(len_after == len_before + 1) # Delete a design resp = cli.get('/beeswax/delete_design/1') assert_true('Delete design?' in resp.content) resp = cli.post('/beeswax/delete_design/1') assert_equal(resp.status_code, 302) # Helper to test the view, filtering, etc def do_view(param): resp = cli.get('/beeswax/list_designs?' + param) assert_true(len(resp.context['page'].object_list) >= 0) # Make the query run return resp do_view('user=test') do_view('text=whatever') do_view('type=hql') do_view('type=report') do_view('sort=date') do_view('sort=-date') do_view('sort=name') do_view('sort=-name') do_view('sort=desc') do_view('sort=-desc') do_view('sort=type') do_view('sort=-type') do_view('sort=name&user=bogus') resp = do_view('sort=-type&user=test&type=hql&text=Rubbish') assert_true('rubbish' in resp.content) # Test personal saved queries permissions client = make_logged_in_client(username='******', is_superuser=False) _make_query(self.client, "select one", name='client query 1', submission_type='Save') _make_query(self.client, "select two", name='client query 2', submission_type='Save') finish = conf.SHARE_SAVED_QUERIES.set_for_testing(True) try: resp = self.client.get('/beeswax/list_designs') assert_true('client query 1' in resp.content) assert_true('client query 2' in resp.content) finally: finish() finish = conf.SHARE_SAVED_QUERIES.set_for_testing(False) try: resp = self.client.get('/beeswax/list_designs') assert_true('client query 1' in resp.content) assert_true('client query 2' in resp.content) finally: finish() client.logout() # Login as someone else client2 = make_logged_in_client(username='******', is_superuser=False) # Failing for now as the user does not have access to the Beeswax app. # finish = conf.SHARE_SAVED_QUERIES.set_for_testing(True) # try: # resp = client2.get('/beeswax/list_designs') # assert_true('client query 1' in resp.content) # assert_true('client query 2' in resp.content) # finally: # finish() finish = conf.SHARE_SAVED_QUERIES.set_for_testing(False) try: resp = client2.get('/beeswax/list_designs') assert_true('client query 1' not in resp.content) assert_true('client query 2' not in resp.content) finally: finish() client2.logout() # Login as super user client3 = make_logged_in_client('admin', is_superuser=True) finish = conf.SHARE_SAVED_QUERIES.set_for_testing(True) try: resp = client3.get('/beeswax/list_designs') assert_true('client query 1' in resp.content) assert_true('client query 2' in resp.content) finally: finish() finish = conf.SHARE_SAVED_QUERIES.set_for_testing(False) try: resp = client3.get('/beeswax/list_designs') assert_true('client query 1' in resp.content) assert_true('client query 2' in resp.content) finally: finish() client3.logout()
def test_designs(self): """Test design view and interaction""" cli = self.client # An auto hql design should be created, and it should ignore the given name and desc _make_query(self.client, 'SELECT bogus FROM test', name='mydesign', desc='hyatt') resp = cli.get('/beeswax/list_designs') n_designs = len(resp.context['page'].object_list) # Retrieve that design. It's the first one since it's most recent design = beeswax.models.SavedQuery.objects.all()[0] resp = cli.get('/beeswax/execute/%s' % (design.id,)) assert_true('SELECT bogus FROM test' in resp.content) # Make a valid auto hql design resp = _make_query(self.client, 'SELECT * FROM test') wait_for_query_to_finish(self.client, resp, max=60.0) resp = cli.get('/beeswax/list_designs') nplus_designs = len(resp.context['page'].object_list) assert_true(nplus_designs == n_designs, 'Auto design should not show up in list_designs') # Test explicit save query = 'MORE BOGUS JUNKS FROM test' exe_resp = _make_query(self.client, query, name='rubbish', submission_type='Save') assert_true(exe_resp.context.get("error_message") is None) resp = cli.get('/beeswax/list_designs') assert_true('rubbish' in resp.content) nplusplus_designs = len(resp.context['page'].object_list) assert_true(nplusplus_designs > nplus_designs) # Retrieve that design design = beeswax.models.SavedQuery.objects.filter(name='rubbish')[0] resp = cli.get('/beeswax/execute/%s' % (design.id,)) assert_similar_pages(resp.content, exe_resp.content) # Clone the rubbish design len_before = len(beeswax.models.SavedQuery.objects.filter(name__contains='rubbish')) resp = cli.get('/beeswax/clone_design/%s' % (design.id,)) len_after = len(beeswax.models.SavedQuery.objects.filter(name__contains='rubbish')) assert_true(len_after == len_before + 1) # Delete a design resp = cli.get('/beeswax/delete_design/1') assert_true('sure?' in resp.content) resp = cli.post('/beeswax/delete_design/1') assert_true(resp.template == 'list_designs.mako') # Helper to test the view, filtering, etc def do_view(param): resp = cli.get('/beeswax/list_designs?' + param) assert_true(len(resp.context['page'].object_list) >= 0) # Make the query run return resp do_view('user=test') do_view('text=whatever') do_view('type=hql') do_view('type=report') do_view('sort=date') do_view('sort=-date') do_view('sort=name') do_view('sort=-name') do_view('sort=desc') do_view('sort=-desc') do_view('sort=type') do_view('sort=-type') do_view('sort=name&user=bogus') resp = do_view('sort=-type&user=test&type=hql&text=Rubbish') assert_true('rubbish' in resp.content)
def test_designs(self): """Test design view and interaction""" cli = self.client # An auto hql design should be created, and it should ignore the given name and desc _make_query(self.client, 'SELECT bogus FROM test', name='mydesign', desc='hyatt') resp = cli.get('/beeswax/list_designs') n_designs = len(resp.context['page'].object_list) # Retrieve that design. It's the first one since it's most recent design = beeswax.models.SavedQuery.objects.all()[0] resp = cli.get('/beeswax/execute/%s' % (design.id, )) assert_true('SELECT bogus FROM test' in resp.content) # Make a valid auto hql design resp = _make_query(self.client, 'SELECT * FROM test') wait_for_query_to_finish(self.client, resp, max=60.0) resp = cli.get('/beeswax/list_designs') nplus_designs = len(resp.context['page'].object_list) assert_true(nplus_designs == n_designs, 'Auto design should not show up in list_designs') # Test explicit save query = 'MORE BOGUS JUNKS FROM test' exe_resp = _make_query(self.client, query, name='rubbish', submission_type='Save') assert_true(exe_resp.context.get("error_message") is None) resp = cli.get('/beeswax/list_designs') assert_true('rubbish' in resp.content) nplusplus_designs = len(resp.context['page'].object_list) assert_true(nplusplus_designs > nplus_designs) # Retrieve that design design = beeswax.models.SavedQuery.objects.filter(name='rubbish')[0] resp = cli.get('/beeswax/execute/%s' % (design.id, )) assert_similar_pages(resp.content, exe_resp.content) # Clone the rubbish design len_before = len( beeswax.models.SavedQuery.objects.filter(name__contains='rubbish')) resp = cli.get('/beeswax/clone_design/%s' % (design.id, )) len_after = len( beeswax.models.SavedQuery.objects.filter(name__contains='rubbish')) assert_true(len_after == len_before + 1) # Delete a design resp = cli.get('/beeswax/delete_design/1') assert_true('sure?' in resp.content) resp = cli.post('/beeswax/delete_design/1') assert_true(resp.template == 'list_designs.mako') # Helper to test the view, filtering, etc def do_view(param): resp = cli.get('/beeswax/list_designs?' + param) assert_true(len(resp.context['page'].object_list) >= 0) # Make the query run return resp do_view('user=test') do_view('text=whatever') do_view('type=hql') do_view('type=report') do_view('sort=date') do_view('sort=-date') do_view('sort=name') do_view('sort=-name') do_view('sort=desc') do_view('sort=-desc') do_view('sort=type') do_view('sort=-type') do_view('sort=name&user=bogus') resp = do_view('sort=-type&user=test&type=hql&text=Rubbish') assert_true('rubbish' in resp.content)
def test_designs(self): """Test design view and interaction""" cli = self.client # An auto hql design should be created, and it should ignore the given name and desc _make_query(self.client, 'SELECT bogus FROM test', name='mydesign', desc='hyatt') resp = cli.get('/beeswax/list_designs') n_designs = len(resp.context['page'].object_list) # Retrieve that design. It's the first one since it's most recent design = beeswax.models.SavedQuery.objects.all()[0] resp = cli.get('/beeswax/execute/%s' % (design.id,)) assert_true('SELECT bogus FROM test' in resp.content) # Make a valid auto hql design resp = _make_query(self.client, 'SELECT * FROM test') wait_for_query_to_finish(self.client, resp, max=60.0) resp = cli.get('/beeswax/list_designs') nplus_designs = len(resp.context['page'].object_list) assert_true(nplus_designs == n_designs, 'Auto design should not show up in list_designs') # Test explicit save query = 'MORE BOGUS JUNKS FROM test' exe_resp = _make_query(self.client, query, name='rubbish', submission_type='Save') assert_true("error_message" not in exe_resp.context) resp = cli.get('/beeswax/list_designs') assert_true('rubbish' in resp.content) nplusplus_designs = len(resp.context['page'].object_list) assert_true(nplusplus_designs > nplus_designs) # Retrieve that design design = beeswax.models.SavedQuery.objects.filter(name='rubbish')[0] resp = cli.get('/beeswax/execute/%s' % (design.id,)) assert_similar_pages(resp.content, exe_resp.content) # Clone the rubbish design len_before = len(beeswax.models.SavedQuery.objects.filter(name__contains='rubbish')) resp = cli.get('/beeswax/clone_design/%s' % (design.id,)) len_after = len(beeswax.models.SavedQuery.objects.filter(name__contains='rubbish')) assert_true(len_after == len_before + 1) # Delete a design resp = cli.get('/beeswax/delete_design/1') assert_true('Delete design?' in resp.content) resp = cli.post('/beeswax/delete_design/1') assert_equal(resp.status_code, 302) # Helper to test the view, filtering, etc def do_view(param): resp = cli.get('/beeswax/list_designs?' + param) assert_true(len(resp.context['page'].object_list) >= 0) # Make the query run return resp do_view('user=test') do_view('text=whatever') do_view('type=hql') do_view('sort=date') do_view('sort=-date') do_view('sort=name') do_view('sort=-name') do_view('sort=desc') do_view('sort=-desc') do_view('sort=type') do_view('sort=-type') do_view('sort=name&user=bogus') resp = do_view('sort=-type&user=test&type=hql&text=Rubbish') assert_true('rubbish' in resp.content) # Test personal saved queries permissions client_me = make_logged_in_client(username='******', is_superuser=False, groupname='test') grant_access("its_me", "test", "beeswax") _make_query(client_me, "select one", name='client query 1', submission_type='Save') _make_query(client_me, "select two", name='client query 2', submission_type='Save') finish = conf.SHARE_SAVED_QUERIES.set_for_testing(True) try: resp = client_me.get('/beeswax/list_designs') assert_true('client query 1' in resp.content, resp.content) assert_true('client query 2' in resp.content, resp.content) finally: finish() finish = conf.SHARE_SAVED_QUERIES.set_for_testing(False) try: resp = client_me.get('/beeswax/list_designs') assert_true('client query 1' in resp.content) assert_true('client query 2' in resp.content) finally: finish() client_me.logout() # Login as someone else client_not_me = make_logged_in_client(username='******', is_superuser=False, groupname='test') grant_access("not_me", "test", "beeswax") finish = conf.SHARE_SAVED_QUERIES.set_for_testing(True) try: resp = client_not_me.get('/beeswax/list_designs') assert_true('client query 1' in resp.content) assert_true('client query 2' in resp.content) finally: finish() finish = conf.SHARE_SAVED_QUERIES.set_for_testing(False) try: resp = client_not_me.get('/beeswax/list_designs') assert_true('client query 1' not in resp.content) assert_true('client query 2' not in resp.content) finally: finish() client_not_me.logout() # Login as super user client_admin = make_logged_in_client('admin', is_superuser=True) finish = conf.SHARE_SAVED_QUERIES.set_for_testing(True) try: resp = client_admin.get('/beeswax/list_designs') assert_true('client query 1' in resp.content) assert_true('client query 2' in resp.content) finally: finish() finish = conf.SHARE_SAVED_QUERIES.set_for_testing(False) try: resp = client_admin.get('/beeswax/list_designs') assert_true('client query 1' in resp.content) assert_true('client query 2' in resp.content) finally: finish() client_admin.logout()