-
Notifications
You must be signed in to change notification settings - Fork 8
/
test_dolar.py
executable file
·132 lines (104 loc) · 4.55 KB
/
test_dolar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/python
# -*- coding: utf-8 -*-
import unittest
from datetime import date
from dolar import (
Dolar,
ModosDeConsulta,
BancoCentralException
)
class TestCase(unittest.TestCase):
def setUp(self):
TODAY = date(2020, 10, 1)
periodo = {
"inicio": date(2020, 9, 28),
"final": date(2020, 10, 2)
}
self.cotacaoDia = Dolar(mode=ModosDeConsulta.PorDia, data=TODAY)
self.cotacaoPeriodo = Dolar(mode=ModosDeConsulta.PorPeriodo, periodo=periodo)
def test_server_response_diferente_200_ok(self):
dolar = Dolar(mode=ModosDeConsulta.PorDia, data=date(2020, 8, 20))
dolar.URL = 'http://my.url'
with self.assertRaises(BancoCentralException) as context:
dolar.getURL()
self.assertTrue('Erro na conexão' in str(context.exception))
def test_dolar_compra_ptax(self):
self.assertIsNotNone(self.cotacaoDia.dolar_compra_ptax())
self.assertIsNotNone(self.cotacaoPeriodo.dolar_compra_ptax())
def test_dolar_compra_ptax_weekend(self):
TODAY = date(2020, 11, 1)
with self.assertRaises(BancoCentralException) as context:
Dolar(
mode=ModosDeConsulta.PorDia,
data=TODAY
)
self.assertTrue('Sábado e Domingo não há cotações' in str(context.exception))
def test_dolar_compra_ptax_holiday(self):
TODAY = date(2020, 11, 2)
with self.assertRaises(BancoCentralException) as context:
Dolar(
mode=ModosDeConsulta.PorDia,
data=TODAY
)
self.assertTrue('Feriados não há cotações' in str(context.exception))
def test_mode_errors(self):
TODAY = date(2020, 10, 31)
with self.assertRaises(BancoCentralException) as context:
Dolar(
mode=ModosDeConsulta.Error,
data=TODAY
)
self.assertTrue('Tipo de consulta inválida' in str(context.exception))
def test_dolar_compra_maior_zero(self):
self.assertTrue(self.cotacaoDia.dolar_compra_ptax() > 0)
self.assertTrue(self.cotacaoPeriodo.dolar_compra_ptax() > 0)
def test_dolar_compra_futuro_zero(self):
TODAY = date(2050, 11, 1)
self.cotacaoDia = Dolar(mode=ModosDeConsulta.PorDia, data=TODAY)
self.assertTrue(self.cotacaoDia.dolar_compra_ptax() == 0)
def test_dolar_venda_ptax(self):
self.assertIsNotNone(self.cotacaoDia.dolar_venda_ptax())
self.assertIsNotNone(self.cotacaoPeriodo.dolar_venda_ptax())
def test_dolar_venda_futuro_zero(self):
TODAY = date(2050, 11, 1)
self.cotacaoDia = Dolar(mode=ModosDeConsulta.PorDia, data=TODAY)
self.assertTrue(self.cotacaoDia.dolar_venda_ptax() == 0)
def test_dolar_venda_ptax_maior_zero(self):
self.assertTrue(self.cotacaoDia.dolar_venda_ptax() > 0)
self.assertTrue(self.cotacaoPeriodo.dolar_venda_ptax() > 0)
def test_ultimacotacao_exist(self):
self.assertIsNotNone(self.cotacaoDia.dolar_ultimacotacao())
self.assertIsNotNone(self.cotacaoPeriodo.dolar_ultimacotacao())
def test_dolar_ultima_cotacao_data_futura_zero(self):
TODAY = date(2050, 11, 1)
self.cotacaoDia = Dolar(mode=ModosDeConsulta.PorDia, data=TODAY)
self.assertTrue(self.cotacaoDia.dolar_ultimacotacao() == 0)
def test_is_holiday_tiradentes(self):
TODAY = date(2020, 4, 21)
self.assertTrue(self.cotacaoDia.is_holiday(TODAY))
def test_is_holiday_independencia(self):
TODAY = date(2020, 9, 7)
self.assertTrue(self.cotacaoDia.is_holiday(TODAY))
def test_is_holiday_aparecida(self):
TODAY = date(2020, 10, 12)
self.assertTrue(self.cotacaoDia.is_holiday(TODAY))
def test_is_holiday_finados(self):
TODAY = date(2020, 11, 2)
self.assertTrue(self.cotacaoDia.is_holiday(TODAY))
def test_is_holiday_republica(self):
TODAY = date(2020, 11, 15)
self.assertTrue(self.cotacaoDia.is_holiday(TODAY))
def test_is_holiday_trabalho(self):
TODAY = date(2020, 5, 1)
self.assertTrue(self.cotacaoDia.is_holiday(TODAY))
def test_is_holiday_saopaulo(self):
TODAY = date(2020, 1, 25)
self.assertTrue(self.cotacaoDia.is_holiday(TODAY))
def test_is_not_weekday(self):
TODAY = date(2020, 10, 1)
self.assertFalse(self.cotacaoDia.is_weekend(TODAY))
def test_is_weekday(self):
TODAY = date(2020, 10, 3)
self.assertTrue(self.cotacaoDia.is_weekend(TODAY))
if __name__ == '__main__':
unittest.main()