def setUp(self): super(UsersTests, self).setUp() self._mox = mox.Mox() self._other = DATA self._me = { 'username': '******', 'password': '******', 'email': '*****@*****.**', } User.create(**self._me) User.create(**self._other) Blocked.create(self._me['username'], self._other['username']) self._mox.StubOutWithMock(APIHandler, 'get_current_user', use_mock_anything=True) APIHandler.get_current_user().AndReturn(self._me['username']) self._mox.ReplayAll()
def test_unblock_one(self): r = self.delete(self._path.format(self._other['username'])) self.assertEqual(r.code, 200) self.assertDictEqual(json.loads(r.body), {'status': 1}) exists = Blocked.get_by_user_blocked( self._me['username'], self._other['username']) self.assertIsNone(exists) self._mox.VerifyAll()
def get(self): username = self.current_user users = yield gen.maybe_future(Blocked.list_blocked(username)) blockeds = list() if users: ids = [user.blocked_id for user in users] users = yield gen.maybe_future(User.get_multi(*ids)) blockeds = [user.information() for user in users] raise gen.Return({ 'blockeds': blockeds, 'total': len(blockeds), })
def get(self, username): user = yield gen.maybe_future(User.get_by_name(username)) if user is None: raise exceptions.UsernameDoesNotExists() else: info = user.information() followed, blocked = False, False if self.current_user != username: me = yield gen.maybe_future(User.get_by_name(self.current_user)) followed = yield gen.maybe_future( Following.followed(me.id, user.id)) blocked = yield gen.maybe_future( Blocked.blocked(me.id, user.id)) info.update({'followed': followed, 'blocked': blocked}) raise gen.Return(info)
def delete(self, username): me = self.current_user r = yield gen.maybe_future(Blocked.get_by_user_blocked(me, username)) yield gen.maybe_future(r.delete())
def post(self, username): me = self.current_user yield gen.maybe_future(Blocked.create(me, username))