Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NAS-131615 / 25.04 / Add unit tests for apps validation #56

Merged
merged 6 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Unit Tests

on: [push]

jobs:
run-unit-test:
name: Run Unit Tests
runs-on: ubuntu-latest
container:
image: ghcr.io/truenas/middleware:master

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Install dev-tools
run: |
install-dev-tools

- name: Install dependencies
run: |
apt install python3-pytest-mock -y

- name: Run Tests
run: |
PYTHONPATH=$(pwd) pytest apps_validation/pytest/unit/
PYTHONPATH=$(pwd) pytest catalog_reader/pytest/unit/
PYTHONPATH=$(pwd) pytest apps_schema/pytest/unit/
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ catalog_reader/__pycache__/*
catalog_reader/*/__pycache__/*
catalog_templating/__pycache__/*
catalog_templating/*/__pycache__/*
__pycache__
.coverage
Original file line number Diff line number Diff line change
Expand Up @@ -499,12 +499,56 @@
},
False
),
(
'attribute',
False
),
(
{
'type': 'string',
'$ref': [123]
},
False
),
(
{
'type': 'text',
},
True
),
(
{
'type': 'string',
'default': 'test',
'enum': [{
'value': 'test',
'description': 'test'
}]
},
True
),
(
{
'type': 'string',
'default': 'invalid',
'enum': [{
'value': 'test',
'description': 'test'
}]
},
False
),
])
def test_schema_validation(schema, should_work):
schema_object = get_schema(schema)
if not should_work:
with pytest.raises(ValidationErrors):
get_schema(schema).validate('')
if schema_object is None:
assert schema_object is None
else:
with pytest.raises(ValidationErrors):
schema_object.validate('')
else:
assert get_schema(schema).validate('') is None
assert schema_object.validate('', schema) is None
assert schema_object.get_schema_str(schema) == str(schema)+"."

# FIXME: Port validate_question test as well
Loading
Loading