def test_queryset(self): self.mailer.get_all_threads.return_value = [ Bunch(id='1'), Bunch(id='2'), Bunch(id='3'), ] tqs = ThreadQuerySet(model=Thread, credentials=self.credentials, mailer=self.mailer) self.assertEqual(tqs.count(), 3) self.assertEqual(tqs[1].id, '2') self.assertTrue([model._meta for model in tqs.all()])
def test_queryset_filter_Q(self): self.mailer.get_all_threads.return_value = [ Bunch(id='target1'), Bunch(id='target2'), ] tqs = ThreadQuerySet(model=Thread, credentials=self.credentials, mailer=self.mailer) query = Q(to__icontains="*****@*****.**") tqs2 = tqs.filter(query) self.assertEqual([b.id for b in tqs2.all()], ['target1', 'target2']) self.assertEqual( self.mailer.get_all_threads.call_args_list[0][1]['to'], '*****@*****.**')
def test_queryset_get(self): self.mailer.get_thread_by_id.return_value = Bunch(id='target') tqs = ThreadQuerySet(model=Thread, credentials=self.credentials, mailer=self.mailer) self.assertEqual(tqs.get(id='target').id, 'target') self.assertEqual(self.mailer.get_thread_by_id.call_args[0][1], 'target')
def test_message_with_id(self): self.mailer.get_message_by_id.return_value = Bunch(id='1') mqs = MessageQuerySet(model=Message, credentials=self.credentials, mailer=self.mailer) self.assertEqual(mqs.get(pk='1843903').pk, '1') self.assertEqual(self.mailer.get_message_by_id.call_args[0][1], '1843903')
def test_message_with_filter(self): self.mailer.get_messages_by_thread_id.return_value = [ Bunch(id='1'), ] mqs = MessageQuerySet(model=Message, credentials=self.credentials, mailer=self.mailer) self.assertEqual(mqs.filter(thread='1')[0].pk, '1') self.assertEqual(self.mailer.get_messages_by_thread_id.call_args[0][1], '1')
def test_reverse_relation_lookup(self): self.mailer.get_messages_by_thread_id.return_value = [ Bunch(id=str(n)) for n in xrange(10) ] t = Thread(id='123123') self.assertEqual(t.messages.count(), 10)