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
97be7ef9
Commit
97be7ef9
authored
1 year ago
by
Florian Spreckelsen
Browse files
Options
Downloads
Patches
Plain Diff
TST: Extend unittest
parent
894c7637
No related branches found
No related tags found
2 merge requests
!89
ENH: JsonSchemaExporter accepts do_not_create parameter.
,
!81
F schema export references
Pipeline
#42785
passed
1 year ago
Stage: setup
Stage: cert
Stage: style
Stage: unittest
Stage: integrationtest
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
unittests/test_json_schema_exporter.py
+111
-1
111 additions, 1 deletion
unittests/test_json_schema_exporter.py
with
111 additions
and
1 deletion
unittests/test_json_schema_exporter.py
+
111
−
1
View file @
97be7ef9
...
...
@@ -42,10 +42,23 @@ def _mock_execute_query(query_string, unique=False, **kwargs):
])
all_records
.
extend
(
other_type_records
)
referencing_type_rt
=
db
.
RecordType
(
name
=
"
ReferencingType
"
)
referencing_type_records
=
db
.
Container
().
extend
([
db
.
Record
(
id
=
103
).
add_parent
(
referencing_type_rt
),
db
.
Record
(
id
=
104
,
name
=
"
referencing
"
).
add_parent
(
referencing_type_rt
)
])
all_records
.
extend
(
referencing_type_records
)
all_files
.
append
(
db
.
File
(
id
=
105
,
name
=
"
GenericFile.txt
"
))
if
query_string
==
"
SELECT name, id FROM RECORD
'
OtherType
'"
:
return
other_type_records
elif
query_string
==
"
FIND RECORDTYPE WITH name=
'
OtherType
'"
and
unique
is
True
:
return
other_type_rt
elif
query_string
==
"
SELECT name, id FROM RECORD
'
ReferencingType
'"
:
return
referencing_type_records
elif
query_string
==
"
FIND RECORDTYPE WITH name=
'
ReferencingType
'"
and
unique
is
True
:
return
referencing_type_rt
elif
query_string
==
"
SELECT name, id FROM RECORD
"
:
return
all_records
elif
query_string
==
"
SELECT name, id FROM FILE
"
:
...
...
@@ -289,6 +302,25 @@ def test_rt_with_references():
db
.
execute_query
(
"
SELECT name, id FROM FILE
"
))
assert
"
oneOf
"
not
in
props
[
"
RefProp
"
]
example
=
{
"
RefProp
"
:
"
101, otherB
"
}
validate
(
example
,
schema
)
example
=
{
"
RefProp
"
:
"
23, I don
'
t exist
"
}
with
raises
(
ValidationError
):
# Wrong enum value
validate
(
example
,
schema
)
example
=
{
"
RefProp
"
:
{
"
IntegerProp
"
:
12
}
}
with
raises
(
ValidationError
):
# Can't have objects in generic references
validate
(
example
,
schema
)
rt
=
db
.
RecordType
()
rt
.
add_property
(
name
=
"
RefProp
"
,
datatype
=
"
OtherType
"
)
rt
.
add_property
(
name
=
"
OtherTextProp
"
,
datatype
=
db
.
TEXT
)
...
...
@@ -321,6 +353,19 @@ def test_rt_with_references():
assert
"
OtherTextProp
"
in
props
assert
props
[
"
OtherTextProp
"
][
"
type
"
]
==
"
string
"
example
=
{
"
RefProp
"
:
{
"
IntegerProp
"
:
12
}
}
validate
(
example
,
schema
)
example
=
{
"
RefProp
"
:
"
101, otherB
"
,
"
OtherTextProp
"
:
"
something
"
}
validate
(
example
,
schema
)
rt
=
db
.
RecordType
(
name
=
"
TestType
"
,
description
=
"
Some description
"
)
rt
.
add_property
(
name
=
"
RefProp
"
,
datatype
=
db
.
LIST
(
db
.
REFERENCE
),
description
=
"
I
'
m a list of references.
"
)
...
...
@@ -343,10 +388,75 @@ def test_rt_with_references():
assert
"
oneOf
"
not
in
items
assert
"
description
"
not
in
items
example
=
{
"
RefProp
"
:
"
101, otherB
"
}
with
raises
(
ValidationError
):
# Should be list but isn't
validate
(
example
,
schema
)
example
=
{
"
RefProp
"
:
[
"
101, otherB
"
]
}
validate
(
example
,
schema
)
example
=
{
"
RefProp
"
:
[
"
101, otherB
"
,
"
102
"
,
"
104, referencing
"
]
}
validate
(
example
,
schema
)
rt
=
db
.
RecordType
()
rt
.
add_property
(
name
=
"
RefProp
"
,
datatype
=
db
.
LIST
(
"
OtherType
"
))
schema
=
rtjs
(
rt
)
schema
=
rtjs
(
rt
,
additional_properties
=
False
,
name_and_description_in_properties
=
True
)
assert
schema
[
"
additionalProperties
"
]
is
False
assert
"
name
"
in
schema
[
"
properties
"
]
assert
schema
[
"
properties
"
][
"
name
"
][
"
type
"
]
==
"
string
"
assert
"
description
"
in
schema
[
"
properties
"
]
assert
schema
[
"
properties
"
][
"
description
"
][
"
type
"
]
==
"
string
"
assert
"
RefProp
"
in
schema
[
"
properties
"
]
assert
schema
[
"
properties
"
][
"
RefProp
"
][
"
type
"
]
==
"
array
"
assert
"
additionalProperties
"
not
in
schema
[
"
properties
"
][
"
RefProp
"
]
assert
"
items
"
in
schema
[
"
properties
"
][
"
RefProp
"
]
items
=
schema
[
"
properties
"
][
"
RefProp
"
][
"
items
"
]
assert
"
oneOf
"
in
items
assert
len
(
items
[
"
oneOf
"
])
==
2
# same as above, we can't rely on the order
enum_index
=
0
if
"
enum
"
not
in
items
[
"
oneOf
"
][
enum_index
]:
enum_index
=
1
-
enum_index
assert
"
enum
"
in
items
[
"
oneOf
"
][
enum_index
]
assert
isinstance
(
items
[
"
oneOf
"
][
enum_index
][
"
enum
"
],
list
)
assert
len
(
items
[
"
oneOf
"
][
enum_index
][
"
enum
"
])
==
3
assert
"
100, otherA
"
in
items
[
"
oneOf
"
][
enum_index
][
"
enum
"
]
assert
"
101, otherB
"
in
items
[
"
oneOf
"
][
enum_index
][
"
enum
"
]
assert
"
102
"
in
items
[
"
oneOf
"
][
enum_index
][
"
enum
"
]
other_type
=
items
[
"
oneOf
"
][
1
-
enum_index
]
assert
other_type
[
"
type
"
]
==
"
object
"
assert
other_type
[
"
additionalProperties
"
]
is
False
assert
"
IntegerProp
"
in
other_type
[
"
properties
"
]
assert
len
(
other_type
[
"
required
"
])
==
1
assert
"
IntegerProp
"
in
other_type
[
"
required
"
]
example
=
{
"
RefProp
"
:
[
"
101, otherB
"
,
"
102
"
,
"
104, referencing
"
]
}
with
raises
(
ValidationError
):
# Wrong value in enum
validate
(
example
,
schema
)
example
=
{
"
RefProp
"
:
[{
"
IntegerProp
"
:
12
}]
}
validate
(
example
,
schema
)
example
=
{
"
RefProp
"
:
[{
"
IntegerProp
"
:
12
,
"
additionalProperty
"
:
"
something
"
}]
}
with
raises
(
ValidationError
):
# we have additional_properties=False which propagates to subschemas
validate
(
example
,
schema
)
example
=
{
"
RefProp
"
:
[{
"
IntegerProp
"
:
12
},
"
101, otherB
"
]
}
validate
(
example
,
schema
)
rt
=
db
.
RecordType
()
rt
.
add_property
(
name
=
"
FileProp
"
,
datatype
=
db
.
FILE
)
...
...
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