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.
Files changed (45) hide show
  1. {cli2-3.3.6/cli2.egg-info → cli2-3.3.7}/PKG-INFO +1 -1
  2. {cli2-3.3.6 → cli2-3.3.7}/cli2/client.py +14 -3
  3. {cli2-3.3.6 → cli2-3.3.7}/cli2/test_client.py +24 -1
  4. {cli2-3.3.6 → cli2-3.3.7/cli2.egg-info}/PKG-INFO +1 -1
  5. {cli2-3.3.6 → cli2-3.3.7}/setup.py +1 -1
  6. {cli2-3.3.6 → cli2-3.3.7}/MANIFEST.in +0 -0
  7. {cli2-3.3.6 → cli2-3.3.7}/README.rst +0 -0
  8. {cli2-3.3.6 → cli2-3.3.7}/classifiers.txt +0 -0
  9. {cli2-3.3.6 → cli2-3.3.7}/cli2/__init__.py +0 -0
  10. {cli2-3.3.6 → cli2-3.3.7}/cli2/argument.py +0 -0
  11. {cli2-3.3.6 → cli2-3.3.7}/cli2/asyncio.py +0 -0
  12. {cli2-3.3.6 → cli2-3.3.7}/cli2/cli.py +0 -0
  13. {cli2-3.3.6 → cli2-3.3.7}/cli2/colors.py +0 -0
  14. {cli2-3.3.6 → cli2-3.3.7}/cli2/command.py +0 -0
  15. {cli2-3.3.6 → cli2-3.3.7}/cli2/configuration.py +0 -0
  16. {cli2-3.3.6 → cli2-3.3.7}/cli2/decorators.py +0 -0
  17. {cli2-3.3.6 → cli2-3.3.7}/cli2/display.py +0 -0
  18. {cli2-3.3.6 → cli2-3.3.7}/cli2/entry_point.py +0 -0
  19. {cli2-3.3.6 → cli2-3.3.7}/cli2/example_client.py +0 -0
  20. {cli2-3.3.6 → cli2-3.3.7}/cli2/example_client_complex.py +0 -0
  21. {cli2-3.3.6 → cli2-3.3.7}/cli2/example_nesting.py +0 -0
  22. {cli2-3.3.6 → cli2-3.3.7}/cli2/example_obj.py +0 -0
  23. {cli2-3.3.6 → cli2-3.3.7}/cli2/group.py +0 -0
  24. {cli2-3.3.6 → cli2-3.3.7}/cli2/logging.py +0 -0
  25. {cli2-3.3.6 → cli2-3.3.7}/cli2/node.py +0 -0
  26. {cli2-3.3.6 → cli2-3.3.7}/cli2/overrides.py +0 -0
  27. {cli2-3.3.6 → cli2-3.3.7}/cli2/sphinx.py +0 -0
  28. {cli2-3.3.6 → cli2-3.3.7}/cli2/table.py +0 -0
  29. {cli2-3.3.6 → cli2-3.3.7}/cli2/test.py +0 -0
  30. {cli2-3.3.6 → cli2-3.3.7}/cli2/test_cli.py +0 -0
  31. {cli2-3.3.6 → cli2-3.3.7}/cli2/test_command.py +0 -0
  32. {cli2-3.3.6 → cli2-3.3.7}/cli2/test_configuration.py +0 -0
  33. {cli2-3.3.6 → cli2-3.3.7}/cli2/test_decorators.py +0 -0
  34. {cli2-3.3.6 → cli2-3.3.7}/cli2/test_display.py +0 -0
  35. {cli2-3.3.6 → cli2-3.3.7}/cli2/test_entry_point.py +0 -0
  36. {cli2-3.3.6 → cli2-3.3.7}/cli2/test_group.py +0 -0
  37. {cli2-3.3.6 → cli2-3.3.7}/cli2/test_inject.py +0 -0
  38. {cli2-3.3.6 → cli2-3.3.7}/cli2/test_node.py +0 -0
  39. {cli2-3.3.6 → cli2-3.3.7}/cli2/test_table.py +0 -0
  40. {cli2-3.3.6 → cli2-3.3.7}/cli2.egg-info/SOURCES.txt +0 -0
  41. {cli2-3.3.6 → cli2-3.3.7}/cli2.egg-info/dependency_links.txt +0 -0
  42. {cli2-3.3.6 → cli2-3.3.7}/cli2.egg-info/entry_points.txt +0 -0
  43. {cli2-3.3.6 → cli2-3.3.7}/cli2.egg-info/requires.txt +0 -0
  44. {cli2-3.3.6 → cli2-3.3.7}/cli2.egg-info/top_level.txt +0 -0
  45. {cli2-3.3.6 → cli2-3.3.7}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cli2
3
- Version: 3.3.6
3
+ Version: 3.3.7
4
4
  Summary: image:: https://yourlabs.io/oss/cli2/badges/master/pipeline.svg
5
5
  Home-page: https://yourlabs.io/oss/cli2
6
6
  Author: James Pic
@@ -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
- return data.data
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
- return getattr(obj.client, self.model)(value)
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 test_relation():
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):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cli2
3
- Version: 3.3.6
3
+ Version: 3.3.7
4
4
  Summary: image:: https://yourlabs.io/oss/cli2/badges/master/pipeline.svg
5
5
  Home-page: https://yourlabs.io/oss/cli2
6
6
  Author: James Pic
@@ -3,7 +3,7 @@ from setuptools import setup
3
3
 
4
4
  setup(
5
5
  name='cli2',
6
- version='3.3.6',
6
+ version='3.3.7',
7
7
  setup_requires='setupmeta',
8
8
  install_requires=[
9
9
  'docstring_parser',
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