cli2 5.0.0rc2__tar.gz → 5.0.0rc6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cli2-5.0.0rc2/cli2.egg-info → cli2-5.0.0rc6}/PKG-INFO +1 -1
- {cli2-5.0.0rc2 → cli2-5.0.0rc6/cli2.egg-info}/PKG-INFO +1 -1
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/setup.py +1 -1
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/tests/test_ansible.py +2 -2
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/tests/test_cli.py +1 -1
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/tests/test_client.py +82 -64
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/MANIFEST.in +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/README.rst +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/classifiers.txt +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/cli2/__init__.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/cli2/asyncio.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/cli2/cli.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/cli2/cli2.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/cli2/colors.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/cli2/configuration.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/cli2/decorators.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/cli2/display.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/cli2/examples/__init__.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/cli2/examples/conf.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/cli2/examples/example.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/cli2/examples/example_obj.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/cli2/examples/nesting.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/cli2/examples/obj.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/cli2/examples/obj2.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/cli2/examples/test.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/cli2/lock.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/cli2/log.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/cli2/mask.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/cli2/node.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/cli2/sphinx.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/cli2/table.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/cli2/test.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/cli2.egg-info/SOURCES.txt +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/cli2.egg-info/dependency_links.txt +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/cli2.egg-info/entry_points.txt +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/cli2.egg-info/requires.txt +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/cli2.egg-info/top_level.txt +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/setup.cfg +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/tests/test_ansible_variables.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/tests/test_asyncio.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/tests/test_command.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/tests/test_configuration.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/tests/test_decorators.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/tests/test_display.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/tests/test_entry_point.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/tests/test_group.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/tests/test_inject.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/tests/test_lock.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/tests/test_mask.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/tests/test_node.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/tests/test_restful.py +0 -0
- {cli2-5.0.0rc2 → cli2-5.0.0rc6}/tests/test_table.py +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import cli2
|
|
2
|
-
import
|
|
2
|
+
import chttpx
|
|
3
3
|
import httpx
|
|
4
4
|
import mock
|
|
5
5
|
import pytest
|
|
@@ -32,7 +32,7 @@ async def test_mask(monkeypatch):
|
|
|
32
32
|
|
|
33
33
|
@pytest.mark.asyncio
|
|
34
34
|
async def test_response_error(httpx_mock):
|
|
35
|
-
class Client(
|
|
35
|
+
class Client(chttpx.Client):
|
|
36
36
|
mask_keys = ['secret']
|
|
37
37
|
|
|
38
38
|
class Action(cansible.ActionBase):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from datetime import datetime
|
|
2
2
|
import cli2
|
|
3
|
-
import
|
|
3
|
+
import chttpx
|
|
4
4
|
import httpx
|
|
5
5
|
import inspect
|
|
6
6
|
import mock
|
|
@@ -11,7 +11,7 @@ async def _response(**kwargs):
|
|
|
11
11
|
return httpx.Response(**kwargs)
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
class HandlerSentinel(
|
|
14
|
+
class HandlerSentinel(chttpx.Handler):
|
|
15
15
|
def __init__(self, *args, **kwargs):
|
|
16
16
|
super().__init__(*args, **kwargs)
|
|
17
17
|
self.calls = []
|
|
@@ -23,9 +23,9 @@ class HandlerSentinel(cclient.Handler):
|
|
|
23
23
|
|
|
24
24
|
@pytest.fixture
|
|
25
25
|
def client_class():
|
|
26
|
-
class TestClient(
|
|
26
|
+
class TestClient(chttpx.Client):
|
|
27
27
|
""" doc """
|
|
28
|
-
class Paginator(
|
|
28
|
+
class Paginator(chttpx.Paginator):
|
|
29
29
|
def pagination_parameters(self, params, page_number):
|
|
30
30
|
if page_number > 1:
|
|
31
31
|
params['page'] = page_number
|
|
@@ -118,7 +118,7 @@ async def test_client_cli_override(client_class, httpx_mock):
|
|
|
118
118
|
|
|
119
119
|
|
|
120
120
|
def test_client_model(client_class):
|
|
121
|
-
assert issubclass(client_class.Model,
|
|
121
|
+
assert issubclass(client_class.Model, chttpx.Model)
|
|
122
122
|
assert client_class.Model._client_class == client_class
|
|
123
123
|
|
|
124
124
|
class TestModel(client_class.Model):
|
|
@@ -152,7 +152,7 @@ async def test_async_factory(httpx_mock, client_class):
|
|
|
152
152
|
|
|
153
153
|
@pytest.mark.asyncio
|
|
154
154
|
async def test_client_cli_side_effect(client_class, httpx_mock):
|
|
155
|
-
from
|
|
155
|
+
from chttpx import example
|
|
156
156
|
|
|
157
157
|
# test that this didn't spill over client_class
|
|
158
158
|
test_client_cli(client_class, httpx_mock)
|
|
@@ -261,7 +261,7 @@ async def test_handler(client_class):
|
|
|
261
261
|
client = client_class()
|
|
262
262
|
client.client_reset = mock.AsyncMock()
|
|
263
263
|
client.token_reset = mock.AsyncMock()
|
|
264
|
-
handler =
|
|
264
|
+
handler = chttpx.Handler(accepts=[201], refuses=[218], retokens=[418])
|
|
265
265
|
|
|
266
266
|
response = httpx.Response(status_code=201)
|
|
267
267
|
result = await handler(client, response, 0, log)
|
|
@@ -276,7 +276,7 @@ async def test_handler(client_class):
|
|
|
276
276
|
|
|
277
277
|
response = httpx.Response(status_code=200, content='[2]')
|
|
278
278
|
response.request = httpx.Request('POST', '/', json=[1])
|
|
279
|
-
with pytest.raises(
|
|
279
|
+
with pytest.raises(chttpx.RetriesExceededError) as exc:
|
|
280
280
|
await handler(client, response, handler.tries + 1, log)
|
|
281
281
|
log.info.assert_called_once_with(
|
|
282
282
|
'retry', status_code=200, tries=0, sleep=.0
|
|
@@ -287,7 +287,7 @@ async def test_handler(client_class):
|
|
|
287
287
|
|
|
288
288
|
response = httpx.Response(status_code=200)
|
|
289
289
|
response.request = httpx.Request('GET', '/')
|
|
290
|
-
with pytest.raises(
|
|
290
|
+
with pytest.raises(chttpx.RetriesExceededError) as exc:
|
|
291
291
|
await handler(client, response, handler.tries + 1, log)
|
|
292
292
|
|
|
293
293
|
msg = 'Unacceptable response <Response [200 OK]> after 31 tries\n\x1b[0m\x1b[1mGET /\x1b[0m\n\x1b[1mHTTP 200\x1b[0m' # noqa
|
|
@@ -295,7 +295,7 @@ async def test_handler(client_class):
|
|
|
295
295
|
|
|
296
296
|
response = httpx.Response(status_code=218)
|
|
297
297
|
response.request = httpx.Request('POST', '/')
|
|
298
|
-
with pytest.raises(
|
|
298
|
+
with pytest.raises(chttpx.RefusedResponseError) as exc:
|
|
299
299
|
await handler(client, response, 1, log)
|
|
300
300
|
|
|
301
301
|
assert exc.value.response
|
|
@@ -306,7 +306,7 @@ async def test_handler(client_class):
|
|
|
306
306
|
|
|
307
307
|
response = httpx.Response(status_code=418)
|
|
308
308
|
response.request = httpx.Request('POST', '/')
|
|
309
|
-
with pytest.raises(
|
|
309
|
+
with pytest.raises(chttpx.TokenGetError):
|
|
310
310
|
await handler(client, response, 1, log)
|
|
311
311
|
|
|
312
312
|
assert not client.client_reset.await_count
|
|
@@ -337,7 +337,7 @@ async def test_handler(client_class):
|
|
|
337
337
|
assert not result
|
|
338
338
|
assert client.token_reset.await_count == 1
|
|
339
339
|
|
|
340
|
-
handler =
|
|
340
|
+
handler = chttpx.Handler(accepts=[], refuses=[222])
|
|
341
341
|
|
|
342
342
|
response = httpx.Response(status_code=123)
|
|
343
343
|
result = await handler(client, response, 0, log)
|
|
@@ -476,7 +476,7 @@ async def test_pagination_model(httpx_mock, client_class):
|
|
|
476
476
|
|
|
477
477
|
|
|
478
478
|
def test_paginator_fields(client_class):
|
|
479
|
-
paginator =
|
|
479
|
+
paginator = chttpx.Paginator(client_class(), '/')
|
|
480
480
|
paginator.total_items = 95
|
|
481
481
|
paginator.per_page = 10
|
|
482
482
|
assert paginator.total_pages == 10
|
|
@@ -517,7 +517,7 @@ async def test_pagination_patterns(httpx_mock, client_class):
|
|
|
517
517
|
class Offset(client_class.Model):
|
|
518
518
|
url_list = '/off'
|
|
519
519
|
|
|
520
|
-
class Paginator(
|
|
520
|
+
class Paginator(chttpx.Paginator):
|
|
521
521
|
def pagination_initialize(self, data):
|
|
522
522
|
self.total_items = data['total']
|
|
523
523
|
|
|
@@ -552,8 +552,21 @@ async def test_pagination_patterns(httpx_mock, client_class):
|
|
|
552
552
|
assert params == dict(offset=1, limit=1)
|
|
553
553
|
|
|
554
554
|
|
|
555
|
+
@pytest.fixture
|
|
556
|
+
def reverse_client(httpx_mock, client_class):
|
|
557
|
+
class Paginator(client_class.Paginator):
|
|
558
|
+
def pagination_initialize(self, data):
|
|
559
|
+
self.total_pages = data['total_pages']
|
|
560
|
+
|
|
561
|
+
# test that we can reverse pagination too
|
|
562
|
+
class Client(client_class):
|
|
563
|
+
paginator = Paginator
|
|
564
|
+
|
|
565
|
+
return Client(base_url='http://lol')
|
|
566
|
+
|
|
567
|
+
|
|
555
568
|
@pytest.mark.asyncio
|
|
556
|
-
async def test_pagination_reverse(
|
|
569
|
+
async def test_pagination_reverse(reverse_client, httpx_mock):
|
|
557
570
|
httpx_mock.add_response(
|
|
558
571
|
url='http://lol/bar',
|
|
559
572
|
json=dict(total_pages=3, items=[dict(a=1), dict(a=2)]),
|
|
@@ -566,27 +579,32 @@ async def test_pagination_reverse(httpx_mock, client_class):
|
|
|
566
579
|
url='http://lol/bar?page=3',
|
|
567
580
|
json=dict(total_pages=3, items=[dict(a=5)]),
|
|
568
581
|
)
|
|
569
|
-
|
|
570
|
-
class Paginator(client_class.Paginator):
|
|
571
|
-
def pagination_initialize(self, data):
|
|
572
|
-
self.total_pages = data['total_pages']
|
|
573
|
-
|
|
574
|
-
# test that we can reverse pagination too
|
|
575
|
-
class Client(client_class):
|
|
576
|
-
paginator = Paginator
|
|
577
|
-
|
|
578
|
-
client = Client(base_url='http://lol')
|
|
579
|
-
paginator = client.paginate('/bar')
|
|
582
|
+
paginator = reverse_client.paginate('/bar')
|
|
580
583
|
paginator = paginator.reverse()
|
|
581
584
|
results = await paginator.list()
|
|
582
585
|
assert [x['a'] for x in results] == [5, 4, 3, 2, 1]
|
|
583
586
|
|
|
584
587
|
|
|
588
|
+
@pytest.mark.asyncio
|
|
589
|
+
async def test_pagination_last(httpx_mock, reverse_client):
|
|
590
|
+
httpx_mock.add_response(
|
|
591
|
+
url='http://lol/bar',
|
|
592
|
+
json=dict(total_pages=3, items=[dict(a=1), dict(a=2)]),
|
|
593
|
+
)
|
|
594
|
+
httpx_mock.add_response(
|
|
595
|
+
url='http://lol/bar?page=3',
|
|
596
|
+
json=dict(total_pages=3, items=[dict(a=5)]),
|
|
597
|
+
)
|
|
598
|
+
paginator = reverse_client.paginate('/bar')
|
|
599
|
+
last_item = await paginator.last_item()
|
|
600
|
+
assert last_item['a'] == 5
|
|
601
|
+
|
|
602
|
+
|
|
585
603
|
def test_descriptor(client_class):
|
|
586
604
|
class Model(client_class.Model):
|
|
587
|
-
id =
|
|
588
|
-
bar =
|
|
589
|
-
foo =
|
|
605
|
+
id = chttpx.Field()
|
|
606
|
+
bar = chttpx.Field('nested/bar')
|
|
607
|
+
foo = chttpx.Field('undeclared/foo')
|
|
590
608
|
|
|
591
609
|
model = Model(data=dict(id=1, nested=dict(bar=2)))
|
|
592
610
|
assert model.data['id'] == 1
|
|
@@ -621,7 +639,7 @@ def test_descriptor(client_class):
|
|
|
621
639
|
|
|
622
640
|
def test_jsonstring(client_class):
|
|
623
641
|
class Model(client_class.Model):
|
|
624
|
-
json =
|
|
642
|
+
json = chttpx.JSONStringField()
|
|
625
643
|
|
|
626
644
|
client = client_class()
|
|
627
645
|
model = client.Model(data=dict(json='{"foo": 1}'))
|
|
@@ -641,7 +659,7 @@ def test_jsonstring(client_class):
|
|
|
641
659
|
|
|
642
660
|
def test_datetime(client_class):
|
|
643
661
|
class Model(client_class.Model):
|
|
644
|
-
dt =
|
|
662
|
+
dt = chttpx.DateTimeField()
|
|
645
663
|
|
|
646
664
|
model = Model(dict(dt='2020-11-12T01:02:03'))
|
|
647
665
|
assert model.dt == datetime(2020, 11, 12, 1, 2, 3)
|
|
@@ -651,10 +669,10 @@ def test_datetime(client_class):
|
|
|
651
669
|
|
|
652
670
|
def test_model_inheritance(client_class):
|
|
653
671
|
class Model(client_class.Model):
|
|
654
|
-
foo =
|
|
672
|
+
foo = chttpx.Field()
|
|
655
673
|
|
|
656
674
|
class Model2(Model):
|
|
657
|
-
bar =
|
|
675
|
+
bar = chttpx.Field()
|
|
658
676
|
|
|
659
677
|
client = client_class()
|
|
660
678
|
assert [*client.Model._fields.keys()] == ['foo']
|
|
@@ -663,10 +681,10 @@ def test_model_inheritance(client_class):
|
|
|
663
681
|
|
|
664
682
|
def test_relation_simple(client_class):
|
|
665
683
|
class Child(client_class.Model):
|
|
666
|
-
foo =
|
|
684
|
+
foo = chttpx.Field()
|
|
667
685
|
|
|
668
686
|
class Father(client_class.Model):
|
|
669
|
-
child =
|
|
687
|
+
child = chttpx.Related('Child')
|
|
670
688
|
|
|
671
689
|
client = client_class()
|
|
672
690
|
model = client.Father(dict(child=dict(foo=1)))
|
|
@@ -685,10 +703,10 @@ def test_relation_simple(client_class):
|
|
|
685
703
|
|
|
686
704
|
def test_relation_many(client_class):
|
|
687
705
|
class Child(client_class.Model):
|
|
688
|
-
foo =
|
|
706
|
+
foo = chttpx.Field()
|
|
689
707
|
|
|
690
708
|
class Father(client_class.Model):
|
|
691
|
-
children =
|
|
709
|
+
children = chttpx.Related('Child', many=True)
|
|
692
710
|
|
|
693
711
|
client = client_class()
|
|
694
712
|
model = client.Father(dict(children=[dict(foo=1)]))
|
|
@@ -714,8 +732,8 @@ async def test_python_expression(httpx_mock, client_class):
|
|
|
714
732
|
|
|
715
733
|
class Model(client_class.Model):
|
|
716
734
|
url_list = '/foo'
|
|
717
|
-
a =
|
|
718
|
-
b =
|
|
735
|
+
a = chttpx.Field()
|
|
736
|
+
b = chttpx.Field()
|
|
719
737
|
paginator = Paginator
|
|
720
738
|
|
|
721
739
|
def mock():
|
|
@@ -766,8 +784,8 @@ async def test_python_expression(httpx_mock, client_class):
|
|
|
766
784
|
async def test_expression_parameter(httpx_mock, client_class):
|
|
767
785
|
class Model(client_class.Model):
|
|
768
786
|
url_list = '/foo'
|
|
769
|
-
a =
|
|
770
|
-
b =
|
|
787
|
+
a = chttpx.Field()
|
|
788
|
+
b = chttpx.Field(parameter='b')
|
|
771
789
|
|
|
772
790
|
httpx_mock.add_response(url='http://lol/foo?b=1', json=dict(
|
|
773
791
|
items=[dict(a=1, b=1), dict(a=3, b=1)],
|
|
@@ -796,7 +814,7 @@ async def test_model_crud(httpx_mock, client_class):
|
|
|
796
814
|
@pytest.mark.asyncio
|
|
797
815
|
async def test_client_cli2(httpx_mock, client_class):
|
|
798
816
|
class Foo(client_class.Model):
|
|
799
|
-
id =
|
|
817
|
+
id = chttpx.Field()
|
|
800
818
|
url_list = '/foo'
|
|
801
819
|
|
|
802
820
|
assert client_class.cli.name == 'test'
|
|
@@ -837,14 +855,14 @@ async def test_object_command(httpx_mock, client_class):
|
|
|
837
855
|
))
|
|
838
856
|
def test_datetime_fmts(intern, extern, client_class):
|
|
839
857
|
class DtModel(client_class.Model):
|
|
840
|
-
dt =
|
|
858
|
+
dt = chttpx.DateTimeField()
|
|
841
859
|
model = client_class().DtModel(dict(dt=intern))
|
|
842
860
|
assert model.dt == extern
|
|
843
861
|
|
|
844
862
|
|
|
845
863
|
def test_datetime_fmt(client_class):
|
|
846
864
|
class DtModel(client_class.Model):
|
|
847
|
-
dt =
|
|
865
|
+
dt = chttpx.DateTimeField(fmt='%d/%m/%Y %H:%M:%S')
|
|
848
866
|
model = client_class().DtModel(dict(dt='13/02/2025 12:34:56'))
|
|
849
867
|
assert model.dt == datetime(2025, 2, 13, 12, 34, 56)
|
|
850
868
|
|
|
@@ -854,15 +872,15 @@ def test_datetime_fmt(client_class):
|
|
|
854
872
|
|
|
855
873
|
def test_datetime_error(client_class):
|
|
856
874
|
class DtModel(client_class.Model):
|
|
857
|
-
dt =
|
|
875
|
+
dt = chttpx.DateTimeField()
|
|
858
876
|
model = client_class().DtModel(dict(dt='13/024:56'))
|
|
859
|
-
with pytest.raises(
|
|
877
|
+
with pytest.raises(chttpx.FieldExternalizeError):
|
|
860
878
|
model.dt
|
|
861
879
|
|
|
862
880
|
|
|
863
881
|
def test_datetime_default_fmt(client_class):
|
|
864
882
|
class DtModel(client_class.Model):
|
|
865
|
-
dt =
|
|
883
|
+
dt = chttpx.DateTimeField()
|
|
866
884
|
model = client_class().DtModel()
|
|
867
885
|
model.dt = datetime(2025, 2, 13, 16, 9, 30)
|
|
868
886
|
assert model.data['dt'] == '2025-02-13T16:09:30.000000'
|
|
@@ -874,11 +892,11 @@ def test_datetime_default_fmt(client_class):
|
|
|
874
892
|
|
|
875
893
|
@pytest.mark.asyncio
|
|
876
894
|
async def test_mask_recursive(client_class, monkeypatch):
|
|
877
|
-
client = client_class(mask=
|
|
895
|
+
client = client_class(mask=chttpx.Mask(['scrt', 'password']))
|
|
878
896
|
client.client.send = mock.AsyncMock()
|
|
879
897
|
|
|
880
898
|
log = mock.Mock()
|
|
881
|
-
monkeypatch.setattr(
|
|
899
|
+
monkeypatch.setattr(chttpx, 'log', log)
|
|
882
900
|
response = httpx.Response(
|
|
883
901
|
status_code=200,
|
|
884
902
|
content='{"pub": 1, "foo": [{"scrt": "pass"}]}',
|
|
@@ -908,11 +926,11 @@ async def test_mask_recursive(client_class, monkeypatch):
|
|
|
908
926
|
'key', ('json', 'data'),
|
|
909
927
|
)
|
|
910
928
|
async def test_mask_logs(client_class, key, monkeypatch):
|
|
911
|
-
client = client_class(mask=
|
|
929
|
+
client = client_class(mask=chttpx.Mask(['scrt', 'password']))
|
|
912
930
|
client.client.send = mock.AsyncMock()
|
|
913
931
|
|
|
914
932
|
log = mock.Mock()
|
|
915
|
-
monkeypatch.setattr(
|
|
933
|
+
monkeypatch.setattr(chttpx, 'log', log)
|
|
916
934
|
response = httpx.Response(
|
|
917
935
|
status_code=200,
|
|
918
936
|
content='{"pub": 1, "scrt": "pass"}',
|
|
@@ -948,26 +966,26 @@ async def test_mask_exceptions(client_class):
|
|
|
948
966
|
response.request = httpx.Request('POST', '/', json=dict(a=1, b=2))
|
|
949
967
|
client.mask.keys.add('a')
|
|
950
968
|
client.mask.keys.add('c')
|
|
951
|
-
error =
|
|
969
|
+
error = chttpx.ResponseError(client, response, 1)
|
|
952
970
|
expected = "\n\x1b[0m\x1b[1mPOST /\x1b[0m\n\x1b[94ma\x1b[39;49;00m:\x1b[37m \x1b[39;49;00m\x1b[33m'\x1b[39;49;00m\x1b[33m***MASKED***\x1b[39;49;00m\x1b[33m'\x1b[39;49;00m\x1b[37m\x1b[39;49;00m\n\x1b[94mb\x1b[39;49;00m:\x1b[37m \x1b[39;49;00m2\x1b[37m\x1b[39;49;00m\n\n\x1b[1mHTTP 218\x1b[0m\n\x1b[94mc\x1b[39;49;00m:\x1b[37m \x1b[39;49;00m\x1b[33m'\x1b[39;49;00m\x1b[33m***MASKED***\x1b[39;49;00m\x1b[33m'\x1b[39;49;00m\x1b[37m\x1b[39;49;00m\n\x1b[94md\x1b[39;49;00m:\x1b[37m \x1b[39;49;00m4\x1b[37m\x1b[39;49;00m\n" # noqa
|
|
953
971
|
assert str(error) == expected
|
|
954
972
|
|
|
955
973
|
# this needs to work with form data too
|
|
956
974
|
response = httpx.Response(status_code=218, content='{"c": 3, "d": 4}')
|
|
957
975
|
response.request = httpx.Request('POST', '/', data=dict(a=1, b=2))
|
|
958
|
-
client.mask =
|
|
959
|
-
error =
|
|
976
|
+
client.mask = chttpx.Mask(['a', 'c'])
|
|
977
|
+
error = chttpx.ResponseError(client, response, 1)
|
|
960
978
|
expected = "\n\x1b[0m\x1b[1mPOST /\x1b[0m\n\x1b[94ma\x1b[39;49;00m:\x1b[37m \x1b[39;49;00m\x1b[33m'\x1b[39;49;00m\x1b[33m***MASKED***\x1b[39;49;00m\x1b[33m'\x1b[39;49;00m\x1b[37m\x1b[39;49;00m\n\x1b[94mb\x1b[39;49;00m:\x1b[37m \x1b[39;49;00m\x1b[33m'\x1b[39;49;00m\x1b[33m2\x1b[39;49;00m\x1b[33m'\x1b[39;49;00m\x1b[37m\x1b[39;49;00m\n\n\x1b[1mHTTP 218\x1b[0m\n\x1b[94mc\x1b[39;49;00m:\x1b[37m \x1b[39;49;00m\x1b[33m'\x1b[39;49;00m\x1b[33m***MASKED***\x1b[39;49;00m\x1b[33m'\x1b[39;49;00m\x1b[37m\x1b[39;49;00m\n\x1b[94md\x1b[39;49;00m:\x1b[37m \x1b[39;49;00m4\x1b[37m\x1b[39;49;00m\n" # noqa
|
|
961
979
|
assert str(error) == expected
|
|
962
980
|
|
|
963
981
|
|
|
964
982
|
@pytest.mark.asyncio
|
|
965
983
|
async def test_request_mask(client_class, monkeypatch):
|
|
966
|
-
client = client_class(mask=
|
|
984
|
+
client = client_class(mask=chttpx.Mask(['password']))
|
|
967
985
|
client.client.send = mock.AsyncMock()
|
|
968
986
|
|
|
969
987
|
log = mock.Mock()
|
|
970
|
-
monkeypatch.setattr(
|
|
988
|
+
monkeypatch.setattr(chttpx, 'log', log)
|
|
971
989
|
response = httpx.Response(
|
|
972
990
|
status_code=200,
|
|
973
991
|
content='{"pub": 1, "scrt": "pass"}',
|
|
@@ -998,7 +1016,7 @@ async def test_log_content(client_class, monkeypatch):
|
|
|
998
1016
|
client = client_class()
|
|
999
1017
|
client.client.send = mock.AsyncMock()
|
|
1000
1018
|
log = mock.Mock()
|
|
1001
|
-
monkeypatch.setattr(
|
|
1019
|
+
monkeypatch.setattr(chttpx, 'log', log)
|
|
1002
1020
|
response = httpx.Response(status_code=200, content='lol:]bar')
|
|
1003
1021
|
response.request = httpx.Request('POST', '/')
|
|
1004
1022
|
client.client.send.return_value = response
|
|
@@ -1019,7 +1037,7 @@ async def test_log_quiet(client_class, monkeypatch):
|
|
|
1019
1037
|
client = client_class()
|
|
1020
1038
|
client.client.send = mock.AsyncMock()
|
|
1021
1039
|
log = mock.Mock()
|
|
1022
|
-
monkeypatch.setattr(
|
|
1040
|
+
monkeypatch.setattr(chttpx, 'log', log)
|
|
1023
1041
|
response = httpx.Response(status_code=200, content='[1]')
|
|
1024
1042
|
response.request = httpx.Request('GET', '/')
|
|
1025
1043
|
client.client.send.return_value = response
|
|
@@ -1047,8 +1065,8 @@ def test_class_override(client_class):
|
|
|
1047
1065
|
@pytest.mark.asyncio
|
|
1048
1066
|
async def test_save(client_class, httpx_mock):
|
|
1049
1067
|
class TestModel(client_class.Model):
|
|
1050
|
-
id =
|
|
1051
|
-
foo =
|
|
1068
|
+
id = chttpx.Field()
|
|
1069
|
+
foo = chttpx.Field()
|
|
1052
1070
|
|
|
1053
1071
|
client = client_class()
|
|
1054
1072
|
model = client.TestModel(id=1, foo='bar')
|
|
@@ -1081,22 +1099,22 @@ async def test_save(client_class, httpx_mock):
|
|
|
1081
1099
|
|
|
1082
1100
|
def test_id_value(client_class):
|
|
1083
1101
|
class TestModel(client_class.Model):
|
|
1084
|
-
id =
|
|
1102
|
+
id = chttpx.Field()
|
|
1085
1103
|
assert client_class().TestModel(id=1).id_value == 1
|
|
1086
1104
|
|
|
1087
1105
|
class TestModel2(client_class.Model):
|
|
1088
|
-
bar =
|
|
1106
|
+
bar = chttpx.Field()
|
|
1089
1107
|
id_field = 'bar'
|
|
1090
1108
|
assert client_class().TestModel2(bar=1).id_value == 1
|
|
1091
1109
|
|
|
1092
1110
|
|
|
1093
1111
|
@pytest.mark.asyncio
|
|
1094
1112
|
async def test_debug(client_class, monkeypatch):
|
|
1095
|
-
client = client_class(mask=
|
|
1113
|
+
client = client_class(mask=chttpx.Mask(['scrt', 'password']), debug=True)
|
|
1096
1114
|
client.client.send = mock.AsyncMock()
|
|
1097
1115
|
|
|
1098
1116
|
log = mock.Mock()
|
|
1099
|
-
monkeypatch.setattr(
|
|
1117
|
+
monkeypatch.setattr(chttpx, 'log', log)
|
|
1100
1118
|
|
|
1101
1119
|
response = httpx.Response(
|
|
1102
1120
|
status_code=200,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|