def test_enqueue_messages_with_messages_mocker (self): dummy_AccountGroup = self.mocker.replace('singularmsd.AccountGroup') dummy_AccountGroup.account.id self.mocker.result (1) self.mocker.count (6) dummy_AccountGroup(ANY) self.mocker.result (dummy_AccountGroup) self.mocker.count (6) dummy_AccountGroup.start () self.mocker.result (True) self.mocker.count (6) dummy_AccountGroup.event.set () self.mocker.result (True) self.mocker.count (20) self.mocker.replay () ms = MessageScheduler ({}) ms.create_account_groups() processor = SMSProcessor () for i in range (0, 10): processor.sendSMS (WebServiceTests.username, WebServiceTests.password, 'AccessWithPurchase', 'foo', 'bar', datetime.datetime.now()) for i in range (0, 10): processor.sendSMSToChannel (WebServiceTests.username, WebServiceTests.password, 'AccessWithPurchase', 'TestChannel', 'bar', datetime.datetime.now()) ms.enqueue_messages ()
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_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_sendSMS (self): processor = SMSProcessor () retcode = processor.sendSMS (WebServiceTests.username, WebServiceTests.password, 'AccessWithPurchase', 'foo', 'bar', datetime.datetime.now()) self.assertEqual (retcode, 3)
def test_sendSMS_no_credit (self): processor = SMSProcessor () retcode = processor.sendSMS (WebServiceTests.username, WebServiceTests.password, 'AccessNoPurchase', 'foo', 'bar', datetime.datetime.now()) self.assertEqual (retcode, Purchase.INSUFFICIENT_CREDIT)
def test_sendSMS_wrong_account (self): processor = SMSProcessor () retcode = processor.sendSMS (WebServiceTests.username, WebServiceTests.password, 'wrongAccount', 'foo', 'bar', datetime.datetime.now()) self.assertEqual (retcode, Customer.WRONG_ACCOUNT)
def test_sendSMS_wrong_password (self): processor = SMSProcessor () retcode = processor.sendSMS (WebServiceTests.wrong_username, WebServiceTests.wrong_password, 'whatever', 'foo', 'bar', datetime.datetime.now()) self.assertEqual (retcode, Customer.WRONG_USERNAME_OR_PASSWORD)