Пример #1
0
 def lookupTeamID(self, teamname):
     team = Team()
     team.connectDB()
     teamID = team.lookupID({'teamname': teamname}, self.log)
     if (len(teamID) > 1):
         raise RuntimeError('Ambiguous team name: ' + str(teamname))
     elif (len(teamID) == 0):
         raise RuntimeError('Team not found: ' + str(teamname))
     # At this point we know teamID is a list of length 1, so we return
     # the first value only
     return teamID[0]
Пример #2
0
def test_game_lookupID(data_teams):
    # Setup
    log = Log('test.log')
    t = Team()
    t.connectDB()

    # This should raise a format error
    with pytest.raises(RuntimeError) as excinfo:
        needle = 'My favorite team'
        t.lookupID(needle, log)
    assert 'lookupID requires a dictionary' in str(excinfo.value)

    # This should raise a missing-fields error
    with pytest.raises(RuntimeError) as excinfo:
        needle = {
            'FirstName': 'Harvey'
        }
        t.lookupID(needle, log)
    assert 'Submitted data is missing the following fields' in str(excinfo.value)

    # This should bring back one record
    needle = {
        'teamname': 'Columbus Crew'
    }
    assert len(t.lookupID(needle, log)) >= 1
Пример #3
0
def test_team_disconnect():
    t = Team()
    t.connectDB()
    assert hasattr(t, 'db')
    t.disconnectDB()
    assert hasattr(t, 'db') is False