Skip to content

Commit

Permalink
Merge pull request #56 from truenas/unit-tests-for-apps-validation
Browse files Browse the repository at this point in the history
NAS-131615 / 25.04 / Add unit tests for apps validation
  • Loading branch information
sonicaj authored Oct 7, 2024
2 parents 5e61a05 + 3421ad4 commit 5002d51
Show file tree
Hide file tree
Showing 15 changed files with 1,644 additions and 5 deletions.
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

0 comments on commit 5002d51

Please sign in to comment.