Exemplo n.º 1
0
 def test_success_boleto_ids(self):
     boletos = generateExampleBoletosJson(n=5)
     boletos = starkbank.boleto.create(boletos)
     boleto_ids = {boleto.id for boleto in boletos}
     logs = starkbank.boleto.log.query(boleto_ids=boleto_ids)
     for log in logs:
         print(log)
Exemplo n.º 2
0
    def test_fail_invalid_json_boleto(self):
        boletos = generateExampleBoletosJson(n=16)
        boletos[0].amount = None  # Required
        boletos[1].name = None  # Required
        boletos[2].tax_id = None  # Required
        boletos[3].street_line_1 = None  # Required
        boletos[4].street_line_2 = None  # Required
        boletos[5].district = None  # Required
        boletos[6].city = None  # Required
        boletos[7].state_code = None  # Required
        boletos[8].zip_code = None  # Required

        boletos[9].due = None  # Optional
        boletos[10].fine = None  # Optional
        boletos[11].interest = None  # Optional
        boletos[12].overdue_limit = None  # Optional
        boletos[13].tags = None  # Optional
        boletos[14].descriptions = None  # Optional

        boletos[15].invalid_parameter = "invalidValue"

        with self.assertRaises(InputErrors) as context:
            boletos = starkbank.boleto.create(boletos)
        errors = context.exception.errors
        for error in errors:
            print(error)
            self.assertEqual("invalidJson", error.code)
        self.assertEqual(9, len(errors))
Exemplo n.º 3
0
 def test_fail_invalid_description(self):
     boletos = generateExampleBoletosJson(n=18)
     boletos[0].descriptions = [{"text": "abc"}]  # Valid (correct)
     boletos[1].descriptions = [{"text": "abc", "amount": 1}]  # Valid (correct)
     boletos[2].descriptions = None  # Valid (Null)
     boletos[3].descriptions = {}  # Valid (Null)
     boletos[4].descriptions = []  # Valid (Null)
     boletos[5].descriptions = ""  # Valid (Null)
     boletos[6].descriptions = 0  # Valid (Null)
     boletos[7].descriptions = [1]
     boletos[8].descriptions = [{}]
     boletos[9].descriptions = [["abc", 2]]
     boletos[10].descriptions = [{"a": "1"}]  # 2 errors
     boletos[11].descriptions = [{"amount": 1}]
     boletos[12].descriptions = [{"text": 1, "amount": 1}]
     boletos[13].descriptions = [{"text": [], "amount": 1}]
     boletos[14].descriptions = [{"text": "abc", "amount": []}]
     boletos[15].descriptions = [{"text": "abc", "amount": {}}]
     boletos[16].descriptions = [{"text": "abc", "amount": "abc"}]
     boletos[17].descriptions = [{"text": "abc", "amount": 1, "test": "abc"}]
     with self.assertRaises(InputErrors) as context:
         boletos = starkbank.boleto.create(boletos)
     errors = context.exception.errors
     for error in errors:
         print(error)
         self.assertEqual('invalidDescription', error.code)
     self.assertEqual(12, len(errors))
Exemplo n.º 4
0
 def test_fail_invalid_array_size(self):
     boletos = generateExampleBoletosJson(n=105)
     with self.assertRaises(InputErrors) as context:
         boletos = starkbank.boleto.create(boletos)
     errors = context.exception.errors
     for error in errors:
         print(error)
         self.assertEqual("invalidJson", error.code)
     self.assertEqual(1, len(errors))
Exemplo n.º 5
0
    def test_success(self):
        boleto_samples = starkbank.boleto.create(generateExampleBoletosJson(n=5))

        holmes = starkbank.boletoholmes.create([
            starkbank.BoletoHolmes(boleto_id=boleto.id, tags=["elementary", "watson"])
            for boleto in boleto_samples
        ])
        for holmes in holmes:
            print(holmes)
Exemplo n.º 6
0
 def test_fail_delete_twice(self):
     boletos = generateExampleBoletosJson(n=1)
     boletos = starkbank.boleto.create(boletos)
     boleto_id = boletos[0].id
     boletos = starkbank.boleto.delete(id=boleto_id)
     with self.assertRaises(InputErrors) as context:
         boletos = starkbank.boleto.delete(id=boleto_id)
     errors = context.exception.errors
     for error in errors:
         print(error)
         self.assertEqual("invalidBoleto", error.code)
     self.assertEqual(1, len(errors))
Exemplo n.º 7
0
 def test_fail_invalid_tax_id(self):
     boletos = generateExampleBoletosJson(n=5)
     boletos[0].tax_id = "000.000.000-00"
     boletos[1].tax_id = "00.000.000/0000-00"
     boletos[2].tax_id = "abc"
     boletos[3].tax_id = 123  # 2 errors
     boletos[4].tax_id = {}  # 2 errors
     with self.assertRaises(InputErrors) as context:
         boletos = starkbank.boleto.create(boletos)
     errors = context.exception.errors
     for error in errors:
         print(error)
         self.assertEqual('invalidTaxId', error.code)
     self.assertEqual(7, len(errors))
Exemplo n.º 8
0
 def test_fail_invalid_amount(self):
     boletos = generateExampleBoletosJson(n=5)
     boletos[0].amount = "123"
     boletos[1].amount = -5
     boletos[2].amount = 0
     boletos[3].amount = 1000000000000000
     boletos[4].amount = {}
     with self.assertRaises(InputErrors) as context:
         boletos = starkbank.boleto.create(boletos)
     errors = context.exception.errors
     for error in errors:
         print(error)
         self.assertEqual('invalidAmount', error.code)
     self.assertEqual(5, len(errors))
Exemplo n.º 9
0
 def test_success_boleto_ids(self):
     boletos = generateExampleBoletosJson(n=5)
     boletos = starkbank.boleto.create(boletos)
     boleto_ids = {boleto.id for boleto in boletos}
     logs = starkbank.boleto.log.query(boleto_ids=boleto_ids)
     log_result = {
         "created": set(),
         "registered": set(),
     }
     sleep(5)
     for log in logs:
         log_result[log.type].add(log.boleto.id)
     print(log_result)
     self.assertEqual(boleto_ids, log_result["created"])
     self.assertEqual(boleto_ids, log_result["registered"])
Exemplo n.º 10
0
 def test_success(self):
     boletos = generateExampleBoletosJson(n=1)
     boletos = starkbank.boleto.create(boletos)
     boleto_id = boletos[0].id
     boleto = starkbank.boleto.delete(id=boleto_id)
     print(boleto.id)
Exemplo n.º 11
0
 def test_success(self):
     boletos = generateExampleBoletosJson(n=5)
     boletos = starkbank.boleto.create(boletos)
     for boleto in boletos:
         print(boleto)
Exemplo n.º 12
0
    def test_fail_invalid_discounts(self):
        boletos = generateExampleBoletosJson(n=19,
                                             useRandomFutureDueDate=False)
        boletos[0].discounts = None  # Valid (correct)
        boletos[1].discounts = []  # Valid (correct)
        boletos[2].discounts = [{
            "percentage": 3,
            "date": date.today() + timedelta(days=1)
        }, {
            "percentage": 5,
            "date": date.today()
        }]  # Valid (correct)
        boletos[3].discounts = [{
            "percentage": 5,
            "date": date.today()
        }, {
            "percentage": 2.5,
            "date": date.today() + timedelta(days=2)
        }]  # Valid (correct)
        boletos[4].discounts = [{
            "percentage": 5,
            "date": date.today()
        }, {
            "percentage": 4,
            "date": date.today() + timedelta(days=1)
        }, {
            "percentage": 3,
            "date": date.today() + timedelta(days=2)
        }, {
            "percentage": 2,
            "date": date.today() + timedelta(days=3)
        }, {
            "percentage": 1,
            "date": date.today() + timedelta(days=4)
        }, {
            "percentage": 0.5,
            "date": date.today() + timedelta(days=5)
        }]  # too many discounts
        boletos[5].discounts = [{
            "percentage": 1,
            "date": date.today()
        }, {
            "percentage": 3,
            "date": date.today() + timedelta(days=1)
        }]  # ascending discount
        boletos[6].discounts = [{
            "percentage": 3,
            "date": date.today()
        }, {
            "percentage": 3,
            "date": date.today() + timedelta(days=1)
        }]  # repeated percentage
        boletos[7].discounts = [{
            "percentage": -1,
            "date": date.today()
        }]  # invalid percentage
        boletos[8].discounts = [{
            "percentage": 0,
            "date": date.today()
        }]  # invalid percentage
        boletos[9].discounts = [{
            "percentage": 110,
            "date": date.today()
        }]  # invalid percentage
        boletos[10].discounts = [{
            "percentage": "wrong",
            "date": date.today()
        }]  # invalid percentage
        boletos[11].discounts = [{
            "percentages": 5,
            "date": date.today()
        }]  # invalid argument
        boletos[12].discounts = [{
            "percentage": 5,
            "date": date.today(),
            "wrong": 0
        }]  # invalid argument
        boletos[13].discounts = [{"date": date.today()}]  # missing percentage
        boletos[14].discounts = [{}]  # missing percentage and date
        boletos[14].discounts = [{
            "wrong": "wrong"
        }]  # missing percentage and date
        boletos[15].discounts = [{"percentages": 5}]  # missing date
        boletos[16].discounts = [{
            "percentage": 5,
            "date": date.today() - timedelta(days=1)
        }]  # invalid date
        boletos[17].discounts = [{
            "percentage": 5,
            "date": boletos[17].due + timedelta(days=1)
        }]  # invalid date
        boletos[18].discounts = [{
            "percentage": 5,
            "date": "wrong"
        }]  # invalid date

        with self.assertRaises(InputErrors) as context:
            starkbank.boleto.create(boletos)
        errors = context.exception.errors
        for error in errors:
            print(error)
            self.assertTrue(
                error.code in
                ['invalidBoleto', 'invalidDiscount', 'invalidDiscountDate'])
        self.assertEqual(20, len(errors))