Commit 8e5d4ee9 authored by Tomas Taraba's avatar Tomas Taraba

3386 Add tests with and without user association

parent da8e95a3
......@@ -14,10 +14,9 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from xivo_dao.alchemy.labels import Labels
from xivo_dao.helpers.db_manager import daosession
from xivo_dao.helpers.db_manager import Session
from xivo_dao.helpers.db_manager import daosession
from xivo_dao.resources.labels.search import label_search
from xivo_dao.resources.utils.search import SearchResult
......
......@@ -14,10 +14,12 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from hamcrest import assert_that, equal_to
from xivo_dao.resources.utils.search import SearchResult
from xivo_dao.tests.test_dao import DAOTestCase
from xivo_dao.resources.labels import dao as label_dao
from xivo_dao.resources.utils.search import SearchResult
from xivo_dao.resources.user import dao as user_dao
class TestLabelExist(DAOTestCase):
......@@ -33,3 +35,24 @@ class TestLabelExist(DAOTestCase):
result = label_dao.exists(label_row.id)
assert_that(result, equal_to(True))
def test_get_all_labels(self):
label_row = self.add_label()
result = label_dao.search()
expected = SearchResult(total=1, items=[label_row])
assert_that(result[1][0].users_count, equal_to(0))
assert_that(result, equal_to(expected))
def test_get_all_labels_with_associated_user(self):
label_row = self.add_label()
user = self.add_user(callerid='"John Doe"')
user.labels.append(label_row)
result = label_dao.search()
expected = SearchResult(total=1, items=[label_row])
assert_that(result[1][0].users_count, equal_to(1))
assert_that(result, equal_to(expected))
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