def test_adjusted_currency_code(self): new_currency_code = 'IDR' self.user_profile.network.subscriber_currency = new_currency_code self.user_profile.network.save() status = {} checkin_response = checkin.CheckinResponder(self.bts).process(status) self.assertEqual(new_currency_code, checkin_response['config']['endaga']['currency_code'])
def test_adjusted_number_country(self): """We can change the number country and send it to the BTS.""" new_number_country = 'CL' self.user_profile.network.number_country = new_number_country self.user_profile.network.save() status = {} checkin_response = checkin.CheckinResponder(self.bts).process(status) self.assertEqual( new_number_country, checkin_response['config']['endaga']['number_country'])
def test_bts_config_precedence(self): openbts_conf = self.checkin_response['config']['openbts'] self.assertEqual('901', str(openbts_conf['GSM.Identity.MCC'])) # Add a BTS-specific ConfigurationKey to change the value ck = models.ConfigurationKey.objects.get(network=self.user_profile.network, key='GSM.Identity.MCC') ck.pk = None # clone new object ck.bts = self.bts ck.value = "123" ck.save() status = {} checkin_response = checkin.CheckinResponder(self.bts).process(status) openbts_conf = checkin_response['config']['openbts'] self.assertEqual('123', str(openbts_conf['GSM.Identity.MCC'])) # Make sure other BTS uses network config checkin_response = checkin.CheckinResponder(self.bts2).process(status) openbts_conf = checkin_response['config']['openbts'] self.assertEqual('901', str(openbts_conf['GSM.Identity.MCC']))
def post(self, request): """Handles POST requests.""" try: bts_uuid, bts_status = self._process_post_data(request) except HTTP_415_Error as e: return Response(str(e), status=status.HTTP_415_UNSUPPORTED_MEDIA_TYPE) except HTTP_422_Error as e: return Response(str(e), status=status.HTTP_422_UNPROCESSABLE_ENTITY) except (ValueError, KeyError): return Response("Invalid/missing checkin parameters.", status=status.HTTP_400_BAD_REQUEST) # See if this BTS has been deregistered. try: dbts = models.DeregisteredBTS.objects.get(uuid=bts_uuid) resp = { 'status': 'deregistered', } dbts.delete() return Response({'response': resp}, status=status.HTTP_200_OK) except models.DeregisteredBTS.DoesNotExist: pass # The BTS isn't deregistered, continue with the checkin as normal. network = get_network_from_user(request.user) try: bts = models.BTS.objects.get(uuid=bts_uuid, network=network) except models.BTS.DoesNotExist: return Response("Incorrect auth for BTS.", status=status.HTTP_403_FORBIDDEN) try: resp = checkin.CheckinResponder(bts).process(bts_status) except Exception as e: print "Error handling checkin (BTS %s): %s" % (bts.uuid, e) print "BTS status: %s" % bts_status raise checkin_resp = Response({'response': resp}, status=status.HTTP_200_OK) def gzip_response_callback(response): if len(response.content) < MIN_COMPRESSIBLE_RESPONSE_SZ: return response gzipped_resp = gzip_middleware.process_response(request, response) return gzipped_resp checkin_resp.add_post_render_callback(gzip_response_callback) return checkin_resp
def setUpClass(cls): """Using setUpClass so we don't create duplicate objects.""" cls.user = models.User(username="******", email="*****@*****.**") cls.user.save() cls.user_profile = models.UserProfile.objects.get(user=cls.user) # mock out notifications' celery cls.old_celery_app = notifications.celery_app notifications.celery_app = mock.MagicMock() cls.bts = models.BTS(uuid="234123", nickname="test-bts-name", inbound_url="http://localhost/334455/test", network=cls.user_profile.network) cls.bts.save() cls.bts2 = models.BTS(uuid="b234123b", nickname="test-bts2-name", inbound_url="http://localhost/33445566/test", network=cls.user_profile.network) cls.bts2.save() # Set some network autoupgrade preferences. cls.user_profile.network.autoupgrade_enabled = True cls.user_profile.network.autoupgrade_channel = 'beta' cls.user_profile.network.autoupgrade_in_window = True cls.user_profile.network.autoupgrade_window_start = '12:34:56' cls.user_profile.network.save() # Create two client releases. feb3 = datetime(year=2020, month=2, day=3, hour=21, tzinfo=pytz.utc) cls.stable_release = models.ClientRelease(date=feb3, version='1.2.34', channel='stable') cls.stable_release.save() aug10 = datetime(year=2020, month=8, day=10, hour=13, tzinfo=pytz.utc) cls.beta_release = models.ClientRelease(date=aug10, version='5.6.78', channel='beta') cls.beta_release.save() # Generate a checkin response which will be evaluated in the tests. status = {} cls.checkin_response = checkin.CheckinResponder( cls.bts).process(status) cls.prices = cls.checkin_response['config']['prices']