Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-advanced-user-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-advanced-user-tools
Commits
9fdfa254
Commit
9fdfa254
authored
1 year ago
by
Florian Spreckelsen
Browse files
Options
Downloads
Patches
Plain Diff
TST: Begin unit tests for json schema exporter
parent
4c27d928
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!89
ENH: JsonSchemaExporter accepts do_not_create parameter.
,
!80
F simple schema export
Pipeline
#42096
failed
1 year ago
Stage: setup
Stage: cert
Stage: style
Stage: unittest
Stage: integrationtest
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/caosadvancedtools/json_schema_exporter.py
+3
-5
3 additions, 5 deletions
src/caosadvancedtools/json_schema_exporter.py
unittests/test_json_schema_exporter.py
+53
-0
53 additions, 0 deletions
unittests/test_json_schema_exporter.py
with
56 additions
and
5 deletions
src/caosadvancedtools/json_schema_exporter.py
+
3
−
5
View file @
9fdfa254
...
...
@@ -20,8 +20,6 @@
# with this program. If not, see <https://www.gnu.org/licenses/>.
#
import
json
import
linkahead
as
db
...
...
@@ -43,7 +41,7 @@ def _make_prop_from_prop(prop):
return
_make_text_property
(
prop
.
description
,
"
date-time
"
)
json_prop
=
{}
if
prop
.
description
#
if prop.description
def
_make_text_property
(
description
=
""
,
text_format
=
None
,
text_pattern
=
None
):
...
...
@@ -62,7 +60,7 @@ def _make_text_property(description="", text_format=None, text_pattern=None):
def
recordtype_to_json_schema
(
rt
:
db
.
RecordType
,
additional_properties
:
bool
=
True
,
name_and_description_in_properties
:
bool
=
Tru
e
):
name_and_description_in_properties
:
bool
=
Fals
e
):
"""
Create a jsonschema from a given RecordType that can be used, e.g., to
validate a json specifying a record of the given type.
...
...
@@ -75,7 +73,7 @@ def recordtype_to_json_schema(rt: db.RecordType, additional_properties: bool = T
schema. Optional, default is True.
name_and_description_in_properties : bool, optional
Whether to include name and description in the `properties` section of
the schema to be exported. Optional, default is
Tru
e.
the schema to be exported. Optional, default is
Fals
e.
Returns
-------
...
...
This diff is collapsed.
Click to expand it.
unittests/test_json_schema_exporter.py
0 → 100644
+
53
−
0
View file @
9fdfa254
#!/usr/bin/env python
# encoding: utf-8
#
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2023 Indiscale GmbH <info@indiscale.com>
# Copyright (C) 2023 Florian Spreckelsen <f.spreckelsen@indiscale.com>
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <https://www.gnu.org/licenses/>.
#
import
linkahead
as
db
from
caosadvancedtools.json_schema_exporter
import
recordtype_to_json_schema
as
rtjs
def
test_empty_rt
():
rt
=
db
.
RecordType
(
name
=
"
Test
"
,
description
=
"
descr
"
)
schema
=
rtjs
(
rt
)
assert
schema
[
"
title
"
]
==
rt
.
name
assert
schema
[
"
description
"
]
==
rt
.
description
assert
len
(
schema
[
"
properties
"
])
==
0
assert
len
(
schema
[
"
required
"
])
==
0
schema
=
rtjs
(
rt
,
additional_properties
=
False
)
assert
schema
[
"
title
"
]
==
rt
.
name
assert
schema
[
"
description
"
]
==
rt
.
description
assert
len
(
schema
[
"
properties
"
])
==
0
assert
len
(
schema
[
"
required
"
])
==
0
assert
schema
[
"
additionalProperties
"
]
is
False
schema
=
rtjs
(
rt
,
name_and_description_in_properties
=
True
)
assert
len
(
schema
[
"
properties
"
])
==
2
assert
"
name
"
in
schema
[
"
properties
"
]
assert
"
description
"
in
schema
[
"
properties
"
]
assert
schema
[
"
properties
"
][
"
name
"
][
"
type
"
]
==
"
string
"
assert
schema
[
"
properties
"
][
"
description
"
][
"
type
"
]
==
"
string
"
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment