def test_invalid_argument(self):
     base = Base(FakeAccount())
     self.assertEqual(0, TestModel.get_n_rows())
     with self.assertRaises(TypeError) as cm:
         base._publish(message_id='message_id', invalid_argument='not good')
     self.assertEqual(str(cm.exception),
                      'Unexpected keyword arguments: invalid_argument')
 def test_duplicate_messages_identified(self):
     base = Base(FakeAccount())
     self.assertEqual(0, TestModel.get_n_rows())
     self.assertTrue(
         base._publish(message_id='1234',
                       stream='messages',
                       sender='fred',
                       sender_nick='freddy',
                       from_me=True,
                       timestamp='today',
                       message='hello, @jimmy',
                       likes=10,
                       liked=True))
     # Duplicate
     self.assertTrue(
         base._publish(message_id='1234',
                       stream='messages',
                       sender='fred',
                       sender_nick='freddy',
                       from_me=True,
                       timestamp='today',
                       message='hello jimmy',
                       likes=10,
                       liked=False))
     # See, we get only one row in the table.
     self.assertEqual(1, TestModel.get_n_rows())
     # The first published message wins.
     row = TestModel.get_row(0)
     self.assertEqual(row[SCHEMA.INDICES['message']], 'hello, @jimmy')
 def test_invalid_arguments(self):
     # All invalid arguments are mentioned in the exception message.
     base = Base(FakeAccount())
     self.assertEqual(0, TestModel.get_n_rows())
     with self.assertRaises(TypeError) as cm:
         base._publish(message_id='p.middy', bad='no', wrong='yes')
     self.assertEqual(str(cm.exception),
                      'Unexpected keyword arguments: bad, wrong')
 def test_dec_cell(self):
     base = Base(FakeAccount())
     self.assertEqual(0, TestModel.get_n_rows())
     self.assertTrue(base._publish(message_id='1234', likes=10, liked=True))
     base._dec_cell('1234', 'likes')
     row = TestModel.get_row(0)
     self.assertEqual(list(row), [
         'base', 88, '1234', '', '', '', '', False, '', '', '', '', 9, True,
         '', '', '', '', '', '', '', 0.0, 0.0
     ])
Exemple #5
0
 def test_publish_all(self, notify):
     Base._do_notify = lambda protocol, stream: True
     base = Base(FakeAccount())
     base._publish(
         message='notify!',
         message_id='1234',
         sender='Benjamin',
         timestamp=YESTERDAY,
         )
     notify.assert_called_once_with('Benjamin', 'notify!', '')
Exemple #6
0
 def test_publish_no_html(self, notify):
     Base._do_notify = lambda protocol, stream: True
     base = Base(FakeAccount())
     base._publish(
         message='http://example.com!',
         message_id='1234',
         sender='Benjamin',
         timestamp=RIGHT_NOW,
         )
     notify.assert_called_once_with('Benjamin', 'http://example.com!', '')
Exemple #7
0
 def test_publish_no_stale(self, notify):
     Base._do_notify = lambda protocol, stream: True
     base = Base(FakeAccount())
     base._publish(
         message='http://example.com!',
         message_id='1234',
         sender='Benjamin',
         timestamp=LAST_WEEK,
         )
     self.assertEqual(notify.call_count, 0)
Exemple #8
0
 def test_publish_mention_none(self, notify):
     Base._do_notify = lambda protocol, stream: False
     base = Base(FakeAccount())
     base._publish(
         message='Ignore me!',
         message_id='1234',
         sender='Benjamin',
         stream='messages',
         timestamp=RIGHT_NOW,
         )
     self.assertEqual(notify.call_count, 0)
Exemple #9
0
 def test_publish_mentions_private(self, notify):
     Base._do_notify = lambda protocol, stream: stream in (
         'mentions', 'private')
     base = Base(FakeAccount())
     base._publish(
         message='This message is private!',
         message_id='1234',
         sender='Benjamin',
         stream='private',
         timestamp=RIGHT_NOW,
         )
     notify.assert_called_once_with('Benjamin', 'This message is private!', '')
Exemple #10
0
 def test_publish_mention_fail(self, notify):
     Base._do_notify = lambda protocol, stream: stream in (
         'mentions', 'private')
     base = Base(FakeAccount())
     base._publish(
         message='notify!',
         message_id='1234',
         sender='Benjamin',
         stream='messages',
         timestamp=RIGHT_NOW,
         )
     self.assertEqual(notify.call_count, 0)
Exemple #11
0
 def test_publish_avatar_cache(self, notify, gdkpixbuf, avatar):
     Base._do_notify = lambda protocol, stream: True
     base = Base(FakeAccount())
     base._publish(
         message='http://example.com!',
         message_id='1234',
         sender='Benjamin',
         timestamp=RIGHT_NOW,
         icon_uri='http://example.com/bob.jpg',
         )
     avatar.get_image.assert_called_once_with('http://example.com/bob.jpg')
     gdkpixbuf.Pixbuf.new_from_file_at_size.assert_called_once_with(
         avatar.get_image(), 48, 48)
 def test_shared_model_successfully_mocked(self):
     count = Model.get_n_rows()
     self.assertEqual(TestModel.get_n_rows(), 0)
     base = Base(FakeAccount())
     base._publish(message_id='alpha', message='a')
     base._publish(message_id='beta', message='b')
     base._publish(message_id='omega', message='c')
     self.assertEqual(Model.get_n_rows(), count)
     self.assertEqual(TestModel.get_n_rows(), 3)
 def test_duplicate_ids_not_duplicated(self):
     # When two messages are actually identical (same ids and all),
     # we need to avoid duplicating the id in the sharedmodel.
     base = Base(FakeAccount())
     self.assertEqual(0, TestModel.get_n_rows())
     self.assertTrue(
         base._publish(message_id='1234',
                       stream='messages',
                       sender='fred',
                       message='hello, @jimmy'))
     self.assertTrue(
         base._publish(message_id='1234',
                       stream='messages',
                       sender='fred',
                       message='hello, @jimmy'))
     self.assertEqual(1, TestModel.get_n_rows())
     row = TestModel.get_row(0)
     self.assertEqual(list(row), [
         'base',
         88,
         '1234',
         'messages',
         'fred',
         '',
         '',
         False,
         '',
         'hello, @jimmy',
         '',
         '',
         0,
         False,
         '',
         '',
         '',
         '',
         '',
         '',
         '',
         0.0,
         0.0,
     ])
 def test_one_message(self):
     # Test that publishing a message inserts a row into the model.
     base = Base(FakeAccount())
     self.assertEqual(0, TestModel.get_n_rows())
     self.assertTrue(
         base._publish(message_id='1234',
                       stream='messages',
                       sender='fred',
                       sender_nick='freddy',
                       from_me=True,
                       timestamp='today',
                       message='hello, @jimmy',
                       likes=10,
                       liked=True))
     self.assertEqual(1, TestModel.get_n_rows())
     row = TestModel.get_row(0)
     self.assertEqual(list(row), [
         'base',
         88,
         '1234',
         'messages',
         'fred',
         '',
         'freddy',
         True,
         'today',
         'hello, @jimmy',
         '',
         '',
         10,
         True,
         '',
         '',
         '',
         '',
         '',
         '',
         '',
         0.0,
         0.0,
     ])
Exemple #15
0
 def __init__(self, service=None, account_id=88):
     self.consumer_secret = 'secret'
     self.consumer_key = 'consume'
     self.access_token = None
     self.secret_token = None
     self.user_full_name = None
     self.user_name = None
     self.user_id = None
     self.auth = FakeAuth()
     self.login_lock = threading.Lock()
     self.id = account_id
     self.protocol = Base(self)
 def test_seen_dicts_successfully_instantiated(self):
     from friends.utils.base import _seen_ids
     from friends.utils.base import initialize_caches
     self.assertEqual(TestModel.get_n_rows(), 0)
     base = Base(FakeAccount())
     base._publish(message_id='alpha', sender='a', message='a')
     base._publish(message_id='beta', sender='a', message='a')
     base._publish(message_id='omega', sender='a', message='b')
     self.assertEqual(TestModel.get_n_rows(), 3)
     _seen_ids.clear()
     initialize_caches()
     self.assertEqual(_seen_ids, dict(
         alpha=0,
         beta=1,
         omega=2,
     ))
 def test_similar_messages_allowed(self):
     # Because both the sender and message contribute to the unique key we
     # use to identify messages, if two messages are published with
     # different senders, both are inserted into the table.
     base = Base(FakeAccount())
     self.assertEqual(0, TestModel.get_n_rows())
     # The key for this row is 'fredhellojimmy'
     self.assertTrue(
         base._publish(message_id='1234',
                       stream='messages',
                       sender='fred',
                       sender_nick='freddy',
                       from_me=True,
                       timestamp='today',
                       message='hello, @jimmy',
                       likes=10,
                       liked=True))
     self.assertEqual(1, TestModel.get_n_rows())
     # The key for this row is 'tedtholomewhellojimmy'
     self.assertTrue(
         base._publish(message_id='34567',
                       stream='messages',
                       sender='tedtholomew',
                       sender_nick='teddy',
                       from_me=False,
                       timestamp='today',
                       message='hello, @jimmy',
                       likes=10,
                       liked=True))
     # See?  Two rows in the table.
     self.assertEqual(2, TestModel.get_n_rows())
     # The first row is the message from fred.
     self.assertEqual(
         TestModel.get_row(0)[SCHEMA.INDICES['sender']], 'fred')
     # The second row is the message from tedtholomew.
     self.assertEqual(
         TestModel.get_row(1)[SCHEMA.INDICES['sender']], 'tedtholomew')
 def test_unpublish(self):
     base = Base(FakeAccount())
     self.assertEqual(0, TestModel.get_n_rows())
     self.assertTrue(
         base._publish(message_id='1234',
                       sender='fred',
                       message='hello, @jimmy'))
     self.assertTrue(
         base._publish(message_id='1234',
                       sender='fred',
                       message='hello, @jimmy'))
     self.assertTrue(
         base._publish(message_id='5678',
                       sender='fred',
                       message='hello, +jimmy'))
     self.assertEqual(2, TestModel.get_n_rows())
     base._unpublish('1234')
     self.assertEqual(1, TestModel.get_n_rows())
     base._unpublish('5678')
     self.assertEqual(0, TestModel.get_n_rows())
 def test_fetch_cell(self):
     base = Base(FakeAccount())
     self.assertEqual(0, TestModel.get_n_rows())
     self.assertTrue(base._publish(message_id='1234', likes=10, liked=True))
     self.assertEqual(base._fetch_cell('1234', 'likes'), 10)