コード例 #1
0
ファイル: tests.py プロジェクト: ryanhle/idb
class FullModelTest(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")]
        lgv10.release_date = "10/02/2015"
        lgv10.hardware_designer = "LG"
        lgv10.market_countries = "South Korea"
        lgv10.market_regions = "Asia"

        session.add(lgv10)
        session.commit()

        self.db = Database(self.engine)

    def test_model(self):
        self.assertEqual(len(self.db.get_model_all()), 1)
        self.assertEqual(self.db.get_model_all()[0].name, "LG v10")
        self.assertEqual(self.db.get_model_all()[0].brand, "LG")
        self.assertEqual(self.db.get_model_all()[0].carriers, ["Verizon"])
        self.assertEqual(self.db.get_model_all()[0].release_date, "10/02/2015")
        self.assertEqual(self.db.get_model_all()[0].market_countries, ["South Korea"])
        self.assertEqual(self.db.get_model_all()[0].market_regions, ["Asia"])
コード例 #2
0
ファイル: tests.py プロジェクト: ryanhle/idb
    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)
        self.session = session
コード例 #3
0
ファイル: tests.py プロジェクト: ryanhle/idb
    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)
コード例 #4
0
ファイル: tests.py プロジェクト: ryanhle/idb
    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)
コード例 #5
0
ファイル: tests.py プロジェクト: 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")
コード例 #6
0
ファイル: tests.py プロジェクト: ryanhle/idb
    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")]
        lgv10.release_date = "10/02/2015"
        lgv10.hardware_designer = "LG"
        lgv10.market_countries = "South Korea"
        lgv10.market_regions = "Asia"

        session.add(lgv10)
        session.commit()

        self.db = Database(self.engine)
コード例 #7
0
ファイル: tests.py プロジェクト: ryanhle/idb
class InsertOsTest(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)
        self.session = session

    def os_builder(self, quantity):
        oss = []
        for i in range(0, quantity):
            os = Models.OS(image="http://placekitten.com/{0}".format(i),
                    name="iPhone {0}".format(i),
                    developer="Apple {0}".format(i),
                    release_date="01/01/1999",
                    version="0.{0}".format(i),
                    os_kernel="0.{0}".format(i),
                    os_family="0.{0}".format(i),
                    supported_cpu_instruction_sets=list(range(0, i)),
                    predecessor="iPhone {0}".format(i - 1),
                    brands=list(range(0, i)),
                    models=list(range(0, i)),
                    codename="iPhone {0}".format(i),
                    successor="iPhone {0}".format(i + 1))
            oss += [os]
        return oss

    def test_os_insert(self):
        oss = self.os_builder(10)
        Inserter.insert_os(oss, self.session)
        self.session.commit()
        os_get = self.db.get_os_all()
        self.assertEqual(len(os_get), 10)
        i = 0
        for os in os_get:
            self.assertEqual(os.image, "http://placekitten.com/{0}".format(i))
            self.assertEqual(os.name, "iPhone {0}".format(i))
            self.assertEqual(os.developer, "Apple {0}".format(i))
            self.assertEqual(os.release_date, "01/01/1999")
            self.assertEqual(os.version, "0.{0}".format(i))
            self.assertEqual(os.os_kernel, "0.{0}".format(i))
            self.assertEqual(os.os_family, "0.{0}".format(i))
            self.assertEqual(os.supported_cpu_instruction_sets, list(range(0, i)))
            self.assertEqual(os.predecessor, "iPhone {0}".format(i - 1))
            self.assertEqual(os.brands, list(range(0, i)))
            self.assertEqual(os.models, list(range(0, i)))
            self.assertEqual(os.codename, "iPhone {0}".format(i))
            self.assertEqual(os.successor, "iPhone {0}".format(i + 1))
            i += 1
コード例 #8
0
ファイル: tests.py プロジェクト: 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)
コード例 #9
0
ファイル: tests.py プロジェクト: 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")
コード例 #10
0
ファイル: main.py プロジェクト: fgj54jrt/idb
from flask import Flask, render_template, jsonify
from functools import lru_cache
import os

app = Flask(__name__)

from app.db_interface import Database

db = Database()


@app.route('/')
@lru_cache(maxsize=1)
def hello_world():
    return render_template('index.html')


@app.route('/vis')
@lru_cache(maxsize=1)
def visualize():
    return render_template('vis.html')


@app.route('/models', methods=['GET'])
@lru_cache(maxsize=1)
def models_get():
    return jsonify([model.serialize() for model in db.get_model_all()])


@app.route('/brands', methods=['GET'])
@lru_cache(maxsize=1)
コード例 #11
0
ファイル: tests.py プロジェクト: 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)