def test_prepare(self): prepare = Prepare(id=3, key='biz', predicate='set', argument='a') self.assertEqual(prepare.to_json(), { 'id': 3, 'key': 'biz', 'predicate': 'set', 'argument': 'a' }) target = Prepare._id prepare = Prepare(key='buzz', predicate='a', argument='b') self.assertEqual(prepare.to_json(), { 'id': target, 'key': 'buzz', 'predicate': 'a', 'argument': 'b' }) _ = yield self.assert_send_works(prepare, '/prepare') request = tornado.httpclient.HTTPRequest( body=json.dumps(prepare.to_json()), method='POST', headers={'Content-Type': 'application/json'}, url='/prepare') target = Prepare.from_request(request) self.assertEqual(target.to_json(), prepare.to_json())
def test_success(self): prepare = Prepare(id=3, key='biz', predicate='set', argument='a') success = Success(prepare=prepare) self.assertEqual(success.to_json(), { 'status': 'SUCCESS', 'prepare': prepare.to_json() })
def test_promise(self): promise = Promise() self.assertEqual(promise.prepare, None) prepare = Prepare(id=3, key='biz', predicate='set', argument='a') promise = Promise(prepare=prepare) self.assertEqual(promise.prepare, prepare) self.assertEqual(promise.to_json(), {'prepare': prepare.to_json()})
def test_returns_lower_numbered_in_progress_promises(self): lower_prepare = Prepare(id=0, key='foo', predicate='set', argument='a') higher_prepare = Prepare(id=1, key='foo', predicate='set', argument='b') success = self.post('/prepare', lower_prepare.to_json()) self.assertEqual(success.code, 200) self.assertEqual( Promise.from_response(success).to_json(), {'prepare': None}) self.assertEqual(Promises.current.highest_numbered().to_json(), {'prepare': lower_prepare.to_json()}) failure = self.post('/prepare', higher_prepare.to_json()) self.assertEqual(failure.code, 200) target = Promise.from_response(failure) self.assertEqual(target.to_json(), {'prepare': lower_prepare.to_json()})