Пример #1
0
    def test_days_remaining_matches_expected(self):
        sampleData = """
        {
  "mainBalance" : 14.420000076293945,
  "bonusBalance" : 0.0,
  "lastBillAmount" : 0.0,
  "openBillAmount" : 0.0,
  "webTextBalance" : {
    "nationalSms" : 200,
    "internationalSms" : 50,
    "nationalSmsAllowance" : 200,
    "internationalSmsAllowance" : 50
  },
  "addonBalance" : [ {
    "balance" : 10000.0,
    "expiryDate" : "EXPIRYDATE",
    "serviceBundle" : {
      "name" : "Awarded Voice Balance",
      "paymentProfile" : null,
      "serviceCode" : "AB2",
      "recurring" : false,
      "allowance" : 10000.0,
      "type" : "voice",
      "unit" : "Min",
      "charge" : 0.0,
      "status" : "ACTIVE",
      "serviceParameters" : { }
    },
    "optin" : true,
    "visible" : null
  }]
  }
        """

        futureDateTime = (datetime.now() +
                          timedelta(days=20)).strftime("%d-%b-%Y %H:%M")

        sampleData = sampleData.replace("EXPIRYDATE", futureDateTime)
        balances = Balances(sampleData)

        self.assertEqual(balances.services[0].days_remaining(), 19)
Пример #2
0
    def test_create_svc_mystery_type_creates_generic_type(self):
        sampleDataWithUnknownType = """
        {
  "mainBalance" : 14.420000076293945,
  "bonusBalance" : 0.0,
  "lastBillAmount" : 0.0,
  "openBillAmount" : 0.0,
  "webTextBalance" : {
    "nationalSms" : 200,
    "internationalSms" : 50,
    "nationalSmsAllowance" : 200,
    "internationalSmsAllowance" : 50
  },
  "addonBalance" : [ {
    "balance" : 10000.0,
    "expiryDate" : "15-Oct-2017 00:00",
    "serviceBundle" : {
      "name" : "Awarded Voice Balance",
      "paymentProfile" : null,
      "serviceCode" : "AB2",
      "recurring" : false,
      "allowance" : 10000.0,
      "type" : "mystery",
      "unit" : "Min",
      "charge" : 0.0,
      "status" : "ACTIVE",
      "serviceParameters" : { }
    },
    "optin" : true,
    "visible" : null
  }]
  }
        """

        balances = Balances(sampleDataWithUnknownType)

        self.assertTrue(isinstance(balances.services[0], GenericBalance))
Пример #3
0
    def test_create_svc_maps_type_correctly(self):
        with (open(sample_data_dir + "balances_lots_enabled.json")) as f:
            balances = Balances(f.read())

            self.assertTrue(isinstance(balances.services[0], VoiceBalance))
Пример #4
0
    def test_data_gets_voice_balances(self):
        with (open(sample_data_dir + "balances_lots_enabled.json")) as f:
            balances = Balances(f.read())

            self.assertEqual(len(list(balances.voice())), 1)
Пример #5
0
    def test_balances_active_balances_2active_returns_2(self):
        with (open(sample_data_dir + "mobile_data_1024_left.json")) as f:
            balances = Balances(f.read())

            self.assertEqual(len(list(balances.active_balances())), 2)
Пример #6
0
    def test_balances_active_balances_none_returns_0(self):
        with (open(sample_data_dir + "mobile_data_empty.json")) as f:
            balances = Balances(f.read())

            self.assertEqual(len(list(balances.active_balances())), 0)
Пример #7
0
    def test_balances_count_of_services_matches_expected(self):
        with (open(sample_data_dir + "mobile_data_empty.json")) as f:
            balances = Balances(f.read())

            self.assertEqual(len(balances.services), 7)
Пример #8
0
    def test_balances_credit_remaining_matches_expected(self):
        with (open(sample_data_dir + "mobile_data_empty.json")) as f:
            balances = Balances(f.read())

            self.assertEqual(balances.credit_remaining, 4.42)
Пример #9
0
    def test_remaining_total_for_empty_data_matches_expected(self):
        with (open(sample_data_dir + "mobile_data_empty.json")) as f:
            balances = Balances(f.read())

            self.assertEqual(balances.remaining_total("data").remaining_qty, 0)
Пример #10
0
 def test_balances_init_loadsJson(self):
     with (open(sample_data_dir + "mobile_data_empty.json")) as f:
         Balances(f.read())
Пример #11
0
    def test_remaining_total_for_958MB_sample_returns_958(self):
        with (open(sample_data_dir + "mobile_data_958_left.json")) as f:
            balances = Balances(f.read())

            self.assertEqual(
                balances.remaining_total("data").remaining_qty, 958.076171875)
Пример #12
0
    def test_remaining_total_for_data_matches_expected(self):
        with (open(sample_data_dir + "balances_lots_enabled.json")) as f:
            balances = Balances(f.read())

            self.assertEqual(
                balances.remaining_total("data").remaining_qty, 8591.7578125)
Пример #13
0
    def test_remaining_total_for_missing_type_returns_0(self):
        with (open(sample_data_dir + "balances_lots_enabled.json")) as f:
            balances = Balances(f.read())

            self.assertEqual(
                balances.remaining_total("nonexistent").remaining_qty, 0)