def create_identity(): if request.method == 'GET': return CreateIdentity().render() elif request.method == 'POST': dob = "{day}-{month}-{year}".format( day=request.form.get('dob_day', None), month=request.form.get('dob_month', None), year=request.form.get('dob_year', None) ) new_identity = Identity( first_name=request.form.get('first_name', None), middle_names=request.form.get('middle_names', None), last_name=request.form.get('last_name', None), dob=dob, address_line1=request.form.get('address_line1', None), address_line2=request.form.get('address_line2', None), address_line3=request.form.get('address_line3', None), address_line4=request.form.get('address_line4', None), address_line5=request.form.get('address_line5', None), postcode=request.form.get('postcode', None), gender=request.form.get('gender', None) ) new_identity.save() return redirect(url_for('identity.list_identities'))
def test_store_model(self): joe = Identity( first_name='Jane', middle_names='Jenny', last_name='Jones', dob='1-12-1988', address_line1='123 Fake Street', address_line2='Fakerton', address_line3='Fakesbury', address_line4='South Fakeshire', address_line5='Fakeland', postcode='AB12 3CD', gender='MALE' ) self.assertEqual(joe.id, None) joe.save() self.assertNotEqual(joe.id, None) self.assertEquals(joe.first_name, 'Jane') self.assertEquals(joe.middle_names, 'Jenny') self.assertEquals(joe.last_name, 'Jones') self.assertEquals(joe.dob, '1-12-1988') self.assertEquals(joe.address_line1, '123 Fake Street') self.assertEquals(joe.address_line2, 'Fakerton') self.assertEquals(joe.address_line3, 'Fakesbury') self.assertEquals(joe.address_line4, 'South Fakeshire') self.assertEquals(joe.address_line5, 'Fakeland') self.assertEquals(joe.postcode, 'AB12 3CD') self.assertEquals(joe.gender, 'MALE') saved = Identity.get(joe.id) self.assertEqual(joe, saved)
def test_get_all(self): self.assertEqual([], Identity.all()) joe = Identity() joe.save() self.assertEqual([joe], Identity.all()) jane = Identity() jane.save() self.assertListEqual([joe, jane], Identity.all())
def test_empty_options(self): joe = Identity() joe.save() recovered = Identity.get(joe.id) self.assertEquals(recovered.first_name, None) self.assertEquals(recovered.middle_names, None) self.assertEquals(recovered.last_name, None) self.assertEquals(recovered.dob, None) self.assertEquals(recovered.address_line1, None) self.assertEquals(recovered.address_line2, None) self.assertEquals(recovered.address_line3, None) self.assertEquals(recovered.address_line4, None) self.assertEquals(recovered.address_line5, None) self.assertEquals(recovered.postcode, None) self.assertEquals(recovered.gender, None) self.assertNotEquals(recovered.token, None)
def test_get_list_identities(self, client): res = client.get("/identity") html = document_fromstring(res.get_data()) header_exists = html.xpath("boolean(//tr/th)") self.assertTrue(header_exists) rows = html.xpath("boolean(//tr/td)") self.assertFalse(rows) joe = Identity() joe.save() john = Identity() john.save() jim = Identity() jim.save() res = client.get("/identity") html = document_fromstring(res.get_data()) rows = html.xpath("boolean(//tr/td)") self.assertTrue(rows) ids = html.xpath("//tr/td[1]//text()") self.assertIn(str(joe.id), ids)