Exemple #1
0
def test_sent_message_delete_not_exists(client, database):
    user = User('test')
    database.session.add(user)
    database.session.commit()

    rv = client.delete('/messages/{}/sent/1'.format(user.user_login))
    assert rv.status_code == 404
Exemple #2
0
def test_inbox_message_unread_not_exists(client, database):
    user = User('test')
    database.session.add(user)
    database.session.commit()

    rv = client.patch('/messages/{}/inbox/1/unread'.format(user.user_login))
    assert rv.status_code == 404
Exemple #3
0
def test_inbox_message(client, database):
    user = User('test')
    ib1 = Inbox('Subj1', 'Body of this', 'root', 'test;testy')
    user.inboxs.append(ib1)
    database.session.add(user)
    database.session.commit()

    rv = client.get('/messages/{}/inbox/{}'.format(user.user_login,
                                                   ib1.inbox_id))
    json = rv.get_json()
    assert rv.status_code == 200
    assert json == {
        str(ib1.inbox_id): {
            'subject':
            ib1.subject,
            'body':
            ib1.body,
            'from_user':
            ib1.from_user,
            'to_users':
            ib1.to_users,
            'read':
            ib1.read,
            'read-href':
            url_for('inboxmessageread',
                    user_login=user.user_login,
                    message_id=ib1.inbox_id,
                    _external=True),
            'unread-href':
            url_for('inboxmessageunread',
                    user_login=user.user_login,
                    message_id=ib1.inbox_id,
                    _external=True)
        }
    }
Exemple #4
0
def test_inbox_get_empty(client, database):
    user = User('test')
    database.session.add(user)
    database.session.commit()
    rv = client.get('/messages/{}/inbox'.format(user.user_login))
    assert rv.status_code == 200
    assert rv.get_json() == {'data': [], 'total': 0}
Exemple #5
0
def test_sent_post(client, database):
    user = User('test')
    database.session.add(user)
    user2 = User('test2')
    database.session.add(user2)
    user3 = User('test3')
    database.session.add(user3)
    database.session.commit()

    msg = {
        'subject': 'This is subj',
        'body': 'This is body',
        'to_users': 'test2;notest;test3;nonotest'
    }

    rv = client.post('/messages/{}/sent'.format(user.user_login), json=msg)
    assert rv.status_code == 201
    created = rv.get_json()
    created_id = list(created.keys())[0]
    created_obj = Sent.query.filter_by(sent_id=created_id,
                                       user_id=user.user_id).first()
    created_obj2 = Inbox.query.filter_by(user_id=user2.user_id).first()
    created_obj3 = Inbox.query.filter_by(user_id=user3.user_id).first()
    assert created_obj and created_obj2 and created_obj3
    assert created[created_id]['href'] == url_for('sentmessage',
                                                  user_login=user.user_login,
                                                  message_id=created_id,
                                                  _external=True)
    assert created[created_id]['subject'] == msg['subject'] and \
           created_obj.subject == msg['subject'] and \
           created_obj2.subject == msg['subject'] and \
           created_obj3.subject == msg['subject']
    assert created[created_id]['body'] == msg['body'] and \
           created_obj.body == msg['body'] and \
           created_obj2.body == msg['body'] and \
           created_obj3.body == msg['body']
    assert created[created_id]['from_user'] == user.user_login and \
           created_obj2.from_user == user.user_login and \
           created_obj3.from_user == user.user_login
    assert created[created_id]['to_users'] == msg['to_users'] and \
           created_obj.to_users == msg['to_users'] and \
           created_obj2.to_users == msg['to_users'] and \
           created_obj3.to_users == msg['to_users']
Exemple #6
0
def test_sent_message_delete(client, database):
    user = User('test')
    sn1 = Sent('This is is', 'This body', 'testy;testx')
    user.sents.append(sn1)
    database.session.add(user)
    database.session.commit()

    rv = client.delete('/messages/{}/sent/{}'.format(user.user_login,
                                                     sn1.sent_id))
    assert rv.status_code == 204
    assert not Sent.query.filter_by(sent_id=sn1.sent_id).first()
Exemple #7
0
def test_sent_post_invalid_argument(client, database):
    user = User('test')
    database.session.add(user)
    database.session.commit()

    rv = client.post('/messages/test/sent',
                     json={
                         'subject': 'This is subj',
                         'body': 'This is body'
                     })
    assert rv.status_code == 400
Exemple #8
0
def test_inbox_message_delete(client, database):
    user = User('test')
    ib1 = Inbox('Subj1', 'Body of body', 'koor', 'test;testa;testb;testc')
    user.inboxs.append(ib1)
    database.session.add(user)
    database.session.commit()

    rv = client.delete('/messages/{}/inbox/{}'.format(user.user_login,
                                                      ib1.inbox_id))
    assert rv.status_code == 204
    assert not Inbox.query.filter_by(inbox_id=ib1.inbox_id).first()
Exemple #9
0
def test_inbox_message_unread(client, database):
    user = User('test')
    ib1 = Inbox('Subj1', 'Body fo body', 'yum', 'test;test1;test5')
    ib1.read = True
    user.inboxs.append(ib1)
    database.session.add(user)
    database.session.commit()

    rv = client.patch('/messages/{}/inbox/{}/unread'.format(
        user.user_login, ib1.inbox_id))
    assert rv.status_code == 204
    assert not Inbox.query.filter_by(inbox_id=ib1.inbox_id).first().read
Exemple #10
0
def test_sent_get_limit(client, database):
    user = User('test')
    sn1 = Sent('Ho', 'Ho ho ho', 'testx;testy')
    user.sents.append(sn1)
    sn2 = Sent('XO', 'Xo ox xo', 'test1;test4')
    user.sents.append(sn2)
    sn3 = Sent('Lo', 'Lo lo lo', 'testw;testz')
    user.sents.append(sn3)
    database.session.add(user)
    database.session.commit()

    rv = client.get('/messages/{}/sent?limit=1'.format(user.user_login))
    json = rv.get_json()
    assert rv.status_code == 200
    assert json['total'] == 3
    assert json['data'][0] == get_sent_ideal(user, sn1)
Exemple #11
0
def test_inbox_get_limit(client, database):
    user = User('test')
    ib1 = Inbox('Subj1', 'Body this body 1', 'test', 'testx;testy;testz')
    user.inboxs.append(ib1)
    ib2 = Inbox('Subj2', 'Body this body 2', 'test', 'testa;testb')
    user.inboxs.append(ib2)
    ib3 = Inbox('Subj3', 'Body this body 3', 'test', 'testxx;testyy')
    user.inboxs.append(ib3)
    database.session.add(user)
    database.session.commit()

    rv = client.get('/messages/{}/inbox?limit=1'.format(user.user_login))
    json = rv.get_json()
    assert rv.status_code == 200
    assert json['total'] == 3 and len(json['data']) == 1
    assert json['data'][0] == get_inbox_ideal(user, ib1)
Exemple #12
0
def test_sent_message_get(client, database):
    user = User('test')
    sn1 = Sent('This is s', 'THis is body', 'test3;testy')
    user.sents.append(sn1)
    database.session.add(user)
    database.session.commit()

    rv = client.get('/messages/{}/sent/{}'.format(user.user_login,
                                                  sn1.sent_id))
    assert rv.status_code == 200
    assert rv.get_json() == {
        str(sn1.sent_id): {
            'subject': sn1.subject,
            'body': sn1.body,
            'from_user': user.user_login,
            'to_users': sn1.to_users
        }
    }