Пример #1
0
    def test_api_can_retweet_a_status(self):
        '''Test API can retweet a Status'''
        status_to_retweet = {'text': "Hahaha retweet this i dare you"}
        user = {
            'username': "******",
            'email': "*****@*****.**",
            'password': "******"
        }
        with self.app.app_context():
            u = User(email=user['email'], password_hash=user['password'],
                     username=user['username'], verified=True)
            u.insert()
            s = Tweet(text=status_to_retweet['text'], user=u)
            s.insert()

            rv = self.client().post(
                '/statuses/retweet', data=json.dumps({'id': s.id}),
                content_type='application/json', headers={'x-access-token': self.auth_token})
            result_in_json = json.loads(
                rv.data.decode('utf-8').replace("'", "\""))
            self.assertEqual(rv.status_code, 201)
            self.assertIn('success', str(result_in_json['data']))
            self.client().post(
                '/statuses/reply', data=json.dumps({'id': s.id, 'text': 'Hahaha now am gonna also reply'}),
                content_type='application/json', headers={'x-access-token': self.auth_token})
Пример #2
0
def reply_status(current_user):
    data = request.get_json()
    s = Tweet.query.filter_by(id=data['id']).first()
    if not s:
        return jsonify({'data': 'Resource not found', 'error': None}), 404
    reply = Tweet(text=data['text'], user=current_user, in_reply_to_status=s)
    reply.insert()
    db.session.commit()
    return jsonify({'data': 'success', 'error': None}), 201
Пример #3
0
def share_a_status(current_user):
    data = request.get_json()
    s = Tweet.query.filter_by(id=data['id']).first()
    if not s:
        return jsonify({'data': 'Resource not found', 'error': None}), 404
    retweet = Tweet(text=data.get("text", None),
                    user=current_user,
                    retweet_status=s)
    retweet.insert()
    db.session.commit()
    return jsonify({'data': 'success', 'error': None}), 201
Пример #4
0
def create_status(current_user):
    data = request.get_json()
    s = Tweet(text=data['text'], user=current_user)
    s.insert()
    return jsonify({'data': 'success', 'error': None}), 201