def test_mtom_players(self):
     event1 = Event('TheEvent', date.today()+timedelta(days=1))
     self.session.add(event1)
     # self.layer.commit()
     event1 = self.session.query(Event).one()
     nation1 = Nation('Nation1', event1.id_, 'SWE')
     self.session.add(nation1)
     nation2 = Nation('Nation2', event1.id_, 'GBR')
     self.session.add(nation2)
     # self.layer.commit()
     nations = self.session.query(Nation).all()
     event = self.session.query(Event).one()
     game = Game(datetime.now(), event.id_,'group1', nation1_id=nations[0].id_, nation2_id=nations[1].id_)
     game.nation1_score = 3
     game.nation2_score = 0
     self.session.add(game)
     # self.layer.commit()
     event1 = self.session.query(Event).one()
     game = self.session.query(Game).one()
     nations = self.session.query(Nation).all()
     player1 = Player('Freddy', 'midfield', nations[0].id_, event1.id_)
     player2 = Player('Hans', 'defence', nations[0].id_, event1.id_)
     game.players.append(player1)
     game.players.append(player2)
     # self.layer.commit()
     game = self.session.query(Game).one()
     players = self.session.query(Player).all()
     self.assertEqual(len(game.players), 2)
     self.assertEqual(players[0].games[0], game)
    def test_creation(self):
        event1 = Event('TheEvent', date.today()+timedelta(days=1))
        self.session.add(event1)
        event1 = self.session.query(Event).one()
        nation1 = Nation('Nation1', event1.id_, 'SWE')
        self.session.add(nation1)
        nation2 = Nation('Nation2', event1.id_, 'GBR')
        self.session.add(nation2)
        # self.layer.commit()
        nations = self.session.query(Nation).all()
        event = self.session.query(Event).one()
        game = Game(datetime.now(), event.id_,'group1', nation1_id=nations[0].id_, nation2_id=nations[1].id_)
        game.nation1_score = 3
        game.nation2_score = 0
        self.session.add(game)
        player1 = Player('Freddy', 'Midfield', nations[0].id_, event1.id_)
        self.session.add(player1)
        # self.layer.commit()


        player = self.session.query(Player).one()
        game = self.session.query(Game).one()
        stats1 = Playerstatistics(player.id_, game.id_, 5)
        self.session.add(stats1)
        # self.layer.commit()
        myplayer = self.session.query(Player).one()
        game = self.session.query(Game).one()
        stats = self.session.query(Playerstatistics).one()
        self.assertEqual(stats.__repr__(), '<Statistics for Player Freddy. Points: 5>')
        points = myplayer.get_points_for_game(game.id_, self.session)
        self.assertEqual(points, 5)
    def test_creation(self):
        event1 = Event('TheEvent', date.today()+timedelta(days=1))
        # self.layer.commit()
        self.session.add(event1)        
        event1 = self.session.query(Event).one()
        nation1 = Nation('Nation1', event1.id_, 'SWE')
        self.session.add(nation1)
        nation2 = Nation('Nation2', event1.id_, 'GBR')
        self.session.add(nation2)
        # self.layer.commit()
        nations = self.session.query(Nation).all()
        event = self.session.query(Event).one()
        game = Game(datetime.now(), event.id_,'group1', nation1_id=nations[0].id_, nation2_id=nations[1].id_)
        game.nation1_score = 3
        game.nation2_score = 0
        self.session.add(game)
        # self.layer.commit()

        nation = self.session.query(Nation).first()
        player1 = Player('Freddy', 'Goalkeeper', nation.id_, event.id_)
        self.session.add(player1)
        # self.layer.commit()
        
        player1 = self.session.query(Player).one()
        game = self.session.query(Game).one()
        save1 = Save(player1.id_, game.id_)
        self.session.add(save1)
        # self.layer.commit()
        saves = self.session.query(Save).all()
        self.assertEqual(len(saves),1)
        self.assertEqual(saves[0].__repr__(), '<Save <Player Freddy>, 1>')
    def test_creation(self):
        event1 = Event('TheEvent', date.today()+timedelta(days=1))
        self.session.add(event1)        
        # self.layer.commit()
        event1 = self.session.query(Event).one()
        nation1 = Nation('Nation1', event1.id_, 'SWE')
        self.session.add(nation1)
        nation2 = Nation('Nation2', event1.id_, 'GBR')
        self.session.add(nation2)
        # self.layer.commit()
        nations = self.session.query(Nation).all()
        event = self.session.query(Event).one()
        game = Game(datetime.now(), event.id_,'group1',nation1_id=nations[0].id_, nation2_id=nations[1].id_)
        game.nation1_score = 3
        game.nation2_score = 0
        self.session.add(game)
        # self.layer.commit()
        games = self.session.query(Game).all()

        self.assertEqual(len(games), 1)
        self.assertEqual(games[0].__repr__(), '<Game SWE-GBR>')