Пример #1
0
    def testOutgoingInternationalTropoApi(self):
        self.assertEqual(self.tropo_rate_any.conversion_rate, self.usd_rate.conversion)
        msg = SMSLog(domain = self.domain,
            direction = OUTGOING,
            date = datetime.datetime.utcnow(),
            text = self.test_message)
        msg.save()

        if self.sms_config and self.sms_config.get("tropo_int") and self.tropo_backend:
            logging.info("\n\n[Billing - LIVE] Tropo:  Outgoing International SMS Test")
            msg.phone_number = self.sms_config.get("tropo_int")
            msg.save()
            data = self.tropo_backend.send(msg, delay=False)
        else:
            logging.info("\n\n[Billing] Tropo: Outgoing International SMS Test")
            data = "<session><success>true</success><token>faketoken</token><id>aadfg3Aa321gdc8e628df2\n</id></session>"
            msg.phone_number = "+4915253271951"
            msg.save()
            bill_client_for_sms(TropoSMSBillable, msg.get_id, **dict(response=data))

        logging.info("[Billing] Response from TROPO: %s" % data)
        tropo_id = TropoSMSBillable.get_tropo_id(data)
        logging.info("[Billing] TROPO ID: %s" % tropo_id)

        billable_items = TropoSMSBillable.by_domain(self.domain)
        if billable_items:
            billable_item = billable_items[0]
            self.assertEqual(self.tropo_rate_any.base_fee,
                billable_item.billable_amount)
            self.assertEqual(self.tropo_rate_any._id, billable_item.rate_id)
            self.assertEqual(msg._id, billable_item.log_id)
            self.assertEqual(self.tropo_rate_any.conversion_rate, billable_item.conversion_rate)
            self.assertEqual(self.dimagi_surcharge.base_fee, billable_item.dimagi_surcharge)
            self.assertEqual(tropo_id, billable_item.tropo_id)
            billable_item.delete()
            if billable_item.has_error:
                raise Exception("There were recorded errors creating an outgoing International Tropo billing rate: %s" %
                                billable_item.error_message)
        else:
            raise Exception("There were unknown errors creating an outgoing International Tropo billing rate!")
Пример #2
0
    def testOutgoingUnicelApi(self):
        self.assertEqual(self.unicel_rate.conversion_rate, self.usd_rate.conversion)
        msg = SMSLog(domain = self.domain,
            direction = OUTGOING,
            date = datetime.datetime.utcnow(),
            text = self.test_message)
        msg.save()

        if self.sms_config and self.sms_config.get("unicel") and self.unicel_backend:
            logging.info("\n\n[Billing - LIVE] UNICEL: Outgoing SMS Test.")
            msg.phone_number = self.sms_config.get("unicel")
            msg.save()
            data = self.unicel_backend.send(msg, delay=False)
        else:
            logging.info("\n\n[Billing] UNICEL: Outgoing SMS Test")
            data = "successful23541253235"
            msg.phone_number = "+555555555"
            msg.save()
            bill_client_for_sms(UnicelSMSBillable, msg.get_id, **dict(response=data))

        logging.info("Response from UNICEL: %s" % data)

        billable_items = UnicelSMSBillable.by_domain_and_direction(self.domain, OUTGOING)
        if billable_items:
            billable_item = billable_items[0]
            self.assertEqual(self.unicel_rate.base_fee * self.unicel_rate.conversion_rate,
                       billable_item.billable_amount)
            self.assertEqual(self.unicel_rate._id, billable_item.rate_id)
            self.assertEqual(msg._id, billable_item.log_id)
            self.assertEqual(self.unicel_rate.conversion_rate, billable_item.conversion_rate)
            self.assertEqual(self.dimagi_surcharge.base_fee, billable_item.dimagi_surcharge)
            self.assertEqual(data, billable_item.unicel_id)
            if billable_item.has_error:
                raise Exception("There were recorded errors creating an outgoing UNICEL billing rate: %s" %
                                billable_item.error_message)
        else:
            raise Exception("There were unknown errors creating an outgoing UNICEL billing rate!")