cli2 3.3.6__tar.gz → 3.3.7__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-3.3.6/cli2.egg-info → cli2-3.3.7}/PKG-INFO +1 -1
- {cli2-3.3.6 → cli2-3.3.7}/cli2/client.py +14 -3
- {cli2-3.3.6 → cli2-3.3.7}/cli2/test_client.py +24 -1
- {cli2-3.3.6 → cli2-3.3.7/cli2.egg-info}/PKG-INFO +1 -1
- {cli2-3.3.6 → cli2-3.3.7}/setup.py +1 -1
- {cli2-3.3.6 → cli2-3.3.7}/MANIFEST.in +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/README.rst +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/classifiers.txt +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2/__init__.py +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2/argument.py +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2/asyncio.py +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2/cli.py +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2/colors.py +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2/command.py +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2/configuration.py +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2/decorators.py +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2/display.py +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2/entry_point.py +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2/example_client.py +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2/example_client_complex.py +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2/example_nesting.py +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2/example_obj.py +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2/group.py +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2/logging.py +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2/node.py +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2/overrides.py +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2/sphinx.py +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2/table.py +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2/test.py +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2/test_cli.py +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2/test_command.py +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2/test_configuration.py +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2/test_decorators.py +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2/test_display.py +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2/test_entry_point.py +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2/test_group.py +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2/test_inject.py +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2/test_node.py +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2/test_table.py +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2.egg-info/SOURCES.txt +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2.egg-info/dependency_links.txt +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2.egg-info/entry_points.txt +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2.egg-info/requires.txt +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/cli2.egg-info/top_level.txt +0 -0
- {cli2-3.3.6 → cli2-3.3.7}/setup.cfg +0 -0
|
@@ -597,22 +597,33 @@ class Related(MutableField):
|
|
|
597
597
|
.. py:attribute:: model
|
|
598
598
|
|
|
599
599
|
*STRING* name of the related model class.
|
|
600
|
+
|
|
601
|
+
.. py:attribute:: many
|
|
602
|
+
|
|
603
|
+
Set this to True if you're expecting a list of models in the field.
|
|
600
604
|
"""
|
|
601
|
-
def __init__(self, model, *args, **kwargs):
|
|
605
|
+
def __init__(self, model, many=False, *args, **kwargs):
|
|
602
606
|
super().__init__(*args, **kwargs)
|
|
603
607
|
self.model = model
|
|
608
|
+
self.many = many
|
|
604
609
|
|
|
605
610
|
def internalize(self, obj, data):
|
|
606
611
|
"""
|
|
607
612
|
Return the related object's data.
|
|
608
613
|
"""
|
|
609
|
-
|
|
614
|
+
if not self.many:
|
|
615
|
+
return data.data
|
|
616
|
+
|
|
617
|
+
return [item.data for item in data]
|
|
610
618
|
|
|
611
619
|
def externalize(self, obj, value):
|
|
612
620
|
"""
|
|
613
621
|
Instanciate the related model class with the value.
|
|
614
622
|
"""
|
|
615
|
-
|
|
623
|
+
model_class = getattr(obj.client, self.model)
|
|
624
|
+
if not self.many:
|
|
625
|
+
return model_class(value)
|
|
626
|
+
return [model_class(item) for item in value]
|
|
616
627
|
|
|
617
628
|
|
|
618
629
|
class ModelCommand(Command):
|
|
@@ -393,7 +393,7 @@ def test_model_inheritance():
|
|
|
393
393
|
assert [*client.Model2._fields.keys()] == ['bar', 'foo']
|
|
394
394
|
|
|
395
395
|
|
|
396
|
-
def
|
|
396
|
+
def test_relation_simple():
|
|
397
397
|
class Child(Client.Model):
|
|
398
398
|
foo = cli2.Field()
|
|
399
399
|
|
|
@@ -415,6 +415,29 @@ def test_relation():
|
|
|
415
415
|
assert model.data['child']['foo'] == 3
|
|
416
416
|
|
|
417
417
|
|
|
418
|
+
def test_relation_many():
|
|
419
|
+
class Child(Client.Model):
|
|
420
|
+
foo = cli2.Field()
|
|
421
|
+
|
|
422
|
+
class Father(Client.Model):
|
|
423
|
+
children = cli2.Related('Child', many=True)
|
|
424
|
+
|
|
425
|
+
client = Client()
|
|
426
|
+
model = client.Father(dict(children=[dict(foo=1)]))
|
|
427
|
+
assert model.children[0].foo == 1
|
|
428
|
+
assert model.data['children'][0]['foo'] == 1
|
|
429
|
+
|
|
430
|
+
model.children.append(client.Child(foo=2))
|
|
431
|
+
assert model.data['children'][1]['foo'] == 2
|
|
432
|
+
assert model.children[1].foo == 2
|
|
433
|
+
|
|
434
|
+
new = [client.Child(dict(foo=3))]
|
|
435
|
+
model.children = new
|
|
436
|
+
assert len(model.children) == 1
|
|
437
|
+
assert model.children[0].foo == 3
|
|
438
|
+
assert model.data['children'][0]['foo'] == 3
|
|
439
|
+
|
|
440
|
+
|
|
418
441
|
@pytest.mark.asyncio
|
|
419
442
|
async def test_python_expression(httpx_mock):
|
|
420
443
|
class Model(Client.Model):
|
|
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
|