Ejemplo n.º 1
0
def main():
    db = Database(mode='PROD', echo=True)
    if not db.has_tables():
        db.make_tables()
    with open('.smurfs.txt') as f:
        for line in f:
            fetch_and_store_summoner(line.strip(), db)

    session = db.SessionMaker()
    print(session.query(GameStats, GameStats.champion).all())
Ejemplo n.º 2
0
class TestObjectInitialization(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.db = Database()
        self.db.make_tables()

    @classmethod
    def tearDownClass(self):
        self.db.destroy_tables()

    def tearDown(self):
        self.db.truncate_tables()

    def test_when_game_is_made(self):
        session = self.db.SessionMaker()

        def query_for_game(session):
            return session.query(Game).first()

        expected = add_a_game(session)
        observed = query_for_game(session)
        session.close()
        assert expected is observed, 'Observed:\t{0}\nExpected:\t{1}'.format(
            observed, expected)

    def test_when_game_stats_is_made(self):
        session = self.db.SessionMaker()

        def query_for_game_stats():
            return session.query(GameStats).filter_by(
                summoner_name='Bjerson').first()

        expected = add_game_stats(session)
        observed = query_for_game_stats()
        session.close()
        assert expected is observed, 'Observed:\t{0}\nExpected:\t{1}'.format(
            observed, expected)

    def test_when_summoner_is_made(self):
        session = self.db.SessionMaker()

        def query_for_summoner():
            return session.query(Summoner).first()

        expected = add_a_summoner(session)
        observed = query_for_summoner()
        session.close()
        assert expected is observed, 'Observed:\t{0}\nExpected:\t{1}'.format(
            observed, expected)

    def test_when_summoner_name_is_made(self):
        session = self.db.SessionMaker()

        def query_for_summoner_name():
            return session.query(SummonerName).first()

        expected = add_a_summoner_name(session)
        observed = query_for_summoner_name()
        session.close()
        assert expected is observed, 'Observed:\t{0}\nExpected:\t{1}'.format(
            observed, expected)

    def test_when_they_work_together(self):
        pass