Add get_context in user_dao

parent b75b0ce3
......@@ -349,13 +349,18 @@ class TestUserFeaturesDAO(DAOTestCase):
self.session.commit()
return cti_profile.id
def _add_user_with_line(self, name, context='default'):
def _add_user(self, name):
user = UserFeatures()
user.firstname = name
self.session.add(user)
self.session.commit()
return user
def _add_user_with_line(self, name, context='default'):
user = self._add_user(name)
line = LineFeatures()
line.iduserfeatures = user.id
line.context = context
......@@ -724,3 +729,17 @@ class TestUserFeaturesDAO(DAOTestCase):
self.assertEquals(user.id, user_result.id)
self.assertEquals(line.id, line_id_result)
def test_get_context(self):
user, line = self._add_user_with_line('test_user1')
context = user_dao.get_context(user.id)
self.assertEquals(context, line.context)
def test_get_context_no_line(self):
user = self._add_user('test_user1')
context = user_dao.get_context(user.id)
self.assertEqual(context, None)
......@@ -211,3 +211,15 @@ def get_device_id(user_id):
if not row:
raise LookupError('Cannot find a device from this user id %s' % user_id)
return int(row.device)
def get_context(user_id):
res = (_session()
.query(LineFeatures.context)
.filter(LineFeatures.iduserfeatures == user_id)
.first())
if not res:
return None
return res.context
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment