示例#1
0
def test_player_lookupIDbyGoal():
    # Setup
    log = Log('test.log')
    p = Player()
    p.connectDB()

    # Format error
    with pytest.raises(RuntimeError) as excinfo:
        needle = 'Wil'
        p.lookupIDbyGoal(needle, log)
    assert 'lookupID requires a dictionary' in str(excinfo.value)

    # Missing fields error
    with pytest.raises(RuntimeError) as excinfo:
        needle = {
            'FirstName': 'Wil',
            'LastName': 'Trapp'
        }
        p.lookupIDbyGoal(needle, log)
    assert 'Submitted data is missing the following fields' in str(excinfo.value)

    # TODO: Need to actually look something up...
    needle = {
        'playername': 'Man',
        'TeamID': 2,
        'GameID': 1,
    }
    assert p.lookupIDbyGoal(needle, log) == [3]
示例#2
0
    def lookupPlayerID(self, event):
        self.log.message('Looking up PlayerID for event:\n' + str(event))

        # Swap team and opponent IDs for own goals
        event = self.swapTeamIDs(event)

        p = Player()
        p.connectDB()

        PlayerID = p.lookupIDbyGoal(event, self.log)

        # Swap team and opponent IDs back for own goals
        event = self.swapTeamIDs(event)

        if (len(PlayerID) != 1):
            # First step is to ask the user to disambiguate
            newID = self.disambiguatePlayers(event, PlayerID)
            PlayerID = []
            PlayerID.append(newID)

        if (PlayerID[0] == 0):
            # If PlayerID is still zero, mark it as missing
            self.processMissingRecord(event['playername'], len(PlayerID))
            return False

        event['PlayerID'] = PlayerID[0]
        return event