         let expectation = self.expectationWithDescription("Add login")
         let login2 = Login.createWithHostname("hostname1", username: "username2", password: "password2")
 
-        addLogin(login)() >>>
-            addLogin(login2) >>>
+        addLogin(login) >>>
+            addLoginCurried(login2) >>>
             getLoginsFor(login.protectionSpace, expected: [login2, login]) >>>
-            done(expectation)
+            done(login.protectionSpace, expectation: expectation)
 
         waitForExpectationsWithTimeout(10.0, handler: nil)
     }

        let expectation = self.expectationWithDescription("Update login")
        let updated = Login.createWithHostname("hostname1", username: "username1", password: "password3")

        var usageData = updated as! LoginUsageData
        usageData.timeCreated = NSDate.nowMicroseconds()
        usageData.timeLastUsed = NSDate.nowMicroseconds()

        addLogin(login)() >>>
            updateLogin(updated) >>>
            getLoginsFor(login.protectionSpace, expected: [updated]) >>>
            done(expectation)

        waitForExpectationsWithTimeout(10.0, handler: nil)
    }

    /* XXX: Trying to get the usage data for a login throws EXC_BAD_ACCESS. Punting on this for now.
    func testAddUseOfLogin() {
        let expectation = self.expectationWithDescription("Add visit")

        login.timeCreated = NSDate.nowMicroseconds()
        addLogin(login)() >>>
            addUseDelayed(login, time: 1) >>>
            getLoginDetailsFor(login, expected: login) >>>
            done(expectation)

        waitForExpectationsWithTimeout(10.0, handler: nil)
    }
    */

    func done(expectation: XCTestExpectation)() -> Success {
        return removeAllLogins() >>>
            getLoginsFor(login.protectionSpace, expected: []) >>> {
                expectation.fulfill()
                return succeed()
        }
    }

    // Note: These functions are all curried so that we pass arguments, but still chain them below
    func addLogin(login: LoginData)() -> Success {
        log.debug("Add \(login)")
        return logins.addLogin(login)
    }

    func updateLogin(login: LoginData)() -> Success {
        log.debug("Update \(login)")
        var usage = login as! LoginUsageData
        usage.timePasswordChanged = NSDate.nowMicroseconds()
        return logins.updateLogin(login)
    }

    func addUseDelayed(login: Login, time: UInt32)() -> Success {
        sleep(time)
        login.timeLastUsed = NSDate.nowMicroseconds()
        let res = logins.addUseOf(login)
        sleep(time)
        return res
    }

    func getLoginsFor(protectionSpace: NSURLProtectionSpace, expected: [LoginData])() -> Success {
        log.debug("Get logins for \(protectionSpace)")
        return logins.getLoginsForProtectionSpace(login.protectionSpace) >>== { results in
            XCTAssertEqual(expected.count, results.count)
            for (index, login) in enumerate(expected) {
                XCTAssertEqual(results[index]!.username!, login.username!)
                XCTAssertEqual(results[index]!.hostname, login.hostname)
                XCTAssertEqual(results[index]!.password, login.password)
            }
            return succeed()
        }
    }

    /*
    func getLoginDetailsFor(login: Login, expected: LoginUsageData)() -> Success {
        log.debug("Get details for \(login)")
        let deferred = logins.getUsageDataForLogin(login)
        log.debug("Final result \(deferred)")
        return deferred >>== { login in
            log.debug("Got cursor")
            XCTAssertEqual(expected.timePasswordChanged, login.timePasswordChanged)
            XCTAssertEqual(expected.timeLastUsed, login.timeLastUsed)
            XCTAssertEqual(expected.timeCreated, login.timeCreated)
            return succeed()
        }
    }
    */

    func removeLogin(login: LoginData)() -> Success {
        log.debug("Remove \(login)")
        return logins.removeLogin(login)
    }

    func removeAllLogins() -> Success {
        log.debug("Remove All")
        return logins.removeAll()
    }
}
    func testRemoveLogin() {
        let expectation = self.expectationWithDescription("Remove login")

        addLogin(login) >>>
            removeLogin(login) >>>
            getLoginsFor(login.protectionSpace, expected: []) >>>
            done(login.protectionSpace, expectation: expectation)

        waitForExpectationsWithTimeout(10.0, handler: nil)
    }
