Ejemplo n.º 1
0
def test_backend_route():
    router = MockRouter()
    backend = MachBackend(name="mach", router=router, **basic_conf)
    router.start()
    Connection.objects.all().delete()
    conn = Connection.objects.create(backend=backend.model,
                                     identity='1112229999')
    message = IncomingMessage(conn, 'Hi', datetime.datetime.now())
    assert_true(backend.route(message), True)
Ejemplo n.º 2
0
def test_good_message():
    """ Make sure backend creates IncomingMessage properly """
    backend = MachBackend(name="mach", router=None, **basic_conf)
    data = {'snr': '1112229999', 'msg': 'Hi'}
    message = backend.message(data)
    assert_true(isinstance(message, IncomingMessage))
    assert_true(isinstance(message.connection, Connection))
    assert_equals(message.connection.identity, data['snr'])
    assert_equals(message.text, data['msg'])
Ejemplo n.º 3
0
def test_long_ascii_message():
    """ ASCII messages over 160 characters should have a split parameter """
    backend = MachBackend(name="mach", router=None, **basic_conf)
    bk = Backend.objects.create(name='long-ascii')
    connection = Connection.objects.create(identity='1112229999', backend=bk)
    text = get_random_string(200)
    message = OutgoingMessage(connection, text)
    data = backend.prepare_message(message)
    assert_equals(data['split'], 2)
Ejemplo n.º 4
0
def test_long_unicode_message():
    """ Unicode messages over 70 characters should have a split parameter """
    backend = MachBackend(name="mach", router=None, **basic_conf)
    bk = Backend.objects.create(name='long-unicode')
    connection = Connection.objects.create(identity='1112229999', backend=bk)
    text = get_random_string(200, choices=UNICODE_CHARS)
    message = OutgoingMessage(connection, text)
    data = backend.prepare_message(message)
    assert_equals(data['split'], 3)
Ejemplo n.º 5
0
def test_backend_route():
    router = MockRouter()
    backend = MachBackend(name="mach", router=router, **basic_conf)
    router.start()
    Connection.objects.all().delete()
    conn = Connection.objects.create(backend=backend.model,
                                     identity='1112229999')
    message = IncomingMessage(conn, 'Hi', datetime.datetime.now())
    assert_true(backend.route(message), True)
Ejemplo n.º 6
0
def test_good_message():
    """ Make sure backend creates IncomingMessage properly """
    backend = MachBackend(name="mach", router=None, **basic_conf)
    data = {'snr': '1112229999', 'msg': 'Hi'}
    message = backend.message(data)
    assert_true(isinstance(message, IncomingMessage))
    assert_true(isinstance(message.connection, Connection))
    assert_equals(message.connection.identity, data['snr'])
    assert_equals(message.text, data['msg'])
Ejemplo n.º 7
0
def test_long_unicode_message():
    """ Unicode messages over 70 characters should have a split parameter """
    backend = MachBackend(name="mach", router=None, **basic_conf)
    bk = Backend.objects.create(name='long-unicode')
    connection = Connection.objects.create(identity='1112229999', backend=bk)
    text = get_random_string(200, choices=UNICODE_CHARS)
    message = OutgoingMessage(connection, text)
    data = backend.prepare_message(message)
    assert_equals(data['split'], 3)
Ejemplo n.º 8
0
def test_long_ascii_message():
    """ ASCII messages over 160 characters should have a split parameter """
    backend = MachBackend(name="mach", router=None, **basic_conf)
    bk = Backend.objects.create(name='long-ascii')
    connection = Connection.objects.create(identity='1112229999', backend=bk)
    text = get_random_string(200)
    message = OutgoingMessage(connection, text)
    data = backend.prepare_message(message)
    assert_equals(data['split'], 2)
Ejemplo n.º 9
0
def test_outgoing_unicode_characters():
    """ Outgoing unicode characters need to be UCS/UTF-16 encoded """
    backend = MachBackend(name="mach", router=None, **basic_conf)
    bk = Backend.objects.create(name='test')
    connection = Connection.objects.create(identity='1112229999', backend=bk)
    text = random_unicode_string(20)
    message = OutgoingMessage(connection, text)
    data = backend.prepare_message(message)
    assert_equals(data['msg'].decode(MachBackend.encoding), text)
    assert_true(data['encoding'], 'ucs')
Ejemplo n.º 10
0
def test_outgoing_unicode_characters():
    """ Outgoing unicode characters need to be UCS/UTF-16 encoded """
    backend = MachBackend(name="mach", router=None, **basic_conf)
    bk = Backend.objects.create(name='test')
    connection = Connection.objects.create(identity='1112229999', backend=bk)
    text = random_unicode_string(20)
    message = OutgoingMessage(connection, text)
    data = backend.prepare_message(message)
    assert_equals(data['msg'].decode(MachBackend.encoding), text)
    assert_true(data['encoding'], 'ucs')
Ejemplo n.º 11
0
def test_incoming_unicode_characters():
    backend = MachBackend(name="mach", router=None, **basic_conf)
    text = random_unicode_string(20)
    data = {'snr': '1112229999', 'msg': text}
    message = backend.message(data)
    assert_equals(text, message.text)
Ejemplo n.º 12
0
def test_bad_message():
    """ Don't die if POSTed data doesn't contain the necessary items """
    backend = MachBackend(name="mach", router=None, **basic_conf)
    data = {'foo': 'moo'}
    message = backend.message(data)
    assert_equals(message, None)
Ejemplo n.º 13
0
def test_incoming_unicode_characters():
    backend = MachBackend(name="mach", router=None, **basic_conf)
    text = random_unicode_string(20)
    data = {'snr': '1112229999', 'msg': text}
    message = backend.message(data)
    assert_equals(text, message.text)
Ejemplo n.º 14
0
def test_bad_message():
    """ Don't die if POSTed data doesn't contain the necessary items """
    backend = MachBackend(name="mach", router=None, **basic_conf)
    data = {'foo': 'moo'}
    message = backend.message(data)
    assert_equals(message, None)