def tearDown(self): for s in self.sub_section: # ignore SubscriberNotFound try: subscriber.delete_subscriber(s) except SubscriberNotFound: pass
def tearDownClass(cls): # Repair the monkeypatch. utilities.subscriber = cls.original_subscriber subscriber.delete_subscriber('IMSI901550000000084') subscriber.delete_subscriber('IMSI901550000000082') # Clear the GPRSDB. cls.gprs_db.empty()
def tearDownClass(cls): # Terminate the mock API process. core.tests.mock_api.APP_BAD_NUMBER_ALLOCATION.stop() # Restore the old registry endpoint. CONF['registry'] = cls.old_registry # Deregister the user. subscriber.delete_subscriber(cls.fp1.user)
def test_01_not_provisioned(self): """Should get a "not-provisioned" message before registration.""" # First delete the sub. subscriber.delete_subscriber(self.fp1.user) # Then try a credit check. self.fp1.sendSMS(CONF['credit_check_number'], "not provisioned") sleep_until(lambda p=self.fp1: p.sms_received, FS_TIMEOUT) self.assertEqual(self.fp1.content, "Your phone is not provisioned.")
def tearDownClass(cls): # Terminate the mock API process. core.tests.mock_api.APP_NOMINAL.stop() # Restore the old registry endpoint. CONF['registry'] = cls.old_registry # Deregister the users. for phone in [cls.fp1, cls.fp2]: subscriber.delete_subscriber(phone.user)
def tearDownClass(cls): # Terminate the mock API process. core.tests.mock_api.APP_BAD_REGISTRATION.stop() # Restore the old registry endpoint. CONF['registry'] = cls.old_registry # Deregister the user. subscriber.delete_subscriber(cls.fp1.user) # Note: Only in the last test case do we tear down the reactor. cls.fp1.stop()
def test_02_provisioning(self): """We can text 101 to register.""" # First delete the sub. subscriber.delete_subscriber(self.fp1.user) # Then try to register. self.fp1.sendSMS("101", "register me!") sleep_until(lambda: self.fp1.sms_received, FEDERER_TIMEOUT) self.assertEqual(self.fp1.content[:14], "Your number is") self.fp1.number = self.fp1.content[-12:-1] self.assertEqual(len(self.fp1.number), 11) self.assertEqual( 1, len(subscriber.get_subscribers(imsi=self.fp1.user)))
def POST(self, command): """Handles certain POST commands.""" # Always send back these headers. headers = {'Content-type': 'text/plain'} # Validate the exact endpoint. valid_post_commands = ('deactivate_number', 'deactivate_subscriber') if command not in valid_post_commands: return web.NotFound() # Get the posted data and validate. There should be a 'jwt' key with # signed data. That dict should contain a 'number' key -- the one we # want to deactivate. data = web.input() jwt = data.get('jwt', None) if not jwt: return web.BadRequest() serializer = itsdangerous.JSONWebSignatureSerializer( self.conf['bts_secret']) try: jwt = serializer.loads(jwt) except itsdangerous.BadSignature: return web.BadRequest() if command == 'deactivate_number': if 'number' not in jwt: return web.BadRequest() # The params validated, deactivate the number. ValueError is # raised if this is the subscriber's last number. # The number should correspond to an IMSI or give a 404 try: imsi = subscriber.get_imsi_from_number(jwt['number']) subscriber.delete_number(imsi, jwt['number']) except SubscriberNotFound: return web.NotFound() except ValueError: return web.BadRequest() return web.ok(None, headers) elif command == 'deactivate_subscriber': if 'imsi' not in jwt: return web.BadRequest() # The number should correspond to an IMSI. try: subscriber.delete_subscriber(jwt['imsi']) except SubscriberNotFound: return web.NotFound() return web.ok(None, headers)
def setUpClass(cls): # Mock the Endaga API endpoint in a new process. cls.webserver = Thread( target=core.tests.mock_api.APP_BAD_REGISTRATION.run) # This is a kludge -- web.py is strict on taking the port from argv. sys.argv = ['8080'] cls.webserver.setDaemon(True) cls.webserver.start() # Wait for the server to start. sleep_until(cls.webserver.is_alive, FEDERER_TIMEOUT) # Set the API endpoint system wide. cls.old_registry = CONF['registry'] CONF['registry'] = 'http://127.0.0.1:8080' # Setup a FakePhone. cls.fp1 = fake_phone.FakePhone( "IMSI901559000000002", 5069, lambda to, fromm: call_handler(cls.fp1), lambda to, fromm, content: sms_handler(cls.fp1, content)) cls.fp1.start() # Make sure the SR is starting afresh. subscriber.delete_subscriber(cls.fp1.user)
def setUpClass(cls): # Mock the Endaga API endpoint in a new process. cls.webserver = Thread( target=core.tests.mock_api.APP_NOMINAL.run) # This is a kludge -- web.py is strict on taking the port from argv. sys.argv = ['8080'] cls.webserver.setDaemon(True) cls.webserver.start() # Wait for the server to start. sleep_until(cls.webserver.is_alive, FEDERER_TIMEOUT) # Set the API endpoint system wide. cls.old_registry = CONF['registry'] CONF['registry'] = 'http://127.0.0.1:8080' # Setup two FakePhones. cls.fp1 = fake_phone.FakePhone( "IMSI901559000000002", 5066, lambda to, fromm: call_handler(cls.fp1), lambda to, fromm, content: sms_handler(cls.fp1, content)) cls.fp2 = fake_phone.FakePhone( "IMSI901559000000003", 5067, lambda to, fromm: call_handler(cls.fp2), lambda to, fromm, content: sms_handler(cls.fp2, content)) for phone in [cls.fp1, cls.fp2]: phone.sms_received = False phone.content = '' phone.credits = '' phone.number = None cls.fp1.start() cls.fp2.start() # Make sure the SR is starting afresh. for phone in [cls.fp1, cls.fp2]: subscriber.delete_subscriber(phone.user) # Register each phone by texting 101. for phone in [cls.fp1, cls.fp2]: phone.sms_received = False phone.sendSMS("101", "register me!") sleep_until(lambda: phone.sms_received, FEDERER_TIMEOUT) phone.number = phone.content[-12:-1]