Пример #1
0
 def setUpClass(cls):
     cls.user = models.User(username='******', email='*****@*****.**')
     cls.user.save()
     cls.user2 = models.User(username='******', email='*****@*****.**')
     cls.user2.save()
     cls.user_profile = models.UserProfile.objects.get(user=cls.user)
     cls.user_profile2 = models.UserProfile.objects.get(user=cls.user2)
     uuid = "59216199-d664-4b7a-a2db-6f26e9a3d323"
     inbound_url = "http://localhost:8090"
     name = "test-tower-user-one"
     package_versions = {'endaga_version': '00000.00003.00020'}
     cls.bts = models.BTS(uuid=uuid,
                          nickname=name,
                          inbound_url=inbound_url,
                          secret='ok',
                          network=cls.user_profile.network,
                          package_versions=json.dumps(package_versions))
     cls.bts.save()
     # Create an attached Subscriber and a UsageEvent.
     cls.sub = models.Subscriber(balance=100000,
                                 name='sub-one',
                                 imsi='IMSI999990000000555',
                                 network=cls.bts.network,
                                 bts=cls.bts)
     cls.sub.save()
     cls.event = models.UsageEvent(subscriber=cls.sub,
                                   bts=cls.bts,
                                   kind='local_sms',
                                   reason='test',
                                   date=datetime.datetime.now(pytz.utc))
     cls.event.save()
Пример #2
0
 def setUpClass(cls):
     cls.password = '******'
     cls.user = models.User(username='******', email='*****@*****.**')
     cls.user.set_password(cls.password)
     cls.user.save()
     cls.user2 = models.User(username='******', email='*****@*****.**')
     cls.user2.set_password(cls.password)
     cls.user2.save()
     cls.user_profile = models.UserProfile.objects.get(user=cls.user)
     cls.user_profile2 = models.UserProfile.objects.get(user=cls.user2)
     # Create a BTS for each user profile.
     uuid = "59216199-d664-4b7a-a2db-6f26e9a5d323"
     inbound_url = "http://localhost:8090"
     name = "test-tower-user-one"
     cls.bts = models.BTS(uuid=uuid,
                          nickname=name,
                          inbound_url=inbound_url,
                          secret='ok',
                          network=cls.user_profile.network)
     cls.bts.save()
     uuid = "1eac9487-fc7c-4674-8c38-dab66d612453"
     inbound_url = "http://localhost:8090"
     name = "test-tower-user-two"
     cls.bts2 = models.BTS(uuid=uuid,
                           nickname=name,
                           inbound_url=inbound_url,
                           network=cls.user_profile2.network)
     cls.bts2.save()
     # Create two subscribers, one for each tower, each with a number.
     cls.imsi = "IMSI999990000000555"
     cls.sub = models.Subscriber(balance=100000,
                                 name='sub-one',
                                 imsi=cls.imsi,
                                 network=cls.bts.network,
                                 bts=cls.bts)
     cls.sub.save()
     cls.number = models.Number(number='6285574719324',
                                state="inuse",
                                network=cls.user_profile.network,
                                subscriber=cls.sub,
                                kind="number.nexmo.monthly")
     cls.number.save()
     cls.imsi2 = "IMSI999990000000556"
     cls.sub2 = models.Subscriber(balance=100000,
                                  name='sub-two',
                                  imsi=cls.imsi2,
                                  network=cls.bts2.network,
                                  bts=cls.bts2)
     cls.sub2.save()
     cls.number2 = models.Number(number='6285574719443',
                                 state="inuse",
                                 network=cls.user_profile2.network,
                                 subscriber=cls.sub2,
                                 kind="number.nexmo.monthly")
     cls.number2.save()
     # Create one last number, unattached to a subscriber.
     cls.number3 = models.Number(number='5551234',
                                 state="available",
                                 kind="number.nexmo.monthly")
     cls.number3.save()
Пример #3
0
 def setUpClass(cls):
     cls.user = models.User(username='******', email='*****@*****.**')
     cls.user.save()
     cls.user2 = models.User(username='******', email='*****@*****.**')
     cls.user2.save()
     cls.user_profile = models.UserProfile.objects.get(user=cls.user)
     cls.user_profile2 = models.UserProfile.objects.get(user=cls.user2)
     # Create a BTS.
     uuid = "59216199-d664-4b7a-a2db-6f26e9a5d324"
     inbound_url = "http://localhost:8090"
     name = "test-tower-user-one"
     cls.bts = models.BTS(uuid=uuid,
                          nickname=name,
                          inbound_url=inbound_url,
                          secret='ok',
                          network=cls.user_profile.network)
     cls.bts.save()
     # Create two subscribers, one for each tower, each with a number or
     # two.
     cls.imsi = "IMSI999990000000555"
     cls.sub = models.Subscriber(balance=100000,
                                 name='sub-one',
                                 imsi=cls.imsi,
                                 network=cls.bts.network,
                                 bts=cls.bts)
     cls.sub.save()
     cls.number = models.Number(number='6285574719324',
                                state="inuse",
                                network=cls.user_profile.network,
                                subscriber=cls.sub,
                                kind="number.nexmo.monthly")
     cls.number.save()
     cls.number2 = models.Number(number='6285574719443',
                                 state="inuse",
                                 network=cls.user_profile.network,
                                 subscriber=cls.sub,
                                 kind="number.nexmo.monthly")
     cls.number2.save()
     cls.imsi2 = "IMSI999990000000556"
     cls.sub2 = models.Subscriber(balance=100000,
                                  name='sub-two',
                                  imsi=cls.imsi2,
                                  network=cls.user_profile2.network,
                                  bts=None)
     cls.sub2.save()
     cls.number3 = models.Number(number='6285574719444',
                                 state="inuse",
                                 network=cls.user_profile2.network,
                                 subscriber=cls.sub2,
                                 kind="number.nexmo.monthly")
     cls.number3.save()
     cls.pcu = models.PendingCreditUpdate(subscriber=cls.sub,
                                          amount=100,
                                          uuid='abc123')
     cls.pcu.save()
Пример #4
0
 def setUpClass(cls):
     cls.user = models.User(username='******', email='*****@*****.**')
     cls.user.save()
     cls.user2 = models.User(username='******', email='*****@*****.**')
     cls.user2.save()
     cls.user_profile = models.UserProfile.objects.get(user=cls.user)
     cls.user_profile2 = models.UserProfile.objects.get(user=cls.user2)
     # Give the users some credit so they don't try to recharge.
     cls.initial_credit = endagaweb.util.currency.dollars2mc(50)
     cls.user_profile.network.add_credit(cls.initial_credit)
     cls.user_profile2.network.add_credit(cls.initial_credit)
     # Refresh the objects so the ledger balances reload.
     cls.user_profile = models.UserProfile.objects.get(
         id=cls.user_profile.id)
     cls.user_profile2 = models.UserProfile.objects.get(
         id=cls.user_profile2.id)
     # Create a BTS for each user profile.
     uuid = "59216199-d664-4b7a-a2db-6f26e9a5e203"
     inbound_url = "http://localhost:8090"
     name = "user1_testtower"
     cls.bts = models.BTS(uuid=uuid,
                          nickname=name,
                          inbound_url=inbound_url,
                          network=cls.user_profile.network)
     cls.bts.save()
     uuid = "1eac9487-fc7c-4674-8c38-dab66d6125c4"
     inbound_url = "http://localhost:8090"
     name = "user2_testtower"
     cls.bts2 = models.BTS(uuid=uuid,
                           nickname=name,
                           inbound_url=inbound_url,
                           network=cls.user_profile2.network)
     cls.bts2.save()
     # Create two numbers to test intra-network calls.
     cls.imsi = "IMSI999990000000000"
     cls.num = 6285574719464
     cls.number = models.Number(number=cls.num,
                                state="available",
                                network=cls.user_profile.network,
                                kind="number.nexmo.monthly")
     cls.number.save()
     cls.imsi2 = "IMSI999990000000001"
     cls.num2 = 6285574719465
     cls.number2 = models.Number(number=cls.num2,
                                 state="available",
                                 network=cls.user_profile2.network,
                                 kind="number.nexmo.monthly")
     cls.number2.save()
Пример #5
0
 def setUpClass(cls):
     """Setup a User, BTS and Subscriber."""
     cls.user = models.User(username="******", email="*****@*****.**")
     cls.user.save()
     cls.user_profile = models.UserProfile.objects.get(user=cls.user)
     cls.bts = models.BTS(uuid="88332", nickname="test-bts-name",
                          inbound_url="http://localhost/88332/test",
                          network=cls.user_profile.network)
     cls.bts.save()
     cls.imsi = 'IMSI000553'
     cls.subscriber = models.Subscriber.objects.create(
         balance=20000, name='test-sub-name', imsi=cls.imsi,
         network=cls.bts.network)
     cls.subscriber.save()
     cls.incoming_event = {
         'date': '2015-03-15 13:32:17',
         'imsi': cls.imsi,
         'oldamt': 1000,
         'newamt': 1000,
         'change': 0,
         'reason': 'GPRS usage',
         'kind': 'gprs',
         'up_bytes': 120,
         'down_bytes': 430,
         'timespan': 60,
         'seq': 6,
     }
     checkin.handle_event(cls.bts, cls.incoming_event)
     cls.new_usage_event = models.UsageEvent.objects.all()[0]
Пример #6
0
    def setUpClass(cls):
        """Create a Network and BTS."""
        cls.network= models.Network.objects.create()
        cls.header = {
            'HTTP_AUTHORIZATION': 'Token %s' % cls.network.api_token
        }

        """Create a User and BTS."""
        cls.username = '******'
        cls.password = '******'
        cls.user = models.User(username=cls.username, email='*****@*****.**')
        cls.user.set_password(cls.password)
        cls.user.save()

        # mock out notifications' celery
        cls.old_celery_app = notifications.celery_app
        notifications.celery_app = mock.MagicMock()

        cls.user_profile = models.UserProfile.objects.get(user=cls.user)
        cls.uuid = "59216199-d664-4b7a-a2db-6f26e9a5d203"
        inbound_url = "http://localhost:8090"
        cls.bts = models.BTS(
            uuid=cls.uuid, nickname='test-name', inbound_url=inbound_url,
            secret=cls.uuid, network=cls.network, band='GSM900', channel=51)
        cls.bts.save()
        cls.sub = models.Subscriber(
            network=cls.network, bts=cls.bts,
            imsi='IMSI901550000000001', balance=0)
        cls.sub.save()
        cls.number = models.Number(number='5551234', state="inuse",
                                   network=cls.bts.network,
                                   kind="number.nexmo.monthly",
                                   subscriber=cls.sub)
        cls.number.save()
Пример #7
0
    def setUpClass(cls):
        """Create a User and BTS."""
        cls.username = '******'
        cls.password = '******'
        cls.user = models.User(username=cls.username, email='*****@*****.**')
        cls.user.set_password(cls.password)
        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()

        uuid1 = "59216199-d664-4b7a-a2cb-6f26e9a5d203"
        uuid2 = "0e3e8bbc-1614-11e5-9f31-0124d722f2e0"
        inbound_url = "http://localhost:8090"
        cls.bts1 = models.BTS(
            uuid=uuid1, nickname='bts1', inbound_url=inbound_url,
            secret=uuid1, network=cls.user_profile.network)
        cls.bts1.save()
        cls.bts2 = models.BTS(
            uuid=uuid2, nickname='bts2', inbound_url=inbound_url,
            secret=uuid2, network=cls.user_profile.network)
        cls.bts2.save()
        cls.sub = models.Subscriber(
            network=cls.user_profile.network, bts=cls.bts1,
            imsi='IMSI901550000000001', balance=0)
        cls.sub.save()
        cls.number = models.Number(number='5551234', state="inuse",
                                   network=cls.bts1.network,
                                   kind="number.nexmo.monthly",
                                   subscriber=cls.sub)
        cls.number.save()
Пример #8
0
 def test_register_number_on_another_users_bts(self):
     """Numbers created on one BTS can't be registered on another BTS."""
     # Create a new user and BTS.
     user_two = models.User(username="******", email="*****@*****.**")
     user_two.save()
     user_profile_two = models.UserProfile.objects.get(user=user_two)
     bts_two = models.BTS(uuid="aabb33",
                          nickname="test-bts-two",
                          inbound_url="http://localhost/inbound-test-two",
                          network=user_profile_two.network)
     bts_two.save()
     # Attach the avaiable number to the original BTS.
     self.available_number.bts = self.bts
     self.available_number.save()
     # Try to register the number to the second BTS.
     endpoint = self.endpoint + '%s/%s/?imsi=%s' % (
         bts_two.uuid, self.available_number.number, self.subscriber.imsi)
     header = {
         'HTTP_AUTHORIZATION':
         'Token %s' % self.user_profile.network.api_token
     }
     response = self.client.get(endpoint, **header)
     # This request should result in a 403 Not Authorized.  And the sub
     # should still have but one number.
     self.assertEqual(403, response.status_code)
     self.assertEqual(self.subscriber_number, self.subscriber.numbers())
     # Clean up the BTS that was created in this test.
     bts_two.delete()
Пример #9
0
 def setUpClass(cls):
     """Using setUpClass so we don't create duplicate objects."""
     # Create a user, user profile, BTS and subscriber.
     cls.user = models.User(username="******", email="*****@*****.**")
     cls.user.save()
     cls.user_profile = models.UserProfile.objects.get(user=cls.user)
     cls.bts = models.BTS(uuid="zyxw9876",
                          nickname="test-bts",
                          inbound_url="http://localhost/inbound-test",
                          network=cls.user_profile.network)
     cls.bts.save()
     cls.subscriber_imsi = 'IMSI000987123456789'
     cls.subscriber = models.Subscriber.objects.create(
         balance=1000,
         name='cam-test-name',
         imsi=cls.subscriber_imsi,
         network=cls.bts.network)
     cls.subscriber.save()
     # Register a number with this subscriber.
     cls.subscriber_number = '5559876'
     registered_number = models.Number(number=cls.subscriber_number,
                                       state='inuse',
                                       kind='number.nexmo.monthly',
                                       subscriber=cls.subscriber)
     registered_number.save()
     # Set the registration endpoint.
     cls.endpoint = '/api/v1/register/'
Пример #10
0
    def setUpClass(cls):
        cls.user = models.User(username="******", email="*****@*****.**")
        cls.password = '******'
        cls.user.set_password(cls.password)
        cls.user.save()
        cls.user_profile = models.UserProfile.objects.get(user=cls.user)

        cls.bts = models.BTS(
            uuid="12345abcd", nickname="testbts",
            inbound_url="http://localhost/test",
            network=cls.user_profile.network)
        cls.bts.save()

        cls.subscriber_imsi = 'IMSI000123'
        cls.subscriber_num = '5551234'
        cls.subscriber = models.Subscriber.objects.create(
            balance=100, name='test-name', imsi=cls.subscriber_imsi,
            network=cls.bts.network, bts=cls.bts)
        cls.subscriber.save()

        cls.number = models.Number(number=cls.subscriber_num, state="inuse",
                                   network=cls.user_profile.network,
                                   kind="number.nexmo.monthly",
                                   subscriber=cls.subscriber)
        cls.number.save()

        cls.adjust_credit_endpoint = (
            '/dashboard/subscribers/%s/adjust-credit' % cls.subscriber_imsi)
        # Drop all PCUs.
        for pcu in models.PendingCreditUpdate.objects.all():
            pcu.delete()
 def setUpClass(cls):
     """Add some test data."""
     # Setup a User and UserProfile.
     user = models.User(username="******", email="*****@*****.**")
     user.set_password("testpw")
     user.save()
     user_profile = models.UserProfile.objects.get(user=user)
     # Setup two BTS on different networks with the same user.
     cls.bts = models.BTS(uuid='59216199-d664-4b7a-a2db-6f26e9a5d204',
                          nickname='tower-nickname-100',
                          inbound_url='http://localhost:8090',
                          network=user_profile.network)
     cls.bts.save()
     # Add some TimeseriesStats.
     cls.start_date = datetime.strptime('Jul 9 2015, 8:15 AM',
                                        '%b %d %Y, %H:%M %p')
     increment = timedelta(hours=12)
     stat_values = [
         (cls.start_date + 0 * increment, 'tchf_load', 4),
         (cls.start_date + 1 * increment, 'tchf_load', 6),
         (cls.start_date + 2 * increment, 'tchf_load', 2),
         (cls.start_date + 3 * increment, 'tchf_load', 7),
         (cls.start_date + 4 * increment, 'tchf_load', 9),
     ]
     for date, key, value in stat_values:
         stat = models.TimeseriesStat(
             date=date, key=key, value=value, bts=cls.bts,
             network=user_profile.network)
         stat.save()
     # Keep references to these objects so we can destroy them later.
     cls.objects = [user, user_profile, cls.bts]
Пример #12
0
 def setUpClass(cls):
     cls.user = models.User(username="******", email="*****@*****.**")
     cls.user.save()
     cls.user_profile = models.UserProfile.objects.get(user=cls.user)
     cls.bts = models.BTS(uuid="88332", nickname="test-bts-name",
                          inbound_url="http://localhost/88332/test",
                          network=cls.user_profile.network)
     cls.bts.save()
Пример #13
0
    def setUpClass(cls):
        # Setup a UserProfile, BTS, Subscriber and Number.
        cls.user = models.User(username="******", email="*****@*****.**")
        cls.user.save()
        cls.user_profile = models.UserProfile.objects.get(user=cls.user)
        # Add some initial credit to the user profile and disable CC recharge.
        cls.credit_amount = 10 * 1e5
        cls.user_profile.network.add_credit(cls.credit_amount)
        cls.user_profile.network.autoload_enable = False
        cls.user_profile.save()

        # mock out notifications' celery
        cls.old_celery_app = notifications.celery_app
        notifications.celery_app = mock.MagicMock()

        cls.bts = models.BTS(uuid="332244abc",
                             nickname="testbts",
                             inbound_url="http://localhost/test",
                             network=cls.user_profile.network)
        cls.bts.save()
        # Mark the BTS active so that it's not in a no-data state and thus,
        # when we try to get the network's lowest tower version, this BTS will
        # be considered.  This lowest version matters when activating certain
        # billing features.
        cls.bts.mark_active()
        cls.subscriber_number = '19195550987'
        cls.subscriber = models.Subscriber.objects.create(
            balance=2 * 1e5,
            name='test-subscriber',
            imsi='IMSI000123000',
            network=cls.bts.network,
            bts=cls.bts)
        cls.subscriber.save()
        cls.number = models.Number(number=cls.subscriber_number,
                                   state="inuse",
                                   network=cls.user_profile.network,
                                   kind="number.nexmo.monthly",
                                   subscriber=cls.subscriber)
        cls.number.save()
        # Mock the Providers used by the outbound handler.
        cls.original_providers = endagaweb.views.api.SendSMS.HANDLERS
        #this is a really ugly hack to make mocks work here
        endagaweb.views.api.SendSMS.HANDLERS = {
            "number.nexmo.monthly":
            (mock.Mock(), "id", "pw", "ib_sms", "ob_sms", "ib_voice")
        }
        # Mock the tasks used by the inbound handler.
        cls.original_tasks = endagaweb.views.api.tasks
        endagaweb.views.api.tasks = mock.Mock()
        # Setup the api client, SMS endpoints and the token-based auth.
        cls.client = Client()
        cls.send_endpoint = '/api/v1/send/'
        cls.inbound_endpoint = '/api/v1/inbound/'
        cls.header = {
            'HTTP_AUTHORIZATION':
            'Token %s' % cls.user_profile.network.api_token
        }
 def setUpClass(cls):
     """Add some test data."""
     # Setup a User and UserProfile.
     user = models.User(username="******", email="*****@*****.**")
     user.set_password("testpw")
     user.save()
     user_profile = models.UserProfile.objects.get(user=user)
     # Setup two Networks.
     cls.network_a = models.Network(name='network-a')
     cls.network_a.save()
     cls.network_b = models.Network(name='network-b')
     cls.network_b.save()
     # Setup two BTS on different networks with the same user.
     bts_one = models.BTS(uuid='59216199-d664-4b7a-a2db-6f26e9a5d204',
                          nickname='tower-nickname-100',
                          inbound_url='http://localhost:8090',
                          network=cls.network_a)
     bts_one.save()
     bts_two = models.BTS(uuid='59216199-d664-4b7a-a2db-6f26e9a5d205',
                          nickname='tower-nickname-200',
                          inbound_url='http://localhost:8090',
                          network=cls.network_b)
     bts_two.save()
     # Add two Subscribers.
     subscriber_a = models.Subscriber(
         network=bts_one.network, imsi='IMSI999990000000000',
         name='subscriber a', balance=10000, state='active')
     subscriber_a.save()
     subscriber_b = models.Subscriber(
         network=bts_two.network, imsi='IMSI999990000000001',
         name='subscriber b', balance=20000, state='active')
     subscriber_b.save()
     # Add some UsageEvents for the BTS and Subscribers.
     cls.number_of_outside_sms_bts_one = 10
     cls.number_of_local_sms_bts_two = 20
     cls.number_of_outside_calls_bts_one = 30
     cls.number_of_local_calls_bts_two = 40
     cls.number_of_gprs_events_bts_one = 50
     cls.number_of_gprs_events_bts_two = 60
     _add_usage_events(subscriber_a, bts_one, 'outside_sms',
                       cls.number_of_outside_sms_bts_one)
     _add_usage_events(subscriber_b, bts_two, 'local_sms',
                       cls.number_of_local_sms_bts_two)
     _add_usage_events(subscriber_a, bts_one, 'outside_call',
                       cls.number_of_outside_calls_bts_one)
     _add_usage_events(subscriber_b, bts_two, 'local_call',
                       cls.number_of_local_calls_bts_two)
     _add_usage_events(subscriber_a, bts_one, 'gprs',
                       cls.number_of_gprs_events_bts_one)
     _add_usage_events(subscriber_b, bts_two, 'gprs',
                       cls.number_of_gprs_events_bts_two)
     # Keep references to these objects so we can destroy them later.
     # TODO(matt): also grab all the usage_events that are generated.
     cls.objects = [user, user_profile, cls.network_a, cls.network_b,
                    bts_one, bts_two, subscriber_a, subscriber_b]
Пример #15
0
    def setUpClass(cls):
        cls.username = '******'
        cls.password = '******'
        cls.user = models.User(username=cls.username, email='*****@*****.**')
        cls.user.set_password(cls.password)
        cls.user.save()
        cls.user_profile = models.UserProfile.objects.get(user=cls.user)

        cls.uuid = "59216199-d664-4b7a-a2db-6f26e9a5d208"

        # Create a test client.
        cls.client = test.Client()
Пример #16
0
 def setUpClass(cls):
     """Setup some basic objects."""
     cls.user = models.User(username="******", email="*****@*****.**")
     cls.user.save()
     cls.user_profile = models.UserProfile.objects.get(user=cls.user)
     cls.bts = models.BTS(uuid="331111", nickname="test-bts-name",
                          inbound_url="http://localhost/331111/test",
                          network=cls.user_profile.network)
     cls.bts.save()
     cls.subscriber_imsi = 'IMSI000456'
     cls.subscriber = models.Subscriber.objects.create(
         balance=10000, name='test-sub-name', imsi=cls.subscriber_imsi,
         network=cls.bts.network)
     cls.subscriber.save()
Пример #17
0
 def setUpClass(cls):
     # Setup a Network by way of User -> UserProfile post-create hooks.
     cls.user = models.User(username="******", email="*****@*****.**")
     cls.user.set_password("test")
     cls.user.save()
     cls.user_profile = models.UserProfile.objects.get(user=cls.user)
     cls.network = cls.user_profile.network
     cls.bts = models.BTS(uuid="ddgghh3322", nickname="test-bts",
                          inbound_url="http://localhost/test",
                          network=cls.user_profile.network)
     cls.bts.save()
     # Mock the network.get_lowest_tower_version method so that it returns a
     # version where BillingTiers are supported.  Without this, the lowest
     # tower version will be None and all prices will default to Tier A.
     cls.original_version_lookup = cls.network.get_lowest_tower_version
     cls.network.get_lowest_tower_version = lambda: '0.1'
 def setUpClass(cls):
     cls.username = '******'
     cls.password = '******'
     cls.user = models.User(username=cls.username, email='*****@*****.**')
     cls.user.set_password(cls.password)
     cls.user.save()
     cls.user_profile = models.UserProfile.objects.get(user=cls.user)
     cls.uuid = "59216199-d664-4b7a-a2db-6f26e9a5d208"
     inbound_url = "http://localhost:8090"
     cls.bts = models.BTS(
         uuid=cls.uuid, nickname='test-name', inbound_url=inbound_url,
         network=cls.user_profile.network)
     cls.bts.save()
     cls.primary_network = cls.user_profile.network
     cls.secondary_network = models.Network.objects.create()
     # Create a test client.
     cls.client = test.Client()
Пример #19
0
 def setUpClass(cls):
     # Setup a user and user profile.
     cls.username = "******"
     cls.password = "******"
     email = "*****@*****.**"
     cls.user = models.User(username=cls.username, email=email)
     cls.user.set_password(cls.password)
     cls.user.save()
     # Setup a network.
     network_name = 'test-network-name'
     cls.network = models.Network(name=network_name)
     cls.network.save()
     # Setup a BTS.
     cls.bts = models.BTS(network=cls.network)
     cls.bts.save()
     # Setup a DRF API client and a target endpoint.
     cls.api_client = APIClient()
     cls.endpoint = '/api/v1/stats'
Пример #20
0
    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="224466", nickname="test-bts-name",
                             inbound_url="http://localhost/224466/test",
                             network=cls.user_profile.network)
        cls.bts.save()
        cls.subscriber_imsi = 'IMSI000456'
        cls.subscriber = models.Subscriber.objects.create(
            balance=10000, name='test-sub-name', imsi=cls.subscriber_imsi,
            network=cls.bts.network)
        cls.subscriber.save()
Пример #21
0
    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']
Пример #22
0
    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.lat = 37.871783
        cls.lng = -122.260931  #berkeley

        #3 bts's non overlapping in channel, overlapping in location
        cls.bts1 = models.BTS(uuid="1",
                              nickname="test-bts-1",
                              inbound_url="http://localhost/224466/test",
                              network=cls.user_profile.network,
                              band="GSM900",
                              channel=1,
                              location=Point(cls.lng, cls.lat),
                              power_level=100)
        cls.bts1.save()

        cls.bts2 = models.BTS(uuid="2",
                              nickname="test-bts-2",
                              inbound_url="http://localhost/224466/test",
                              network=cls.user_profile.network,
                              band="GSM900",
                              channel=3,
                              location=Point(cls.lng, cls.lat),
                              power_level=100)
        cls.bts2.save()

        cls.bts3 = models.BTS(uuid="3",
                              nickname="test-bts-3",
                              inbound_url="http://localhost/224466/test",
                              network=cls.user_profile.network,
                              band="GSM900",
                              channel=5,
                              location=Point(cls.lng, cls.lat),
                              power_level=100)
        cls.bts3.save()
Пример #23
0
 def setUp(self):
     self.user = models.User(username="******", email="*****@*****.**")
     self.user.save()
     self.user_profile = models.UserProfile.objects.get(user=self.user)
     self.bts = models.BTS(uuid="133222",
                           nickname="test-bts-name!",
                           inbound_url="http://localhost/133222/test",
                           network=self.user_profile.network)
     self.bts.save()
     self.subscriber = models.Subscriber.objects.create(
         balance=10000,
         name='test-sub-name',
         imsi='IMSI00123',
         network=self.bts.network)
     self.subscriber.save()
     self.number = models.Number(number='5551234',
                                 state="inuse",
                                 network=self.bts.network,
                                 kind="number.nexmo.monthly",
                                 subscriber=self.subscriber)
     self.number.save()
Пример #24
0
 def setUpClass(cls):
     # Mock the stripe package.  Explicitly define a mocked customers to
     # the dict conversion.  The mocked retrieved customer is somewhat
     # complex because UserProfile.network.delete_card calls dict() on it.
     cls.mock_stripe = mock.Mock()
     cls.mock_stripe.StripeError = stripe.StripeError
     models.stripe = cls.mock_stripe
     cls.mock_stripe.Customer = mock.Mock()
     retrieved_customer = mock.MagicMock()
     cls.mock_stripe.Customer.retrieve.return_value = retrieved_customer
     cls.mock_stripe.Charge = mock.Mock()
     # We will set this retrieved customer to be 'deleted' by default so the
     # delete_card method will return True.
     retrieved_customer.keys.return_value.__iter__.return_value = (
         ['deleted'])
     cls.mock_stripe.Customer.create.return_value = {
         "id": "zyx987",
         "cards": {
             "data": [{
                 "last4": "1234",
                 "brand": "Visa",
                 "exp_month": "01",
                 "exp_year": "2020"
             }]
         }
     }
     # Setup a User and UserProfile.
     cls.user = models.User(username="******", email="*****@*****.**")
     cls.user.set_password("test")
     cls.user.save()
     cls.user_profile = models.UserProfile.objects.get(user=cls.user)
     card = {
         'number': '4242424242424242',
         'exp_month': 12,
         'exp_year': 2020,
         'cvc': 987
     }
     cls.user_profile.network.autoload_enable = True
     cls.user_profile.network.update_card(card)
 def setUp(self):
     """Set up the secondary user"""
     self.user2 = models.User(username="******", email="*****@*****.**")
     self.user2.save()
     self.user_profile2 = models.UserProfile.objects.get(user=self.user2)
     self.network2 = self.user_profile2.network
 def setUpClass(cls):
     """Setup a User and associated Network."""
     cls.user = models.User(username="******", email="*****@*****.**")
     cls.user.save()
     cls.user_profile = models.UserProfile.objects.get(user=cls.user)
     cls.network = cls.user_profile.network
 def setUpTestData(cls):
     user = models.User(username="******", email="*****@*****.**")
     user.save()
     user_profile = models.UserProfile.objects.get(user=user)
     cls.network = user_profile.network
Пример #28
0
 def setUpClass(cls):
     """Setup a User and UserProfile."""
     cls.user = models.User(username="******", email="*****@*****.**")
     cls.user.set_password("test")
     cls.user.save()
     cls.user_profile = models.UserProfile.objects.get(user=cls.user)
    def setUpClass(cls):
        """Generate a User, BTS and Number."""
        cls.email = "*****@*****.**"
        cls.user = models.User(username=cls.email, email=cls.email)
        cls.user.save()
        cls.user_profile = models.UserProfile.objects.get(user=cls.user)
        cls.uuid = "59216199-d664-4b7a-a2db-6f26e9a5d209"
        cls.inbound_url = "http://*****:*****@endaga.com"
        cls.user2 = models.User(username=cls.email2, email=cls.email2)
        cls.user2.save()
        cls.user_profile2 = models.UserProfile.objects.get(user=cls.user2)
        cls.user_profile2.network.bypass_gateway_auth = True
        cls.user_profile2.network.save()
        cls.uuid_whitelist = "59216899-d664-4b7a-a2db-6f26e9a5f205"
        cls.bts_whitelist = models.BTS(uuid=cls.uuid_whitelist,
                                       nickname='bts_whitelist',
                                       network=cls.user_profile2.network,
                                       inbound_url='http://localhost:8091')
        cls.bts_whitelist.save()
        imsi2 = "IMSI999990010000001"
        cls.sub2 = models.Subscriber(balance=10000,
                                     name='sub-three',
                                     imsi=imsi2,
                                     network=cls.user_profile2.network,
                                     bts=cls.bts_whitelist)
        cls.sub2.save()
        cls.num2 = 6285574719465
        cls.kind = "number.nexmo.monthly"
        cls.number2 = models.Number(number=cls.num2,
                                    state="inuse",
                                    network=cls.user_profile2.network,
                                    kind=cls.kind,
                                    subscriber=cls.sub2)
        cls.number2.save()