'Test that a login attempt with an invalid user or invalid password
fails in the appropriate way.'

def test_badUsernamePasswordLogin(self):

    self.portal.registerChecker(checkers.InMemoryUsernamePasswordDatabaseDontUse(user='pass'))
    firstLogin = self.clientFactory.login(credentials.UsernamePassword('nosuchuser', 'pass'))
    secondLogin = self.clientFactory.login(credentials.UsernamePassword('user', 'wrongpass'))
    self.assertFailure(firstLogin, UnauthorizedLogin)
    self.assertFailure(secondLogin, UnauthorizedLogin)
    d = gatherResults([firstLogin, secondLogin])
    def cleanup(ignore):
        errors = self.flushLoggedErrors(UnauthorizedLogin)
        self.assertEqual(len(errors), 2)
    d.addCallback(cleanup)
    self.establishClientAndServer()
    self.pump.flush()
    return d
