def test_collection_edit_good(self): from webtest import Text self.test_collection_create_shared() self.sub_logout_user() self.sub_make_user('baz') res = self.sub_login_user('foo') # Edit the collection, rename it, and add in Mr. Baz as a viewer res = res.click('FooBar') res = res.click('Edit Collection') user_field = Text(res.form, tag='input', name='users-2.user', pos=0) role_field = Text(res.form, tag='input', name='users-2.role', pos=0) res.form.fields.setdefault(user_field.name, []).append(user_field) res.form.fields.setdefault(role_field.name, []).append(role_field) res.form.field_order.append((user_field.name, user_field)) res.form.field_order.append((role_field.name, role_field)) res.form['name'] = 'FooBarBaz' res.form[user_field.name] = '*****@*****.**' res.form[role_field.name] = 'viewer' res = res.form.submit().follow() collection = DBSession.query(Collection).filter(Collection.name=='FooBarBaz').first() assert collection is not None foo = self.sub_get_user('foo') bar = self.sub_get_user('bar') baz = self.sub_get_user('baz') assert foo in collection.users assert bar in collection.users assert baz in collection.users assert collection.users[foo] == Role.by_id('owner') assert collection.users[bar] == Role.by_id('editor') assert collection.users[baz] == Role.by_id('viewer') assert 'FooBarBaz Collection' in res return res
def test_collection_create_shared(self): from webtest import Text self.sub_make_user('foo') self.sub_make_user('bar') self.sub_login_user('foo') res = self.test.get('/collections/new') user_field = Text(res.form, tag='input', name='users-0.user', pos=0) role_field = Text(res.form, tag='input', name='users-0.role', pos=0) res.form.fields.setdefault(user_field.name, []).append(user_field) res.form.fields.setdefault(role_field.name, []).append(role_field) res.form.field_order.append((user_field.name, user_field)) res.form.field_order.append((role_field.name, role_field)) res.form['name'] = 'FooBar' res.form[user_field.name] = '*****@*****.**' res.form[role_field.name] = 'editor' res = res.form.submit().follow() collection = DBSession.query(Collection).filter(Collection.name=='FooBar').first() assert collection is not None foo = self.sub_get_user('foo') bar = self.sub_get_user('bar') assert foo in collection.users assert bar in collection.users assert collection.users[foo] == Role.by_id('owner') assert collection.users[bar] == Role.by_id('editor') assert 'FooBar Collection' in res return res
def test_adding_ouder(self): ouder_burgerservicenummer = 987654321 response = self.app.get(self.url) form = response.forms["persoon_form"] form["ouder_set-TOTAL_FORMS"] = 1 form["ouder_set-INITIAL_FORMS"] = 0 form["ouder_set-MIN_NUM_FORMS"] = 0 form["ouder_set-MAX_NUM_FORMS"] = 1000 form[ "burgerservicenummer_persoon"] = self.persoon.burgerservicenummer_persoon form["voornamen_persoon"] = self.persoon.voornamen_persoon form["geslachtsnaam_persoon"] = self.persoon.geslachtsnaam_persoon form["geboortedatum_persoon"] = self.persoon.geboortedatum_persoon form["geslachtsaanduiding"] = self.persoon.geslachtsaanduiding text = Text( form, "input", "ouder_set-0-persoon", 1, value=self.persoon.id, id="ouder_set-0-persoon", ) form.field_order.append(("ouder_set-0-persoon", text)) form.fields["ouder_set-0-persoon"] = text text = Text( form, "input", "ouder_set-0-burgerservicenummer_ouder", 1, value=ouder_burgerservicenummer, id="ouder_set-0-burgerservicenummer_ouder", ) form.field_order.append( ("ouder_set-0-burgerservicenummer_ouder", text)) form.fields["ouder_set-0-burgerservicenummer_ouder"] = text response = form.submit() self.assertTrue(response.status_code, 200) self.assertTrue( Ouder.objects.filter( burgerservicenummer_ouder=ouder_burgerservicenummer).exists()) self.assertTrue( Persoon.objects.filter( burgerservicenummer_persoon=ouder_burgerservicenummer).exists( )) self.assertTrue( Kind.objects.filter(burgerservicenummer_kind=self.persoon. burgerservicenummer_persoon).exists())
def test_tab_wan(self): page = self.app.get("/config/wan/") assert_equal(page.status_int, 200) form = page.forms['main-form'] form.set("proto", "static", 1) form.set("custom_mac", True, 1) # add update flag (normally done by JS) - this is quite awkward in WebTest field = Text(form, "input", None, None, "1") form.fields['update'] = field form.field_order.append(("update", field)) submit = form.submit(headers=XHR_HEADERS) assert_true(submit.body.lstrip().startswith("<form")) # try invalid submission of the form form = submit.forms['main-form'] invalid = form.submit() assert_in(RESPONSE_TEXTS['form_invalid'], invalid) # fill the form returned form = invalid.forms['main-form'] addr, mask, gw, macaddr\ = form['ipaddr'], form['netmask'], form['gateway'], form['macaddr'] \ = "10.0.0.1", "255.0.0.0", "10.0.0.10", "01:23:45:67:89:af" submit = form.submit().follow() assert_in(RESPONSE_TEXTS['form_saved'], submit.body) assert_equal(self.uci_get("network.wan.ipaddr"), addr) assert_equal(self.uci_get("network.wan.netmask"), mask) assert_equal(self.uci_get("network.wan.gateway"), gw) assert_equal(self.uci_get("network.wan.macaddr"), macaddr)
def add_dynamic_field(form: Form, name, value): field = Text(form, "input", None, 999, value) form.fields[name] = field form.field_order.append((name, field))