Skip to content

Commit

Permalink
Merge pull request #55 from Carrene/develop
Browse files Browse the repository at this point in the history
Ignoring protected metadata fields from model object
  • Loading branch information
pylover committed Sep 26, 2018
2 parents b33c2f2 + c023c59 commit 55dffd5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
8 changes: 7 additions & 1 deletion mockup-server/mockupserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ class Resource(ModifiedMixin, OrderingMixin, PaginationMixin, FilteringMixin, De
pattern='[a-zA-Z0-9]{3,}',
min_length=3
)
password = Field(
Unicode(30),
protected=True,
nullable=False,
default='123456'
)


class MockupAuthenticator(StatefulAuthenticator):
Expand Down Expand Up @@ -209,7 +215,7 @@ def insert_basedata(self):
def insert_mockup(self):
for i in range(1, 11):
# noinspection PyArgumentList
DBSession.add(Resource(id=i, title='resource%s' % i))
DBSession.add(Resource(id=i, title='resource%s' % i, password='password%s' % i))
DBSession.commit()

def begin_request(self):
Expand Down
4 changes: 4 additions & 0 deletions src/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ export default function createModelClass (name, options, client, metadata) {
this.__status__ = status
this.__hash__ = 0
for (let field of Object.keys(metadata.fields)) {
// Ignoring protected items of metadata from model
if (metadata.fields[field].protected) {
continue
}
this[field] = metadata.fields[field].default
}
if (values) {
Expand Down
7 changes: 7 additions & 0 deletions tests/metadata.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@ describe('Metadata', function () {
done()
})
})
it('Including protected field', function (done) {
let c = new MockupClient()
c.loadMetadata({'Resource': {url: 'resources'}}).then((resps) => {
expect(c.metadata.models.Resource.fields.password.protected).toBeTruthy()
done()
})
})
})

0 comments on commit 55dffd5

Please sign in to comment.