This repository has been archived by the owner on Feb 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #185 from gamechanger/ae-specs_refactor
Ae specs refactor
- Loading branch information
Showing
9 changed files
with
88 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from copy import deepcopy | ||
|
||
# This is build on top of Schemer's functionality | ||
class DustySchema(object): | ||
def __init__(self, schema, document): | ||
schema.validate(document) | ||
self._document = deepcopy(document) | ||
schema.apply_defaults(self._document) | ||
|
||
def __getitem__(self, name): | ||
return self._document[name] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
from schemer import Schema, Array | ||
|
||
bundle_schema = Schema({ | ||
'description': {'type': basestring}, | ||
'description': {'type': basestring, 'default': ''}, | ||
'apps': {'type': Array(basestring), 'required': True} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
from schemer import Schema, Array | ||
|
||
depends_schema = Schema({ | ||
'libs': {'type': Array(basestring)} | ||
'libs': {'type': Array(basestring), 'default': []} | ||
}) | ||
|
||
lib_schema = Schema({ | ||
'repo': {'type': basestring, 'required': True}, | ||
'mount': {'type': basestring}, | ||
'install': {'type': basestring}, | ||
'depends': {'type': depends_schema} | ||
'mount': {'type': basestring, 'default': ''}, | ||
'install': {'type': basestring, 'default': ''}, | ||
'depends': {'type': depends_schema, 'default': {}} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from unittest import TestCase | ||
from schemer import Schema, Array, ValidationException | ||
from dusty.schemas.base_schema_class import DustySchema | ||
|
||
|
||
class TestDustySchemaClass(TestCase): | ||
def setUp(self): | ||
self.base_schema = Schema({'street': {'type': basestring}, | ||
'house_number': {'type': int, 'default': 1}}) | ||
self.bigger_schema = Schema({'address': {'type': self.base_schema, 'default': {}}, | ||
'first_name': {'type': basestring, 'required': True}, | ||
'last_name': {'type': basestring, 'default': 'johnson'}}) | ||
|
||
def test_init_invalid_doc(self): | ||
doc = {'street': 'dogstoon', | ||
'house_number': '1'} | ||
with self.assertRaises(ValidationException): | ||
DustySchema(self.base_schema, doc) | ||
|
||
def test_valid_doc(self): | ||
doc = {'street': 'dogstoon', | ||
'house_number': 1} | ||
dusty_schema = DustySchema(self.base_schema, doc) | ||
self.assertEquals(dusty_schema['street'], 'dogstoon') | ||
self.assertEquals(dusty_schema['house_number'], 1) | ||
|
||
def test_setting_defaults(self): | ||
doc = {'street': 'dogstoon'} | ||
dusty_schema = DustySchema(self.base_schema, doc) | ||
self.assertEquals(dusty_schema['street'], 'dogstoon') | ||
self.assertEquals(dusty_schema['house_number'], 1) | ||
|
||
def test_setting_defaults_more_complicated_1(self): | ||
doc = {'first_name': 'dusty'} | ||
dusty_schema = DustySchema(self.bigger_schema, doc) | ||
self.assertEquals(dusty_schema['first_name'], 'dusty') | ||
self.assertEquals(dusty_schema['last_name'], 'johnson') | ||
self.assertEquals(dusty_schema['address'], {'house_number': 1}) | ||
|
||
def test_setting_defaults_more_complicated_2(self): | ||
doc = {'first_name': 'dusty', | ||
'address': {'street': 'dogstoon'}} | ||
dusty_schema = DustySchema(self.bigger_schema, doc) | ||
self.assertEquals(dusty_schema['address']['street'], 'dogstoon') | ||
self.assertEquals(dusty_schema['address']['house_number'], 1) |