def test_sub_remove(self):
        self.checkin_response['response']['subscribers'] = self.sub_section
        CheckinHandler(json.dumps(self.checkin_response))
        subs_pre = subscriber.get_subscribers()
        self.assertTrue(len(subs_pre) == 2)

        sub_section = copy.deepcopy(self.sub_section)
        del (sub_section[self.sub2])
        self.checkin_response['response']['subscribers'] = sub_section
        CheckinHandler(json.dumps(self.checkin_response))
        subs_post = subscriber.get_subscriber_states()
        self.assertTrue(len(subs_post) == 1)
 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 test_sub_add(self):
     subs_pre = subscriber.get_subscribers()
     self.checkin_response['response']['subscribers'] = self.sub_section
     CheckinHandler(json.dumps(self.checkin_response))
     subs_post = subscriber.get_subscriber_states()
     self.assertTrue(len(subs_pre) == 0)
     self.assertTrue(len(subs_post) == 2)
     for sub in self.sub_section:
         e_bal = crdt.PNCounter.from_state(
             self.sub_section[sub]['balance']).value()
         actual_bal = crdt.PNCounter.from_state(
             json.loads(subs_post[sub]['balance'])).value()
         self.assertEqual(e_bal, actual_bal)
예제 #4
0
def gather_gprs_data():
    """Gets GPRS data from openbts-python and dumps it in the GPRS DB."""
    gprs_db = gprs_database.GPRSDB()
    try:
        data = subscriber.get_gprs_usage()
    except SubscriberNotFound:
        return
    for imsi in data.keys():
        # If the IMSI is not a registered sub, ignore its data.
        if not subscriber.get_subscribers(imsi=imsi):
            continue
        # Otherwise, get the IMSI's latest record and compute the byte count
        # deltas.
        record = gprs_db.get_latest_record(imsi)
        if not record:
            # No previous records exist for this IMSI so set the old byte
            # counts to zero.
            old_up_bytes = 0
            old_down_bytes = 0
        elif record['ipaddr'] != data[imsi]['ipaddr']:
            # The ipaddr has been reset and with it, the byte count.
            old_up_bytes = 0
            old_down_bytes = 0
        elif (record['uploaded_bytes'] > data[imsi]['uploaded_bytes']
              or record['downloaded_bytes'] > data[imsi]['downloaded_bytes']):
            # The ipaddr was recently re-assigned to this IMSI and it happens
            # to match the IP we had previously.  The byte count was reset
            # during this transition.
            old_up_bytes = 0
            old_down_bytes = 0
        else:
            old_up_bytes = record['uploaded_bytes']
            old_down_bytes = record['downloaded_bytes']
        up_bytes_delta = data[imsi]['uploaded_bytes'] - old_up_bytes
        down_bytes_delta = data[imsi]['downloaded_bytes'] - old_down_bytes
        # Insert the GPRS data into the DB.
        gprs_db.add_record(imsi, data[imsi]['ipaddr'],
                           data[imsi]['uploaded_bytes'],
                           data[imsi]['downloaded_bytes'], up_bytes_delta,
                           down_bytes_delta)
 def test_blank_section(self):
     subs_pre = subscriber.get_subscribers()
     CheckinHandler(json.dumps(self.checkin_response))
     subs_post = subscriber.get_subscribers()
     self.assertTrue(len(subs_pre) == 0)
     self.assertTrue(len(subs_post) == 0)