import unittest
import db
from main.model import OrganizativeUnit, Computer


class TestMainModels(unittest.TestCase):

    def test_repo(self):
        s = db.connect()
        fresa = s.query(Computer).filter_by(name=u"fresa").one()
        ord2 = s.query(Computer).filter_by(name=u"ord2").one()

        sugus = s.query(OrganizativeUnit).filter_by(name=u"Aula A3.60").one()
        alpha = s.query(OrganizativeUnit).filter_by(name=u"Aula A4.10").one()
        facu = s.query(OrganizativeUnit).filter_by(name=u"Facultad").one()

        repo1 = fresa.get_repo()
        repo2 = ord2.get_repo()
        repo3 = sugus.get_repo()
        repo4 = alpha.get_repo()
        repo5 = facu.get_repo()

        self.assertEqual(repo1.name, u"chocolate")
        self.assertEqual(repo2.name, u"ord1")

        self.assertEqual(repo1, repo3)
        self.assertEqual(repo2, repo4)
        self.assertEqual(repo2, repo5)


def suite():
   suite = unittest.TestSuite()
   suite.addTest(unittest.makeSuite(TestMainModels))
   return suite
