-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf89d7e
commit b97b19b
Showing
2 changed files
with
34 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import pytest | ||
|
||
from datagateway_api.common.helpers import is_valid_json | ||
|
||
|
||
class TestIsValidJSON: | ||
@pytest.mark.parametrize( | ||
"input_json", | ||
[ | ||
pytest.param("[]", id="empty array"), | ||
pytest.param("null", id="null"), | ||
pytest.param('{"test":1}', id="key-value pair"), | ||
pytest.param('{"test":{"inner_key":"inner_value"}}', id="nested json"), | ||
], | ||
) | ||
def test_valid_json_input(self, input_json): | ||
valid_json = is_valid_json(input_json) | ||
|
||
assert valid_json | ||
|
||
@pytest.mark.parametrize( | ||
"invalid_json", | ||
[ | ||
pytest.param("{'test':1}", id="single quotes"), | ||
pytest.param(None, id="none"), | ||
pytest.param(1, id="integer"), | ||
pytest.param({"test": 1}, id="dictionary"), | ||
pytest.param([], id="empty list"), | ||
], | ||
) | ||
def test_invalid_json_input(self, invalid_json): | ||
valid_json = is_valid_json(invalid_json) | ||
|
||
assert not valid_json |