def test_list(self): from c2cgeoform.views import list from models_test import Person DBSession.add(Person(name="Peter", first_name="Smith")) DBSession.add(Person(name="John", first_name="Wayne")) request = testing.DummyRequest() request.matchdict['schema'] = 'tests_persons' response = list(request) self.assertTrue('entities' in response) entities = response['entities'] self.assertEquals(2, len(entities))
def test_list(self): from c2cgeoform.views import list from models_test import Person DBSession.add(Person(name="Peter", first_name="Smith")) DBSession.add(Person(name="John", first_name="Wayne")) request = self._get_request() request.matchdict['schema'] = 'tests_persons' response = list(request) self.assertTrue('entities' in response) entities = response['entities'] self.assertEquals(2, len(entities)) schema = response['schema'] self.assertEquals(['id', 'name'], schema.list_fields)
def test_view_user(self): from c2cgeoform.views import view_user from models_test import Person person = Person(name="Peter", first_name="Smith", hash="123-456") DBSession.add(person) DBSession.flush() request = self._get_request() request.matchdict['schema'] = 'tests_persons' request.matchdict['hash'] = "123-456" response = view_user(request) self.assertTrue('schema' in response) self.assertTrue('form' in response) form_html = response['form'] self.assertTrue('Peter' in form_html) self.assertTrue('Smith' in form_html)
def test_view_user(self): from c2cgeoform.views import view_user from models_test import Person person = Person(name="Peter", first_name="Smith", hash="123-456") DBSession.add(person) DBSession.flush() request = self._get_request() request.matchdict['schema'] = 'tests_persons' request.matchdict['hash'] = "123-456" response = view_user(request) self.assertTrue('schema' in response) self.assertTrue('form' in response) form_html = response['form'] self.assertTrue('Peter' in form_html) self.assertTrue('Smith' in form_html)
def test_edit_submit_invalid(self): from c2cgeoform.views import edit from models_test import Person person = Person(name="Peter", first_name="Smith") DBSession.add(person) DBSession.flush() request = testing.DummyRequest() request.matchdict['schema'] = 'tests_persons' request.matchdict['id'] = str(person.id) request.POST['id'] = str(person.id) request.POST['submit'] = 'submit' response = edit(request) self.assertTrue('schema' in response) self.assertTrue('form' in response) form_html = response['form'] self.assertTrue('class="errorMsgLbl"' in form_html)
def test_edit_submit_invalid(self): from c2cgeoform.views import edit from models_test import Person person = Person(name="Peter", first_name="Smith") DBSession.add(person) DBSession.flush() request = self._get_request() request.matchdict['schema'] = 'tests_persons' request.matchdict['id'] = str(person.id) request.POST['id'] = str(person.id) request.POST['submit'] = 'submit' response = edit(request) self.assertTrue('schema' in response) self.assertTrue('form' in response) form_html = response['form'] self.assertTrue('class="errorMsgLbl"' in form_html)
def test_view_admin(self): from c2cgeoform.views import view_admin from models_test import Person person = Person(name="Peter", first_name="Smith") DBSession.add(person) DBSession.flush() request = self._get_request() request.matchdict['schema'] = 'tests_persons' request.matchdict['id'] = str(person.id) response = view_admin(request) self.assertTrue('schema' in response) self.assertTrue('form' in response) form_html = response['form'] self.assertTrue('name="id"' in form_html) self.assertTrue('value="' + str(person.id) + '"' in form_html) self.assertTrue('Peter' in form_html) self.assertTrue('Smith' in form_html)
def test_view(self): from c2cgeoform.views import view from models_test import Person person = Person(name="Peter", first_name="Smith") DBSession.add(person) DBSession.flush() request = testing.DummyRequest() request.matchdict['schema'] = 'tests_persons' request.matchdict['id'] = str(person.id) response = view(request) self.assertTrue('schema' in response) self.assertTrue('form' in response) form_html = response['form'] self.assertTrue('name="id"' in form_html) self.assertTrue('value="' + str(person.id) + '"' in form_html) self.assertTrue('Peter' in form_html) self.assertTrue('Smith' in form_html)
def test_edit_show(self): from c2cgeoform.views import edit from models_test import Person person = Person(name="Peter", first_name="Smith") DBSession.add(person) DBSession.flush() request = self._get_request() request.matchdict['schema'] = 'tests_persons' request.matchdict['id'] = str(person.id) response = edit(request) self.assertTrue('schema' in response) self.assertTrue('form' in response) form_html = response['form'] self.assertTrue('name="id"' in form_html) self.assertTrue('value="' + str(person.id) + '"' in form_html) self.assertTrue('value="Peter"' in form_html) self.assertTrue('value="Smith"' in form_html) self.assertTrue('name="submit"' in form_html)
def test_edit_submit_successful(self): from c2cgeoform.views import edit from models_test import Person, Phone, TagsForPerson person = Person(name="Peter", first_name="Smith") phone = Phone(number="123456789") person.phones.append(phone) tag_for_person = TagsForPerson(tag_id=0) person.tags.append(tag_for_person) DBSession.add(person) DBSession.flush() old_tag_for_person_id = tag_for_person.id request = testing.DummyRequest(post=MultiDict()) request.matchdict['schema'] = 'tests_persons' request.matchdict['id'] = str(person.id) request.POST.add('id', str(person.id)) request.POST.add('submit', 'submit') request.POST.add('name', 'Peter') request.POST.add('first_name', 'Smith') request.POST.add('age', '43') request.POST.add('__start__', 'phones:sequence') request.POST.add('__start__', 'phones:mapping') request.POST.add('id', str(phone.id)) request.POST.add('number', '23456789') request.POST.add('person_id', str(person.id)) request.POST.add('__end__', 'phones:mapping') request.POST.add('__start__', 'phones:mapping') request.POST.add('number', '123456') request.POST.add('__end__', 'phones:mapping') request.POST.add('__end__', 'phones:sequence') request.POST.add('__start__', 'tags:sequence') request.POST.add('tags', u'0') request.POST.add('tags', u'1') request.POST.add('__end__', 'tags:sequence') response = edit(request) person = DBSession.query(Person).get(person.id) self.assertEquals('Peter', person.name) self.assertEquals('Smith', person.first_name) self.assertEquals(43, person.age) self.assertEquals(2, len(person.phones)) updated_phone = person.phones[0] self.assertEquals('23456789', updated_phone.number) self.assertEquals(phone.id, updated_phone.id) new_phone = person.phones[1] self.assertEquals('123456', new_phone.number) self.assertIsNotNone(new_phone.id) self.assertEquals(2, len(person.tags)) tag_for_person1 = person.tags[0] self.assertEquals(0, tag_for_person1.tag_id) self.assertEquals(person.id, tag_for_person1.person_id) self.assertIsNotNone(tag_for_person1.id) # a new row is created, also for the old entry self.assertNotEquals(old_tag_for_person_id, tag_for_person1.id) tag_for_person2 = person.tags[1] self.assertEquals(1, tag_for_person2.tag_id) self.assertEquals(person.id, tag_for_person2.person_id) self.assertIsNotNone(tag_for_person2.id) tags_for_persons = DBSession.query(TagsForPerson).all() # check that the old entry was deleted, so that there are only 2 self.assertEquals(2, len(tags_for_persons)) self.assertTrue('schema' in response) self.assertTrue('form' in response) form_html = response['form'] self.assertTrue('name="id"' in form_html) self.assertTrue('value="' + str(person.id) + '"' in form_html) self.assertTrue( 'name="id" value="' + str(person.id) + '"' in form_html) self.assertTrue('name="id" value="' + str(phone.id) + '"' in form_html) self.assertTrue( 'name="id" value="' + str(new_phone.id) + '"' in form_html) self.assertTrue( 'name="person_id" value="' + str(person.id) + '"' in form_html) self.assertTrue('name="submit"' in form_html) self.assertTrue('Tag A' in form_html) self.assertTrue('Tag B' in form_html)
def setup_test_data(settings): from c2cgeoform.models import DBSession import transaction if DBSession.query(District).get(0) is None: DBSession.add(District(id=0, name="Pully")) DBSession.add(District(id=1, name="Paudex")) DBSession.add(District(id=2, name="Belmont-sur-Lausanne")) DBSession.add(District(id=3, name="Trois-Chasseurs")) DBSession.add(District(id=4, name="La Claie-aux-Moines")) DBSession.add(District(id=5, name="Savigny")) DBSession.add(District(id=6, name="Mollie-Margot")) if DBSession.query(Situation).get(0) is None: DBSession.add(Situation(id=0, name="Road", name_fr="Route")) DBSession.add(Situation(id=1, name="Sidewalk", name_fr="Trottoir")) DBSession.add(Situation(id=2, name="Berm", name_fr="Berme")) DBSession.add(Situation( id=3, name="Vegetated berm", name_fr="Berme végétalisée")) DBSession.add(Situation(id=4, name="Green zone", name_fr="Zone verte")) DBSession.add(Situation(id=5, name="Cobblestone", name_fr="Pavés")) if DBSession.query(BusStop).count() == 0: _add_bus_stops(DBSession, settings['bus_stops_file']) if DBSession.query(Address).get(0) is None: DBSession.add(Address(id=0, label="Bern")) DBSession.add(Address(id=1, label="Lausanne")) DBSession.add(Address(id=2, label="Genève")) DBSession.add(Address(id=3, label="Zurich")) DBSession.add(Address(id=4, label="Lugano")) transaction.commit()
def setUp(self): # noqa curdir = os.path.dirname(os.path.abspath(__file__)) configfile = os.path.realpath(os.path.join(curdir, '../../tests.ini')) settings = get_appsettings(configfile) apply_local_settings(settings) engine = engine_from_config(settings, 'sqlalchemy.') DBSession.configure(bind=engine) from .models_test import Person, EmploymentStatus, Tag # noqa Base.metadata.create_all(engine) self.cleanup() # fill some test data into the `EmploymentStatus` and `Tags` table DBSession.add(EmploymentStatus(id=0, name='Worker')) DBSession.add(EmploymentStatus(id=1, name='Employee')) DBSession.add( EmploymentStatus(id=2, name='Self-employed and contractor')) DBSession.add(EmploymentStatus(id=3, name='Director')) DBSession.add(EmploymentStatus(id=4, name='Office holder')) DBSession.add(Tag(id=0, name='Tag A')) DBSession.add(Tag(id=1, name='Tag B')) DBSession.add(Tag(id=2, name='Tag C')) DBSession.add(Tag(id=3, name='Tag D')) DBSession.add(Tag(id=4, name='Tag E')) self.request = testing.DummyRequest(post=MultiDict(), dbsession=DBSession) testing.setUp(request=self.request) config = testing.setUp() config.add_route('form', '/{schema}/form/') config.add_route('view_user', '/{schema}/form/{hash}') config.add_route('confirm', '/{schema}/form/confirm') init_deform('c2cgeoform')
def _add_test_persons(self): self.person1 = Person(name="Smith", first_name="Peter") DBSession.add(self.person1) DBSession.add(Person(name="Wayne", first_name="John")) DBSession.add(Person(name="Elda", first_name="Hasbrouck")) DBSession.add(Person(name="Lashaun", first_name="Brasel")) DBSession.add(Person(name="Lashawna", first_name="Ashford")) DBSession.add(Person(name="Lesha", first_name="Snellgrove")) DBSession.add(Person(name="Sulema", first_name="Page")) DBSession.add(Person(name="Derek", first_name="Boroughs")) DBSession.add(Person(name="Odis", first_name="Bateman")) DBSession.add(Person(name="Venetta", first_name="Briganti")) DBSession.add(Person(name="Monte", first_name="Quill")) DBSession.add(Person(name="Daniel", first_name="Ruth")) DBSession.add(Person(name="Eloise", first_name="Hellickson")) DBSession.add(Person(name="Hee", first_name="Deloney")) DBSession.add(Person(name="Sharee", first_name="Warf")) DBSession.add(Person(name="Delpha", first_name="Philip")) DBSession.add(Person(name="Claudio", first_name="Campfield")) DBSession.add(Person(name="Janessa", first_name="Beatty")) DBSession.add(Person(name="Hollis", first_name="Richmond")) DBSession.add(Person(name="Karoline", first_name="Carew")) DBSession.add(Person(name="Bess", first_name="Papp")) DBSession.add(Person(name="Vada", first_name="Infantino")) DBSession.flush()
def setup_test_data(settings): from c2cgeoform.models import DBSession import transaction if DBSession.query(District).get(0) is None: DBSession.add(District(id=0, name="Pully")) DBSession.add(District(id=1, name="Paudex")) DBSession.add(District(id=2, name="Belmont-sur-Lausanne")) DBSession.add(District(id=3, name="Trois-Chasseurs")) DBSession.add(District(id=4, name="La Claie-aux-Moines")) DBSession.add(District(id=5, name="Savigny")) DBSession.add(District(id=6, name="Mollie-Margot")) if DBSession.query(Situation).get(0) is None: DBSession.add(Situation(id=0, name="Road", name_fr="Route")) DBSession.add(Situation(id=1, name="Sidewalk", name_fr="Trottoir")) DBSession.add(Situation(id=2, name="Berm", name_fr="Berme")) DBSession.add( Situation(id=3, name="Vegetated berm", name_fr="Berme végétalisée")) DBSession.add(Situation(id=4, name="Green zone", name_fr="Zone verte")) DBSession.add(Situation(id=5, name="Cobblestone", name_fr="Pavés")) if DBSession.query(BusStop).count() == 0: _add_bus_stops(DBSession, settings['bus_stops_file']) if DBSession.query(Address).get(0) is None: DBSession.add(Address(id=0, label="Bern")) DBSession.add(Address(id=1, label="Lausanne")) DBSession.add(Address(id=2, label="Genève")) DBSession.add(Address(id=3, label="Zurich")) DBSession.add(Address(id=4, label="Lugano")) transaction.commit()
def setUp(self): # noqa curdir = os.path.dirname(os.path.abspath(__file__)) configfile = os.path.realpath( os.path.join(curdir, '../../tests.ini')) settings = get_appsettings(configfile) apply_local_settings(settings) engine = engine_from_config(settings, 'sqlalchemy.') DBSession.configure(bind=engine) from .models_test import Person, EmploymentStatus, Tag # noqa Base.metadata.create_all(engine) self.cleanup() # fill some test data into the `EmploymentStatus` and `Tags` table DBSession.add(EmploymentStatus(id=0, name='Worker')) DBSession.add(EmploymentStatus(id=1, name='Employee')) DBSession.add(EmploymentStatus( id=2, name='Self-employed and contractor')) DBSession.add(EmploymentStatus(id=3, name='Director')) DBSession.add(EmploymentStatus(id=4, name='Office holder')) DBSession.add(Tag(id=0, name='Tag A')) DBSession.add(Tag(id=1, name='Tag B')) DBSession.add(Tag(id=2, name='Tag C')) DBSession.add(Tag(id=3, name='Tag D')) DBSession.add(Tag(id=4, name='Tag E')) self.request = testing.DummyRequest(post=MultiDict(), dbsession=DBSession) testing.setUp(request=self.request) config = testing.setUp() config.add_route('form', '/{schema}/form/') config.add_route('view_user', '/{schema}/form/{hash}') config.add_route('confirm', '/{schema}/form/confirm') init_deform('c2cgeoform')
def setup_test_data(): from c2cgeoform.models import DBSession import transaction if DBSession.query(District).get(0) is None: DBSession.add(District(id=0, name="Pully")) DBSession.add(District(id=1, name="Paudex")) DBSession.add(District(id=2, name="Belmont-sur-Lausanne")) DBSession.add(District(id=3, name="Trois-Chasseurs")) DBSession.add(District(id=4, name="La Claie-aux-Moines")) DBSession.add(District(id=5, name="Savigny")) DBSession.add(District(id=6, name="Mollie-Margot")) if DBSession.query(Situation).get(0) is None: DBSession.add(Situation(id=0, name="Road", name_fr="Route")) DBSession.add(Situation(id=1, name="Sidewalk", name_fr="Trottoir")) DBSession.add(Situation(id=2, name="Berm", name_fr="Berme")) DBSession.add(Situation( id=3, name="Vegetated berm", name_fr="Berme végétalisée")) DBSession.add(Situation(id=4, name="Green zone", name_fr="Zone verte")) DBSession.add(Situation(id=5, name="Cobblestone", name_fr="Pavés")) transaction.commit()
def test_edit_submit_successful(self): from c2cgeoform.views import edit from models_test import Person, Phone, TagsForPerson person = Person(name="Peter", first_name="Smith") phone = Phone(number="123456789") person.phones.append(phone) tag_for_person = TagsForPerson(tag_id=0) person.tags.append(tag_for_person) DBSession.add(person) DBSession.flush() old_tag_for_person_id = tag_for_person.id request = self._get_request() request.matchdict['schema'] = 'tests_persons' request.matchdict['id'] = str(person.id) request.POST.add('id', str(person.id)) request.POST.add('submit', 'submit') request.POST.add('name', 'Peter') request.POST.add('first_name', 'Smith') request.POST.add('age', '43') request.POST.add('__start__', 'phones:sequence') request.POST.add('__start__', 'phones:mapping') request.POST.add('id', str(phone.id)) request.POST.add('number', '23456789') request.POST.add('person_id', str(person.id)) request.POST.add('__end__', 'phones:mapping') request.POST.add('__start__', 'phones:mapping') request.POST.add('number', '123456') request.POST.add('__end__', 'phones:mapping') request.POST.add('__end__', 'phones:sequence') request.POST.add('__start__', 'tags:sequence') request.POST.add('tags', u'0') request.POST.add('tags', u'1') request.POST.add('__end__', 'tags:sequence') response = edit(request) person = DBSession.query(Person).get(person.id) self.assertEquals('Peter', person.name) self.assertEquals('Smith', person.first_name) self.assertEquals(43, person.age) self.assertEquals(2, len(person.phones)) updated_phone = person.phones[0] self.assertEquals('23456789', updated_phone.number) self.assertEquals(phone.id, updated_phone.id) new_phone = person.phones[1] self.assertEquals('123456', new_phone.number) self.assertIsNotNone(new_phone.id) self.assertEquals(2, len(person.tags)) tag_for_person1 = person.tags[0] self.assertEquals(0, tag_for_person1.tag_id) self.assertEquals(person.id, tag_for_person1.person_id) self.assertIsNotNone(tag_for_person1.id) # a new row is created, also for the old entry self.assertNotEquals(old_tag_for_person_id, tag_for_person1.id) tag_for_person2 = person.tags[1] self.assertEquals(1, tag_for_person2.tag_id) self.assertEquals(person.id, tag_for_person2.person_id) self.assertIsNotNone(tag_for_person2.id) tags_for_persons = DBSession.query(TagsForPerson).all() # check that the old entry was deleted, so that there are only 2 self.assertEquals(2, len(tags_for_persons)) self.assertTrue('schema' in response) self.assertTrue('form' in response) form_html = response['form'] self.assertTrue('name="id"' in form_html) self.assertTrue('value="' + str(person.id) + '"' in form_html) self.assertTrue('name="id" value="' + str(person.id) + '"' in form_html) self.assertTrue('name="id" value="' + str(phone.id) + '"' in form_html) self.assertTrue('name="id" value="' + str(new_phone.id) + '"' in form_html) self.assertTrue('name="person_id" value="' + str(person.id) + '"' in form_html) self.assertTrue('name="submit"' in form_html) self.assertTrue('Tag A' in form_html) self.assertTrue('Tag B' in form_html)
def _add_test_persons(): from models_test import Person DBSession.add(Person(name="Smith", first_name="Peter")) DBSession.add(Person(name="Wayne", first_name="John")) DBSession.add(Person(name="Elda", first_name="Hasbrouck")) DBSession.add(Person(name="Lashaun", first_name="Brasel")) DBSession.add(Person(name="Lashawna", first_name="Ashford")) DBSession.add(Person(name="Lesha", first_name="Snellgrove")) DBSession.add(Person(name="Sulema", first_name="Page")) DBSession.add(Person(name="Derek", first_name="Boroughs")) DBSession.add(Person(name="Odis", first_name="Bateman")) DBSession.add(Person(name="Venetta", first_name="Briganti")) DBSession.add(Person(name="Monte", first_name="Quill")) DBSession.add(Person(name="Daniel", first_name="Ruth")) DBSession.add(Person(name="Eloise", first_name="Hellickson")) DBSession.add(Person(name="Hee", first_name="Deloney")) DBSession.add(Person(name="Sharee", first_name="Warf")) DBSession.add(Person(name="Delpha", first_name="Philip")) DBSession.add(Person(name="Claudio", first_name="Campfield")) DBSession.add(Person(name="Janessa", first_name="Beatty")) DBSession.add(Person(name="Hollis", first_name="Richmond")) DBSession.add(Person(name="Karoline", first_name="Carew")) DBSession.add(Person(name="Bess", first_name="Papp")) DBSession.add(Person(name="Vada", first_name="Infantino"))
def setUp(self): # noqa curdir = os.path.dirname(os.path.abspath(__file__)) configfile = os.path.realpath( os.path.join(curdir, '../../development.ini')) settings = get_appsettings(configfile) engine = engine_from_config(settings, 'sqlalchemy.') DBSession.configure(bind=engine) from models_test import Person, EmploymentStatus, Tag # noqa Base.metadata.create_all(engine) self.cleanup() # fill some test data into the `EmploymentStatus` and `Tags` table DBSession.add(EmploymentStatus(id=0, name='Worker')) DBSession.add(EmploymentStatus(id=1, name='Employee')) DBSession.add(EmploymentStatus( id=2, name='Self-employed and contractor')) DBSession.add(EmploymentStatus(id=3, name='Director')) DBSession.add(EmploymentStatus(id=4, name='Office holder')) DBSession.add(Tag(id=0, name='Tag A')) DBSession.add(Tag(id=1, name='Tag B')) DBSession.add(Tag(id=2, name='Tag C')) DBSession.add(Tag(id=3, name='Tag D')) DBSession.add(Tag(id=4, name='Tag E'))