def test_receiving_messages_manually(mock_IMAP, mock_SMTP): """Test receiving a simple text message""" client = shawk.Client(username, password) client.setup_inbox(password) imap_instance = client.imap spoof_contact = client.add_contact(number=1234567890, carrier='Verizon', name='Spoof') spoof_phone = SpoofPhone(imap_instance, spoof_contact) message_time = datetime.utcnow() spoof_phone.send('Testing', message_time) client.refresh() assert(imap_instance.copy.call_count == 1) assert(str(client.inbox) == str([shawk.Message('Testing', spoof_phone.sender, message_time)]))
def test_receiving_emoji_message_demojized(mock_IMAP, mock_SMTP): """Test receiving a message with emoji translated back to text""" client = shawk.Client(username, password) client.setup_inbox(password) spoof_contact = client.add_contact(number=1234567890, carrier='Verizon', name='Spoof') spoof_phone = SpoofPhone(client.imap, spoof_contact) message_time = datetime.utcnow() original = 'Testing :thumbs_up_sign:' emojized = emoji.emojize(original, use_aliases=True) spoof_phone.send(original, time=message_time, emojize=True) client.refresh() assert(client.imap.copy.call_count == 1) assert(str(client.inbox) == str([shawk.Message(original, spoof_phone.sender, message_time)]))
def test_receiving_messages_automatically(mock_IMAP, mock_SMTP): """Test receiving a simple text message automatically""" client = shawk.Client(username, password) client.setup_inbox(password, auto=True) imap_instance = client.imap spoof_contact = client.add_contact(number=1234567890, carrier='Verizon', name='Spoof') spoof_phone = SpoofPhone(imap_instance, spoof_contact) message_time = datetime.utcnow() spoof_phone.send('Testing', message_time) # TODO: How best should we wait for this? sleep(max(3, 2 * client.refresh_interval)) assert(imap_instance.copy.call_count == 1) assert(str(client.inbox) == str([shawk.Message('Testing', spoof_phone.sender, message_time)]))
def test_adding_contact_handler_via_function(mock_IMAP, mock_SMTP): """Test adding a contact handler via function""" client = shawk.Client(username, password) client.setup_inbox(password) spoof_contact = client.add_contact(number=1234567890, carrier='Verizon', name='Spoof') spoof_phone = SpoofPhone(client.imap, spoof_contact) context = {} def contact_handler(client, message): context['did_call_contact_handler'] = True client.add_contact_handler(spoof_contact, contact_handler) spoof_phone.send('Testing') client.refresh() assert(context['did_call_contact_handler'])
def test_adding_text_handler_via_decorator_with_flags(mock_IMAP, mock_SMTP): """Test adding a text handler with regex via decorator with flags""" client = shawk.Client(username, password) client.setup_inbox(password) spoof_contact = client.add_contact(number=1234567890, carrier='Verizon', name='Spoof') spoof_phone = SpoofPhone(client.imap, spoof_contact) context = {} @client.text_handler('testing', 'i') def text_handler(client, message, match, regex): context['did_call_text_handler'] = True spoof_phone.send('Testing') client.refresh() assert(context['did_call_text_handler'])
def test_adding_default_text_handler_via_function(mock_IMAP, mock_SMTP): """Test adding a default text handler and verify that it replaces the stock handler""" client = shawk.Client(username, password) client.setup_inbox(password) spoof_contact = client.add_contact(number=1234567890, carrier='Verizon', name='Spoof') spoof_phone = SpoofPhone(client.imap, spoof_contact) context = {} def default_text_handler(client, message): context['did_call_default_text_handler'] = True client.set_default_text_handler(default_text_handler) spoof_phone.send('Testing') client.refresh() assert(context['did_call_default_text_handler'])
def test_adding_default_text_handler_via_decorator(mock_IMAP, mock_SMTP): """Test adding a default text handler and verify that it replaces the stock handler""" client = shawk.Client(username, password) client.setup_inbox(password) spoof_contact = client.add_contact(number=1234567890, carrier='Verizon', name='Spoof') spoof_phone = SpoofPhone(client.imap, spoof_contact) context = {} # HACK: Ugly way to avoid closure non-local scope issues in Python 2 @client.text_handler() def decorated_default_text_handler(client, message): context['did_call_decorated_default_text_handler'] = True spoof_phone.send('Testing') client.refresh() assert(context['did_call_decorated_default_text_handler'])
def test_receiving_messages_manually(mock_IMAP, mock_SMTP): """Test receiving a simple text message""" client = shawk.Client(username, password) client.setup_inbox(password) imap_instance = client.imap spoof_contact = client.add_contact(number=1234567890, carrier='Verizon', name='Spoof') spoof_phone = SpoofPhone(imap_instance, spoof_contact) message_time = datetime.utcnow() spoof_phone.send('Testing', message_time) client.refresh() assert (imap_instance.copy.call_count == 1) assert (str(client.inbox) == str( [shawk.Message('Testing', spoof_phone.sender, message_time)]))
def test_removing_contact_handler(mock_IMAP, mock_SMTP): """Test removing a contact handler""" client = shawk.Client(username, password) client.setup_inbox(password) spoof_contact = client.add_contact(number=1234567890, carrier='Verizon', name='Spoof') spoof_phone = SpoofPhone(client.imap, spoof_contact) context = {} def contact_handler(client, message): context['did_call_text_handler'] = True client.add_contact_handler(spoof_contact, contact_handler) client.remove_text_handler(spoof_contact, contact_handler) spoof_phone.send('Testing') client.refresh() assert(not context.get('did_call_contact_handler', False))
def test_receiving_emoji_message_demojized(mock_IMAP, mock_SMTP): """Test receiving a message with emoji translated back to text""" client = shawk.Client(username, password) client.setup_inbox(password) spoof_contact = client.add_contact(number=1234567890, carrier='Verizon', name='Spoof') spoof_phone = SpoofPhone(client.imap, spoof_contact) message_time = datetime.utcnow() original = 'Testing :thumbs_up_sign:' emojized = emoji.emojize(original, use_aliases=True) spoof_phone.send(original, time=message_time, emojize=True) client.refresh() assert (client.imap.copy.call_count == 1) assert (str(client.inbox) == str( [shawk.Message(original, spoof_phone.sender, message_time)]))
def test_adding_contact_handler_via_function(mock_IMAP, mock_SMTP): """Test adding a contact handler via function""" client = shawk.Client(username, password) client.setup_inbox(password) spoof_contact = client.add_contact(number=1234567890, carrier='Verizon', name='Spoof') spoof_phone = SpoofPhone(client.imap, spoof_contact) context = {} def contact_handler(client, message): context['did_call_contact_handler'] = True client.add_contact_handler(spoof_contact, contact_handler) spoof_phone.send('Testing') client.refresh() assert (context['did_call_contact_handler'])
def test_adding_text_handler_via_decorator_with_flags(mock_IMAP, mock_SMTP): """Test adding a text handler with regex via decorator with flags""" client = shawk.Client(username, password) client.setup_inbox(password) spoof_contact = client.add_contact(number=1234567890, carrier='Verizon', name='Spoof') spoof_phone = SpoofPhone(client.imap, spoof_contact) context = {} @client.text_handler('testing', 'i') def text_handler(client, message, match, regex): context['did_call_text_handler'] = True spoof_phone.send('Testing') client.refresh() assert (context['did_call_text_handler'])
def test_adding_default_text_handler_via_function(mock_IMAP, mock_SMTP): """Test adding a default text handler and verify that it replaces the stock handler""" client = shawk.Client(username, password) client.setup_inbox(password) spoof_contact = client.add_contact(number=1234567890, carrier='Verizon', name='Spoof') spoof_phone = SpoofPhone(client.imap, spoof_contact) context = {} def default_text_handler(client, message): context['did_call_default_text_handler'] = True client.set_default_text_handler(default_text_handler) spoof_phone.send('Testing') client.refresh() assert (context['did_call_default_text_handler'])
def test_receiving_messages_automatically(mock_IMAP, mock_SMTP): """Test receiving a simple text message automatically""" client = shawk.Client(username, password) client.setup_inbox(password, auto=True) imap_instance = client.imap spoof_contact = client.add_contact(number=1234567890, carrier='Verizon', name='Spoof') spoof_phone = SpoofPhone(imap_instance, spoof_contact) message_time = datetime.utcnow() spoof_phone.send('Testing', message_time) # TODO: How best should we wait for this? sleep(max(3, 2 * client.refresh_interval)) assert (imap_instance.copy.call_count == 1) assert (str(client.inbox) == str( [shawk.Message('Testing', spoof_phone.sender, message_time)]))
def test_adding_default_text_handler_via_decorator(mock_IMAP, mock_SMTP): """Test adding a default text handler and verify that it replaces the stock handler""" client = shawk.Client(username, password) client.setup_inbox(password) spoof_contact = client.add_contact(number=1234567890, carrier='Verizon', name='Spoof') spoof_phone = SpoofPhone(client.imap, spoof_contact) context = { } # HACK: Ugly way to avoid closure non-local scope issues in Python 2 @client.text_handler() def decorated_default_text_handler(client, message): context['did_call_decorated_default_text_handler'] = True spoof_phone.send('Testing') client.refresh() assert (context['did_call_decorated_default_text_handler'])
def test_removing_contact_handler(mock_IMAP, mock_SMTP): """Test removing a contact handler""" client = shawk.Client(username, password) client.setup_inbox(password) spoof_contact = client.add_contact(number=1234567890, carrier='Verizon', name='Spoof') spoof_phone = SpoofPhone(client.imap, spoof_contact) context = {} def contact_handler(client, message): context['did_call_text_handler'] = True client.add_contact_handler(spoof_contact, contact_handler) client.remove_text_handler(spoof_contact, contact_handler) spoof_phone.send('Testing') client.refresh() assert (not context.get('did_call_contact_handler', False))