"""unittests for cw.web.formfields"""fromlogilab.common.testlibimportTestCase,unittest_mainfromcubicweb.devtoolsimportTestServerConfigurationfromcubicweb.web.formwidgetsimportPasswordInputfromcubicweb.web.formfieldsimport*fromcubicweb.entities.libimportCardfromcubicweb.entities.authobjsimportEUserfromcubes.file.entitiesimportFileconfig=TestServerConfiguration('data')config.bootstrap_cubes()schema=config.load_schema()Card.schema=schemaCard.__initialize__()EUser.schema=schemaEUser.__initialize__()File.schema=schemaFile.__initialize__()classGuessFieldTC(TestCase):deftest_card_fields(self):title_field=guess_field(Card,schema['title'])self.assertIsInstance(title_field,StringField)self.assertEquals(title_field.required,True)synopsis_field=guess_field(Card,schema['synopsis'])self.assertIsInstance(synopsis_field,TextField)self.assertEquals(synopsis_field.required,False)content_field=guess_field(Card,schema['content'])self.assertIsInstance(content_field,RichTextField)self.assertEquals(content_field.required,False)content_format_field=guess_field(Card,schema['content_format'])self.assertEquals(content_format_field,None)wikiid_field=guess_field(Card,schema['wikiid'])self.assertIsInstance(wikiid_field,StringField)self.assertEquals(wikiid_field.required,False)deftest_euser_fields(self):upassword_field=guess_field(EUser,schema['upassword'])self.assertIsInstance(upassword_field,StringField)self.assertIsInstance(upassword_field.widget,PasswordInput)self.assertEquals(upassword_field.required,True)last_login_time_field=guess_field(EUser,schema['last_login_time'])self.assertIsInstance(last_login_time_field,DateTimeField)self.assertEquals(last_login_time_field.required,False)in_group_field=guess_field(EUser,schema['in_group'])self.assertIsInstance(in_group_field,RelationField)self.assertEquals(in_group_field.required,True)self.assertEquals(in_group_field.role,'subject')owned_by_field=guess_field(EUser,schema['owned_by'],'object')self.assertIsInstance(owned_by_field,RelationField)self.assertEquals(owned_by_field.required,False)self.assertEquals(owned_by_field.role,'object')deftest_file_fields(self):data_format_field=guess_field(File,schema['data_format'])self.assertEquals(data_format_field,None)data_encoding_field=guess_field(File,schema['data_encoding'])self.assertEquals(data_encoding_field,None)data_field=guess_field(File,schema['data'])self.assertIsInstance(data_field,FileField)self.assertEquals(data_field.required,True)self.assertIsInstance(data_field.format_field,StringField)self.assertIsInstance(data_field.encoding_field,StringField)if__name__=='__main__':unittest_main()