Source code for timApp.tests.server.test_cbcountfield

"""Server tests for cbcountfield."""
from timApp.auth.accesstype import AccessType
from timApp.tests.browser.browsertest import BrowserTest
from timApp.timdb.sqa import db


[docs]class CbCountFieldTest(BrowserTest):
[docs] def expect_count(self, r, count): self.assertEqual(count, r["web"]["count"])
[docs] def test_cbcountfield(self): self.login_test1() d = self.create_doc( initial_par=""" #- {#t plugin=cbcountfield} """ ) self.test_user_2.grant_access(d, AccessType.view) self.test_user_3.grant_access(d, AccessType.view) db.session.commit() db.session.refresh(d) r = self.post_answer( "cbcountfield", f"{d.id}.t", user_input={"c": "1"}, ) self.expect_count(r, 1) r = self.post_answer( "cbcountfield", f"{d.id}.t", user_input={"c": "1"}, ) self.expect_count(r, 1) r = self.post_answer( "cbcountfield", f"{d.id}.t", user_input={"c": "0"}, ) self.expect_count(r, 0) r = self.post_answer( "cbcountfield", f"{d.id}.t", user_input={"c": "1"}, ) self.expect_count(r, 1) self.login_test2() r = self.post_answer( "cbcountfield", f"{d.id}.t", user_input={"c": "1"}, ) self.expect_count(r, 2) r = self.post_answer( "cbcountfield", f"{d.id}.t", user_input={"c": "1"}, ) self.expect_count(r, 2) r = self.post_answer( "cbcountfield", f"{d.id}.t", user_input={"c": "0"}, ) self.expect_count(r, 1) self.login_test3() r = self.get(d.url, as_tree=True) par_id = d.document.get_paragraphs()[0].get_id() self.assert_plugin_json( r.cssselect(".parContent cbcountfield-runner")[0], self.create_plugin_json( d, "t", state=None, info=None, par_id=par_id, toplevel={"count": 1}, markup={"autoUpdateTables": True}, ), )
[docs] def test_cbcountfield_grouplogin(self): self.login_test1() self.login_test2(add=True) d = self.create_doc( initial_par=""" #- {#t plugin=cbcountfield}""" ) r = self.post_answer( "cbcountfield", f"{d.id}.t", user_input={"c": "1"}, ) self.expect_count(r, 1)