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
Fix for issue #19 (as discussed) and added generate_xml method #21
Closed
Closed
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8cb9586
added generate_xml method and renamed method generate_and_validate to…
ayushbindlish 60e3d3f
removed unused import
ayushbindlish 0968c53
renamed generate_and_validate method, updated generate method with bo…
ayushbindlish 75ae491
Merge branch 'ghandic:main' into main
ayushbindlish 3bf299e
updated generate method and removed to_xml method
ayushbindlish File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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,38 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema", | ||
"title": "Employee Json Template Spec", | ||
"type": "object", | ||
"properties": { | ||
"EmpID": { | ||
"type": "string", | ||
"maximum": 255 | ||
}, | ||
"UserID": { | ||
"type": "number", | ||
"maximum": 255 | ||
}, | ||
"Name": { | ||
"type": "string", | ||
"minimum": 2 | ||
}, | ||
"Email": { | ||
"type": "string", | ||
"minLength": 6, | ||
"maxLength": 255 | ||
}, | ||
"Phone": { | ||
"type": "string", | ||
"maxLength": 10 | ||
}, | ||
"Salary": { | ||
"type": "number" | ||
}, | ||
"Hiredate": { | ||
"type": "string", | ||
"format": "date" | ||
}, | ||
"RemainingHolidays": { | ||
"type": "number" | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import json | ||
import re | ||
|
||
import json2xml | ||
import pytest | ||
from ..jsf.parser import JSF | ||
import re | ||
|
||
|
||
def test_fake_boolean(TestData): | ||
|
@@ -229,7 +231,7 @@ def test_const(TestData): | |
assert isinstance(f["country"], str) | ||
assert f["country"] == "United States of America" | ||
|
||
|
||
#@pytest.mark.xfail(reason="Always failing with "no such file or dir" error!!") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should exist if youre running the tests from a unix based machine and from the same directory as the src folder |
||
def test_external_ref(TestData): | ||
with open(TestData / f"external-ref.json", "r") as file: | ||
schema = json.load(file) | ||
|
@@ -245,8 +247,36 @@ def test_external_ref(TestData): | |
assert all(isinstance(t, str) for t in f["ReferenceToExternalSchema"]["src"]) | ||
|
||
|
||
def test_gen_and_validate(TestData): | ||
with open(TestData / f"custom.json", "r") as file: | ||
def test_validate(TestData): | ||
with open(TestData / f"validate.json", "r") as file: | ||
schema = json.load(file) | ||
p = JSF(schema) | ||
[p.generate_and_validate() for _ in range(50)] | ||
[p.validate() for _ in range(50)] | ||
|
||
def test_validate_and_generate_single_record(TestData): | ||
"""validate and generate data from schema""" | ||
with open(TestData / f"validate.json", "r") as file: | ||
schema = json.load(file) | ||
p = JSF(schema) | ||
fake_data = p.generate(validate=True) | ||
assert(isinstance(fake_data,dict)) | ||
|
||
def test_validate_and_generate__multiple_records(TestData): | ||
"""validate and generate data from schema""" | ||
with open(TestData / f"validate.json", "r") as file: | ||
schema = json.load(file) | ||
p = JSF(schema) | ||
fake_data = p.generate(validate=True,n=100) | ||
assert(isinstance(fake_data,list)) | ||
assert(len(fake_data)==100) | ||
for x in fake_data: | ||
assert(isinstance(x,dict)) | ||
|
||
def test_generate_xml(TestData): | ||
ayushbindlish marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""validate and generate data from schema""" | ||
with open(TestData / f"validate.json", "r") as file: | ||
schema = json.load(file) | ||
p = JSF(schema) | ||
p.generate_xml() | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since XML wont be added in the package as noted below, could you remove this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does not work for me for some reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am on ubuntu.
command used:
pytest
pwd: jsf/src
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.3 LTS
Release: 20.04
Codename: focal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The above comments are supposed to be for pytest failure I mentioned above.