Beispiel #1
0
def test_unauth_owner():
    'error case test'
    reset_workspace()

    user1 = reg_user1()
    user2 = reg_user2()

    channel1 = create_ch1(user1)

    invite_to_channel(user1, user2, channel1)
    msg1 = send_msg1(user1, channel1)

    data = json.dumps({
        'token': user1['token'],
        'message_id': msg1['message_id'],
    }).encode('utf-8')

    urllib.request.urlopen(
        urllib.request.Request(f"{BASE_URL}/message/pin",
                               data=data,
                               headers={'Content-Type': 'application/json'}))

    data1 = json.dumps({
        'token': user2['token'],
        'message_id': 1,
    }).encode('utf-8')

    with pytest.raises(HTTPError):
        urllib.request.urlopen(
            urllib.request.Request(
                f"{BASE_URL}/message/unpin",
                data=data1,
                headers={'Content-Type': 'application/json'}))
def test_react2():
    '''
    Test another user in a channel attempting to react to another person message
    '''
    reset_workspace()

    user1 = reg_user1()
    user2 = reg_user2()
    channel1 = create_ch1(user1)
    invite_to_channel(user1, user2, channel1)
    msg1 = send_msg1(user1, channel1)

    data = json.dumps({
        'token': user2['token'],
        'message_id': msg1['message_id'],
        'react_id': 1
    }).encode('utf-8')

    req = urllib.request.urlopen(
        urllib.request.Request(f"{BASE_URL}/message/react",
                               data=data,
                               headers={'Content-Type': 'application/json'}))

    payload = json.load(req)

    assert payload == {}
def test_remove2():
    '''
    The admin of a channel attempting to remove another users message
    '''
    reset_workspace()

    user1 = reg_user1()
    user2 = reg_user2()
    channel1 = create_ch1(user1)
    invite_to_channel(user1, user2, channel1)
    msg1 = send_msg1(user2, channel1)

    data = json.dumps({
        'token': user1['token'],
        'message_id': msg1['message_id']
    }).encode('utf-8')

    req = urllib.request.Request(f"{BASE_URL}/message/remove",
                                 data=data,
                                 headers={'Content-Type': 'application/json'})
    req.get_method = lambda: 'DELETE'
    response = json.load(urllib.request.urlopen(req))

    assert response == {}
def test_send2():
    '''
    Test valid use of message_send
    '''
    reset_workspace()

    user1 = reg_user1()
    user2 = reg_user2()
    ch1 = create_ch1(user1)

    invite_to_channel(user1, user2, ch1)

    data = json.dumps({
        'token': user2['token'],
        'channel_id': ch1['channel_id'],
        'message': 'testing'
    }).encode('utf-8')
    req = urllib.request.urlopen(
        urllib.request.Request(f"{BASE_URL}/message/send",
                               data=data,
                               headers={'Content-Type': 'application/json'}))
    payload = json.load(req)

    assert payload['message_id'] == 1