Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
Use deduced_required value for config.push
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindeide committed Jun 4, 2020
1 parent 29cc91b commit c4df2a1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
2 changes: 2 additions & 0 deletions configsuite/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def __init__(
self._valid = True
self._errors = ()
self._snapshot = None
self._deduce_required = deduce_required

self._cached_merged_config = self._build_merged_config()
if self._readable:
Expand Down Expand Up @@ -158,6 +159,7 @@ def push(self, raw_config):
layers=self._layers,
extract_validation_context=self._extract_validation_context,
extract_transformation_context=self._extract_transformation_context,
deduce_required=self._deduce_required,
)

@property
Expand Down
44 changes: 44 additions & 0 deletions tests/test_push_deduced_required.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import unittest

import configsuite

from . import data


class TestPush(unittest.TestCase):
def assertEqualSnapshots(self, first, second):
self.assertEqual(first.heroes, second.heroes)
self.assertEqual(sorted(first.villains), sorted(second.villains))

def test_push_deduced_required(self):
schema = data.hero.build_schema()

heroes = {
"heroes": [
{"name": "Batman", "strength": 10},
{"name": "Flash", "strength": 12},
{"name": "Dirk Gently", "strength": 7},
]
}

villains = {"villains": {"Eobard Thawne": 11, "Lux": 3}}

hero_config = configsuite.ConfigSuite(heroes, schema, deduce_required=True)
self.assertTrue(hero_config.valid)
hero_villains_config = hero_config.push(villains)
self.assertTrue(hero_villains_config.valid)

combined = {
"heroes": [
{"name": "Batman", "strength": 10},
{"name": "Flash", "strength": 12},
{"name": "Dirk Gently", "strength": 7},
],
"villains": {"Eobard Thawne": 11, "Lux": 3},
}
combined_config = configsuite.ConfigSuite(combined, schema)
self.assertTrue(combined_config.valid)

self.assertEqualSnapshots(
combined_config.snapshot, hero_villains_config.snapshot
)

0 comments on commit c4df2a1

Please sign in to comment.