/
validator_spec.py
86 lines (71 loc) · 3.33 KB
/
validator_spec.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
from mamba import description, context, it, before
from expects import expect, be_a, raise_error, equal, be
from doublex_expects import have_been_called_with
from doublex import Spy
from amadeus import Client
from os import environ
from logging import Logger, getLogger
with description('Mixins/Validator') as self:
with before.all:
self.valid_params = {
'client_id': '1234',
'client_secret': '4546'
}
with context('Client.__init__'):
with it('should create a new client with direct variables'):
client = Client(**self.valid_params)
expect(client).to(be_a(Client))
with it('should create a new client with environment variables'):
environ['AMADEUS_CLIENT_ID'] = '123'
environ['AMADEUS_CLIENT_SECRET'] = '234'
expect(Client()).to(be_a(Client))
del environ['AMADEUS_CLIENT_ID']
del environ['AMADEUS_CLIENT_SECRET']
with context('with missing parameters'):
with it("should refuse to create a new client without client_id"):
del self.valid_params['client_id']
expect(lambda: Client(**self.valid_params)).to(
raise_error(ValueError)
)
with it("should refuse to create a new client w/o client_secret"):
del self.valid_params['client_secret']
expect(lambda: Client(**self.valid_params)).to(
raise_error(ValueError)
)
with it('should by default have a logger'):
amadeus = Client(**self.valid_params)
expect(amadeus.logger).to(be_a(Logger))
expect(amadeus.log_level).to(equal('warn'))
with it("should allow for setting a custom logger"):
logger = getLogger('amadeus')
self.valid_params['logger'] = logger
amadeus = Client(**self.valid_params)
expect(amadeus.logger).to(be(logger))
expect(amadeus.log_level).to(equal('warn'))
with it("should persist a custom log level"):
logger = getLogger('amadeus')
logger.setLevel(10)
self.valid_params['logger'] = logger
amadeus = Client(**self.valid_params)
expect(amadeus.logger).to(be(logger))
expect(amadeus.logger.level).to(be(10))
with it('should warn when an unrecognized option is passed in'):
logger = Spy()
self.valid_params['logger'] = logger
self.valid_params['foobar'] = 'test'
Client(**self.valid_params)
expect(logger.warning).to(
have_been_called_with('Unrecognized option: foobar')
)
with it('should default to the test host'):
amadeus = Client(**self.valid_params)
expect(amadeus.host).to(equal(Client.HOSTS['test']))
with it('should allow for setting a different hostname'):
self.valid_params['hostname'] = 'production'
amadeus = Client(**self.valid_params)
expect(amadeus.host).to(equal(Client.HOSTS['production']))
with it('should allow for setting a full different host'):
host = 'http://foo.bar.com/'
self.valid_params['host'] = host
amadeus = Client(**self.valid_params)
expect(amadeus.host).to(equal(host))