Exemple #1
0
def test_get_channels(user1, channel1):
    class MockUser(object):
        def __init__(self, user_id):
            self.id = user_id

    Message.put_item(**dict(channel=channel1,
                            published_at=time.time(),
                            type="text",
                            writer=user1,
                            message="hi"))

    with AuthenticatedClient(user1) as client_sock:
        client_sock.sendobj(dict(method='get_channels'))
        response = client_sock.recvobj()
        assert response['method'] == u'get_channels'
        assert 'users' in response
        assert 'channels' in response
        channel_names = [
            channel['channel'] for channel in response['channels']
        ]
        assert channel1 in channel_names

        activated_channels = TestChatProtocol.get_activated_channels(
            MockUser(user1))
        assert set(activated_channels) == set(channel_names)
Exemple #2
0
def test_unread_specific_channel(channel1, user1, user2):
    Message.put_item(channel=channel1, type=u"text", message=u"Text Message", writer=user1, published_at=time.time())

    with AuthenticatedClient(user2) as client_sock:
        client_sock.sendobj(dict(method="unread", channel=channel1))
        response = client_sock.recvobj()
        assert response["method"] == u"unread"
        new_messages = response["messages"]
        assert len(new_messages) == 1
        assert new_messages[0]["message"] == u"Text Message"
Exemple #3
0
def pytest_runtest_teardown():
    conn = DynamoDBConnection()
    conn.delete_table(Message.get_table_name())
    conn.delete_table(ChannelJoinInfo.get_table_name())
    conn.delete_table(ChannelUsageLog.get_table_name())
    conn.delete_table(Channel.get_table_name())
    conn.delete_table(ChannelWithdrawalLog.get_table_name())

    Message.create_table()
    ChannelWithdrawalLog.create_table()
    ChannelJoinInfo.create_table()
    ChannelUsageLog.create_table()
    Channel.create_table()
Exemple #4
0
def pytest_runtest_teardown():
    conn = DynamoDBConnection()
    conn.delete_table(Message.get_table_name())
    conn.delete_table(ChannelJoinInfo.get_table_name())
    conn.delete_table(ChannelUsageLog.get_table_name())
    conn.delete_table(Channel.get_table_name())
    conn.delete_table(ChannelWithdrawalLog.get_table_name())

    Message.create_table()
    ChannelWithdrawalLog.create_table()
    ChannelJoinInfo.create_table()
    ChannelUsageLog.create_table()
    Channel.create_table()
Exemple #5
0
def test_unread_specific_channel(channel1, user1, user2):
    Message.put_item(channel=channel1,
                     type=u'text',
                     message=u'Text Message',
                     writer=user1,
                     published_at=time.time())

    with AuthenticatedClient(user2) as client_sock:
        client_sock.sendobj(dict(method='unread', channel=channel1))
        response = client_sock.recvobj()
        assert response['method'] == u'unread'
        new_messages = response['messages']
        assert len(new_messages) == 1
        assert new_messages[0]['message'] == u'Text Message'
Exemple #6
0
def test_unread_specific_channel(channel1, user1, user2):
    Message.put_item(
        channel=channel1,
        type=u'text',
        message=u'Text Message',
        writer=user1,
        published_at=time.time()
    )

    with AuthenticatedClient(user2) as client_sock:
        client_sock.sendobj(dict(method='unread', channel=channel1))
        response = client_sock.recvobj()
        assert response['method'] == u'unread'
        new_messages = response['messages']
        assert len(new_messages) == 1
        assert new_messages[0]['message'] == u'Text Message'
Exemple #7
0
def test_get_channels(user1, channel1):
    class MockUser(object):
        def __init__(self, user_id):
            self.id = user_id

    Message.put_item(**dict(channel=channel1, published_at=time.time(), type="text", writer=user1, message="hi"))

    with AuthenticatedClient(user1) as client_sock:
        client_sock.sendobj(dict(method='get_channels'))
        response = client_sock.recvobj()
        assert response['method'] == u'get_channels'
        assert 'users' in response
        assert 'channels' in response
        channel_names = [channel['channel'] for channel in response['channels']]
        assert channel1 in channel_names

        activated_channels = TestChatProtocol.get_activated_channels(MockUser(user1))
        assert set(activated_channels) == set(channel_names)
Exemple #8
0
def test_get_channels_unread_count(user1, user2, channel1):
    with AuthenticatedClient(user1) as sock1:
        sock1.sendobj(dict(method='publish', message='UnreadCountTest', type='text', channel=channel1))
        for x in xrange(10):
            time.sleep(conf['QUEUE_POLLING_INTERVAL'])
            count = Message.query(channel__eq=channel1).count()
            if count > 0:
                break
        else:
            raise ValueError('Logger seems not work')
        with AuthenticatedClient(user2) as sock2:
            sock2.sendobj(dict(method='get_channels'))
            response = sock2.recvobj()
            assert response['method'] == u'get_channels'
            channel = [channel for channel in response['channels'] if channel['channel'] == channel1][0]
            assert channel['unread_count'] == 1
Exemple #9
0
def test_get_channels_unread_count(user1, user2, channel1):
    with AuthenticatedClient(user1) as sock1:
        sock1.sendobj(
            dict(method='publish',
                 message='UnreadCountTest',
                 type='text',
                 channel=channel1))
        for x in xrange(10):
            time.sleep(conf['QUEUE_POLLING_INTERVAL'])
            count = Message.query(channel__eq=channel1).count()
            if count > 0:
                break
        else:
            raise ValueError('Logger seems not work')
        with AuthenticatedClient(user2) as sock2:
            sock2.sendobj(dict(method='get_channels'))
            response = sock2.recvobj()
            assert response['method'] == u'get_channels'
            channel = [
                channel for channel in response['channels']
                if channel['channel'] == channel1
            ][0]
            assert channel['unread_count'] == 1