def test_process_from_queue_with_messages (self): ev = threading.Event() mock_Event = self.mocker.replace(ev) mock_Event () self.mocker.result (mock_Event) self.mocker.count (3) mock_Event.set() self.mocker.result (True) self.mocker.count (3) mock_Queue = self.mocker.replace('Queue') mock_Queue() self.mocker.result (True) self.mocker.count (3) self.mocker.replay () ms = MessageScheduler ({}) processor = SMSProcessor () for i in range (0, 10): processor.sendSMS (WebServiceTests.username, WebServiceTests.password, 'AccessWithPurchase', 'foo', 'bar', datetime.datetime.now()) account = Account.objects.get(name = 'AccessWithPurchase') ag = AccountGroup (account) ms.account_groups[account.id] = ag ms.enqueue_messages () retcode = ag.process_from_queue() self.assertEqual (retcode, True) self.assertEqual (ag.work.qsize (), 10)
def test_create_accountThreads (self): dummy_AccountThread = self.mocker.replace('singularmsd.AccountThread') dummy_AccountThread(ANY, ANY) self.mocker.result (dummy_AccountThread) self.mocker.count (4) dummy_AccountThread.num_threads self.mocker.result (4) self.mocker.count (4) dummy_AccountThread.start () self.mocker.result (True) self.mocker.count (4) self.mocker.replay () account = Account.objects.get(name = 'AccessWithPurchase') ag = AccountGroup (account) ag.create_accountThreads() self.assertEqual (len(ag.threads), 4)
def test_process_from_queue_with_messages(self): ev = threading.Event() mock_Event = self.mocker.replace(ev) mock_Event() self.mocker.result(mock_Event) self.mocker.count(0, 10) mock_Event.set() self.mocker.result(True) self.mocker.count(0, 10) mock_Queue = self.mocker.replace("Queue") mock_Queue() self.mocker.result(True) self.mocker.count(0, 3) self.mocker.replay() ms = MessageScheduler({}) processor = SMSProcessor() for i in range(0, 10): processor.sendSMS( AccountGroupTests.username, AccountGroupTests.password, "AccessWithPurchase", "foo", "bar", datetime.datetime.now(), ) account = Account.objects.get(name="AccessWithPurchase") ag = AccountGroup(account) ms.account_groups[account.id] = ag ms.enqueue_messages() retcode = ag.process_from_queue() self.assertEqual(retcode, True) self.assertEqual(ag.work.qsize(), 10) self.fail("Este test no funciona, hay que rehacerlo") self.mocker.verify()
def test_process_from_queue_without_messages(self): account = Account.objects.get(name="AccessWithPurchase") ag = AccountGroup(account) retcode = ag.process_from_queue() self.assertEqual(retcode, False)