2024-07-14 23:20:44 -05:00
|
|
|
# -*- coding: utf-8; -*-
|
|
|
|
|
|
|
|
from wuttjamaican import people as mod
|
2024-08-27 19:10:50 -05:00
|
|
|
from wuttjamaican.testing import DataTestCase
|
2024-07-14 23:20:44 -05:00
|
|
|
|
|
|
|
try:
|
|
|
|
import sqlalchemy as sa
|
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
|
|
|
|
|
2024-08-27 19:10:50 -05:00
|
|
|
class TestPeopleHandler(DataTestCase):
|
2024-07-14 23:20:44 -05:00
|
|
|
|
2024-08-27 19:10:50 -05:00
|
|
|
def make_handler(self):
|
|
|
|
return mod.PeopleHandler(self.config)
|
2024-07-14 23:20:44 -05:00
|
|
|
|
|
|
|
def test_get_person(self):
|
|
|
|
model = self.app.model
|
|
|
|
myperson = model.Person(full_name='Barny Rubble')
|
|
|
|
self.session.add(myperson)
|
|
|
|
self.session.commit()
|
2024-08-27 19:10:50 -05:00
|
|
|
handler = self.make_handler()
|
2024-07-14 23:20:44 -05:00
|
|
|
|
|
|
|
# empty obj is ignored
|
2024-08-27 19:10:50 -05:00
|
|
|
person = handler.get_person(None)
|
2024-07-14 23:20:44 -05:00
|
|
|
self.assertIsNone(person)
|
|
|
|
|
|
|
|
# person is returned as-is
|
2024-08-27 19:10:50 -05:00
|
|
|
person = handler.get_person(myperson)
|
2024-07-14 23:20:44 -05:00
|
|
|
self.assertIs(person, myperson)
|
|
|
|
|
|
|
|
# find person from user
|
|
|
|
myuser = model.User(username='barney', person=myperson)
|
|
|
|
self.session.add(myuser)
|
|
|
|
self.session.commit()
|
2024-08-27 19:10:50 -05:00
|
|
|
person = handler.get_person(myuser)
|
2024-07-14 23:20:44 -05:00
|
|
|
self.assertIs(person, myperson)
|