def registration_worker(self, from_name, ip, port, ret_num): try: # Postcondition: number must be globally registered and set up. number = self.ic.register_subscriber(imsi=from_name)['number'] subscriber.create_subscriber(from_name, number, ip, port) self.fs_ic.send_to_number( number, ret_num, gt("Your number is %(number)s.") % {'number': number}) reason = 'Provisioned user %s number %s' % (from_name, number) events.create_provision_event(from_name, reason) except Exception as e: self.fs_ic.send_to_imsi(from_name, ip, port, ret_num, gt("Failed to register your handset.")) logger.error("Failed to provision %s: %s" % (from_name, traceback.format_exc(e)))
def setUpClass(cls): # Monkeypatch Subscriber so sub balance lookups succeed. cls.original_subscriber = utilities.subscriber cls.mock_subscriber = mocks.MockSubscriber() utilities.subscriber = cls.mock_subscriber subscriber.create_subscriber('IMSI901550000000084', '5551234') subscriber.create_subscriber('IMSI901550000000082', '5551235') # Connect to the GPRSDB and EventStore. cls.gprs_db = gprs_database.GPRSDB() cls.event_store = events.EventStore() # Add some records to the GPRSDB. The method we're testing should # extract these records and create events in the EventStore. cls.now = time.time() records = [ (psycopg2.TimestampFromTicks(cls.now - 120), 'IMSI901550000000084', '192.168.99.1', 50, 80, 50, 80), (psycopg2.TimestampFromTicks(cls.now - 60), 'IMSI901550000000084', '192.168.99.1', 50, 80, 0, 0), (psycopg2.TimestampFromTicks(cls.now - 30), 'IMSI901550000000084', '192.168.99.1', 300, 500, 250, 420), (psycopg2.TimestampFromTicks(cls.now - 10), 'IMSI901550000000084', '192.168.99.1', 700, 600, 400, 100), (psycopg2.TimestampFromTicks(cls.now - 5), 'IMSI901550000000084', '192.168.99.1', 750, 625, 50, 25), # Create events for a different IMSI. (psycopg2.TimestampFromTicks(cls.now - 60), 'IMSI901550000000082', '192.168.99.2', 50, 80, 0, 0), (psycopg2.TimestampFromTicks(cls.now - 10), 'IMSI901550000000082', '192.168.99.2', 400, 300, 350, 220), (psycopg2.TimestampFromTicks(cls.now - 5), 'IMSI901550000000082', '192.168.99.2', 450, 325, 50, 25), ] schema = ('record_timestamp, imsi, ipaddr, uploaded_bytes,' ' downloaded_bytes, uploaded_bytes_delta,' ' downloaded_bytes_delta') connection = psycopg2.connect(host='localhost', database='endaga', user=PG_USER, password=PG_PASSWORD) with connection.cursor() as cursor: for record in records: values = "%s, '%s', '%s', %s, %s, %s, %s" % record command = 'insert into gprs_records (%s) values(%s)' % (schema, values) cursor.execute(command) connection.commit()
def test_get_one_subscriber(self): """ We can get a list of specific subscribers. """ imsi0 = 'IMSI90155%010d' % (randrange(100, 1e10)) imsi1 = 'IMSI90156%010d' % (randrange(100, 1e10)) imsi2 = 'IMSI90157%010d' % (randrange(100, 1e10)) subscriber.create_subscriber(imsi0, '') # MSISDN unused subscriber.create_subscriber(imsi1, '') # MSISDN unused subscriber.create_subscriber(imsi2, '') # MSISDN unused subs = subscriber.get_subscriber_states([imsi0, imsi1]) self.assertEqual(len(subs), 2) self.assertTrue(imsi0 in subs) self.assertTrue(imsi1 in subs)
def test_get_all_subscribers(self): """ We can get a list of all registered subscribers. """ imsi0 = 'IMSI90155%010d' % (randrange(100, 1e10)) imsi1 = 'IMSI90156%010d' % (randrange(100, 1e10)) imsi2 = 'IMSI90157%010d' % (randrange(100, 1e10)) subscriber.create_subscriber(imsi0, '') # MSISDN unused subscriber.create_subscriber(imsi1, '') # MSISDN unused subscriber.create_subscriber(imsi2, '') # MSISDN unused subs = subscriber.get_subscriber_states() expected = { imsi0: '', # we don't get the MSISDN back imsi1: '', imsi2: '', self.TEST_IMSI: '', } self.assertEqual(len(expected), len(subs)) for imsi in list(subs.keys()): self.assertTrue(imsi in expected)
def test_add_existing_sub(self): """ Adding an existing IMSI should raise ValueError. """ with self.assertRaises(ValueError): subscriber.create_subscriber(self.TEST_IMSI, self.TEST_MSISDN)
def setUpClass(cls): subscriber.create_subscriber(cls.TEST_IMSI, cls.TEST_MSISDN)