Exemplo n.º 1
0
Arquivo: tests.py Projeto: ryanhle/idb
class MissingCarrierTests(TestCase):
    def setUp(self):
        self.engine = create_engine('sqlite:///:memory:', echo=False)
        Session = sessionmaker(bind=self.engine)
        session = Session()

        Base.metadata.create_all(self.engine)

        iPhoneX = Model(name="Apple iPhoneX")
        iPhoneX.brand = Brand(name="Apple", location="Cupertino, United States")
        iPhoneX.os = OS(name="iOS", developer="Apple")

        session.add(iPhoneX)
        session.commit()

        self.db = Database(self.engine)

    def test_os(self):
        self.assertEqual(len(self.db.get_os_all()), 1)
        self.assertEqual(self.db.get_os_all()[0].name, "iOS")

    def test_carrier(self):
        self.assertEqual(len(self.db.get_carrier_all()), 0)

    def test_brand(self):
        self.assertEqual(len(self.db.get_brand_all()), 1)
        self.assertEqual(self.db.get_brand_all()[0].name, "Apple")

    def test_model(self):
        self.assertEqual(len(self.db.get_model_all()), 1)
        self.assertEqual(self.db.get_model_all()[0].name, "Apple iPhoneX")
Exemplo n.º 2
0
Arquivo: tests.py Projeto: ryanhle/idb
class DbInterfaceTests (TestCase):
    def setUp(self):
        self.engine = create_engine('sqlite:///:memory:', echo=False)
        Session = sessionmaker(bind=self.engine)
        session = Session()

        Base.metadata.create_all(self.engine)

        lgv10 = Model(name="LG v10")
        lgv10.brand = Brand(name="LG", location="Seoul, South Korea")
        lgv10.os = OS(name="Android", developer="Google")
        lgv10.carriers = [Carrier(name="Verizon")]

        session.add(lgv10)
        session.commit()

        self.db = Database(self.engine)

    def test_os(self):
        self.assertEqual(len(self.db.get_os_all()), 1)
        self.assertEqual(self.db.get_os_all()[0].name, "Android")

    def test_carrier(self):
        self.assertEqual(len(self.db.get_carrier_all()), 1)
        self.assertEqual(self.db.get_carrier_all()[0].name, "Verizon")

    def test_brand(self):
        self.assertEqual(len(self.db.get_brand_all()), 1)
        self.assertEqual(self.db.get_brand_all()[0].name, "LG")

    def test_model(self):
        self.assertEqual(len(self.db.get_model_all()), 1)
        self.assertEqual(self.db.get_model_all()[0].name, "LG v10")

    def test_single_model(self):
        self.assertNotEqual(self.db.get_model_id(1), None)
        self.assertEqual(self.db.get_model_id(1).name, "LG v10")
        self.assertEqual(self.db.get_model_id(2), None)
    
    def test_single_brand(self):
        self.assertNotEqual(self.db.get_brand_id(1), None)
        self.assertEqual(self.db.get_brand_id(1).name, "LG")
        self.assertEqual(self.db.get_brand_id(2), None)

    def test_single_os(self):
        self.assertNotEqual(self.db.get_os_id(1), None)
        self.assertEqual(self.db.get_os_id(1).name, "Android")
        self.assertEqual(self.db.get_os_id(2), None)

    def test_single_carriers(self):
        self.assertNotEqual(self.db.get_carrier_id(1), None)
        self.assertEqual(self.db.get_carrier_id(1).name, "Verizon")
        self.assertEqual(self.db.get_carrier_id(2), None)
Exemplo n.º 3
0
Arquivo: tests.py Projeto: ryanhle/idb
class MultiplePhonesTests(TestCase):
    def setUp(self):
        self.engine = create_engine('sqlite:///:memory:', echo=False)
        Session = sessionmaker(bind=self.engine)
        session = Session()

        Base.metadata.create_all(self.engine)

        lgv10 = Model(name="LG v10")
        lgv10.brand = Brand(name="LG", location="Seoul, South Korea")
        lgv10.os = OS(name="Android", developer="Google")
        lgv10.carriers = [Carrier(name="Verizon")]

        session.add(lgv10)
        session.commit()

        iPhoneX = Model(name="Apple iPhoneX")
        iPhoneX.brand = Brand(name="Apple", location="Cupertino, United States")
        iPhoneX.os = OS(name="iOS", developer="Apple")
        iPhoneX.carriers = [Carrier(name="AT&T")]

        session.add(iPhoneX)
        session.commit()

        self.db = Database(self.engine)

    def test_os(self):
        self.assertEqual(len(self.db.get_os_all()), 2)
        self.assertEqual(self.db.get_os_all()[0].name, "Android")
        self.assertEqual(self.db.get_os_all()[1].name, "iOS")

    def test_carrier(self):
        self.assertEqual(len(self.db.get_carrier_all()), 2)
        self.assertEqual(self.db.get_carrier_all()[0].name, "Verizon")
        self.assertEqual(self.db.get_carrier_all()[1].name, "AT&T")

    def test_brand(self):
        self.assertEqual(len(self.db.get_brand_all()), 2)
        self.assertEqual(self.db.get_brand_all()[0].name, "LG")
        self.assertEqual(self.db.get_brand_all()[1].name, "Apple")

    def test_model(self):
        self.assertEqual(len(self.db.get_model_all()), 2)
        self.assertEqual(self.db.get_model_all()[0].name, "LG v10")
        self.assertEqual(self.db.get_model_all()[1].name, "Apple iPhoneX")
Exemplo n.º 4
0
Arquivo: tests.py Projeto: ryanhle/idb
class EmptyTest(TestCase):
    def setUp(self):
        self.engine = create_engine('sqlite:///:memory:', echo=False)
        Session = sessionmaker(bind=self.engine)
        session = Session()

        Base.metadata.create_all(self.engine)
        session.commit()

        self.db = Database(self.engine)

    def test_os(self):
        self.assertEqual(len(self.db.get_os_all()), 0)

    def test_carrier(self):
        self.assertEqual(len(self.db.get_carrier_all()), 0)

    def test_brand(self):
        self.assertEqual(len(self.db.get_brand_all()), 0)

    def test_model(self):
        self.assertEqual(len(self.db.get_model_all()), 0)