-
Notifications
You must be signed in to change notification settings - Fork 7
Added version details file naming convention validation code #19
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
7a663c0
Added version details name validation code
da4b9e8
updated validate command
c898f22
Added check_version_tag method & test cases
da27d28
updated
ff3f6aa
updated sonatype-lift issues
524affe
updated sonatype-lift issues
bc18920
added test cases
bf5dfff
update
3b2e271
merged main branch
d5aa966
update
5128acd
merge main
3fc56a1
update
50f1c73
lint update
46618c8
merge main
9da1b41
fixed SSL Certificate issue
e372a0d
update
pramit-d 62791eb
update
ae8fe4b
updated help description
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,70 @@ | ||
| """Version details file validate""" | ||
| import sys | ||
| from urllib.error import HTTPError | ||
| from urllib.request import urlopen | ||
| from rich import print | ||
sudhirverma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| from besecure_developer_toolkit.src.create_ossp_master import OSSPMaster | ||
|
|
||
|
|
||
| class VersionFileValidate(): | ||
| """version details file naming convention validation class""" | ||
|
|
||
| def __init__(self, issue_id: int, name: str, namespace: str, branch: str): | ||
| self.issue_id = issue_id | ||
| self.name = name | ||
| self.namespace = namespace | ||
| self.branch = branch | ||
|
|
||
| def check_username(self): | ||
| """This method checks if given username is valid or not""" | ||
| try: | ||
| urlopen("https://api.github.com/users/"+self.namespace) | ||
| except HTTPError: | ||
| print(f"[bold red]Alert! [green]" | ||
| f"{self.namespace} is not valid username") | ||
| sys.exit() | ||
|
|
||
| def check_branch_exists(self): | ||
| """This method checks if the branch is exists | ||
| under besecure-osspoi-datastore for given user""" | ||
| try: | ||
| urlopen("https://api.github.com/repos/"+self.namespace + | ||
| "/besecure-osspoi-datastore/branches/"+self.branch) | ||
| except HTTPError: | ||
| print(f"[bold red]Alert! [green]{self.branch} does not " | ||
| f"exists under besecure-osspoi-" | ||
| f"datastore for {self.namespace}") | ||
| sys.exit() | ||
|
|
||
| def check_repo_exists(self, flag, namespace) -> None: | ||
| """This is an overriding method of CreateOsspMaster class | ||
| It checks if besecure-osspoi-datastore repo exists under the given user, | ||
| here flag is used for differentiate between base & child class method""" | ||
| try: | ||
| if flag: | ||
| urlopen("https://api.github.com/repos/" + | ||
| namespace+"/besecure-osspoi-datastore") | ||
| except HTTPError: | ||
| print(f"[bold red]Alert! [green]Could not find " | ||
| f"besecure-osspoi-datastore under {namespace}") | ||
| sys.exit() | ||
|
|
||
| def verify_versiondetails_name(self): | ||
| """It checks the version details file naming | ||
| convention that is uploaded by user""" | ||
| obj = OSSPMaster(self.issue_id, self.name) | ||
| obj.check_issue_exists(self.issue_id) | ||
| obj.check_repo_exists(self.name) | ||
| obj.check_issue_related_to_project() | ||
| self.check_username() | ||
| self.check_repo_exists(True, self.namespace) | ||
| self.check_branch_exists() | ||
| try: | ||
| urlopen("https://raw.githubusercontent.com/" | ||
| + self.namespace+"/besecure-osspoi-datastore/" | ||
| + self.branch+"/version_details/"+str(self.issue_id) | ||
| + "-"+self.name+"-Versiondetails.json") | ||
| print(f"{self.issue_id}-{self.name}-Versiondetails.json exists") | ||
| except HTTPError: | ||
| print(f"[bold red]Alert! [green]{self.issue_id}-{self.name}-" | ||
| f"Versiondetails.json does not exists") | ||
This file contains hidden or 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,161 @@ | ||
| """Test cases for version details file naming convention""" | ||
| from typer.testing import CliRunner | ||
sudhirverma marked this conversation as resolved.
Show resolved
Hide resolved
sudhirverma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| from besecure_developer_toolkit.cli import app | ||
| runner = CliRunner() | ||
|
|
||
|
|
||
| def test_vdnc(): | ||
| """test with valid data""" | ||
| issue_id = 136 | ||
| name = "fastjson" | ||
| namespace = "Be-Secure" | ||
| branch = "main" | ||
|
|
||
| result = runner.invoke(app, ["validate", "version_file"], input=str(issue_id) + | ||
| "\n"+name+"\n"+namespace+"\n"+branch+"\n") | ||
| result = result.output | ||
| result = result.split("branch")[1] | ||
| result = result.strip("\n")[1:] | ||
| assert result == "136-fastjson-Versiondetails.json exists" | ||
|
|
||
|
|
||
| def test_vdnc_file_does_not_exists(): | ||
| """test with wrong/invalid file name""" | ||
| issue_id = 405 | ||
| name = "OpenIDM" | ||
| namespace = "pramit-d" | ||
| branch = "main" | ||
|
|
||
| result = runner.invoke(app, ["validate", "version_file"], input=str(issue_id) + | ||
| "\n"+name+"\n"+namespace+"\n"+branch+"\n") | ||
| result = result.output | ||
| result = result.split("branch")[1] | ||
| result = result.strip("\n")[1:] | ||
| assert result == "Alert! 405-OpenIDM-"\ | ||
| "Versiondetails.json does not exists" | ||
|
|
||
|
|
||
| def test_vdnc_with_invalid_id(): | ||
| """test with invlid id""" | ||
| issue_id = 500 | ||
| name = "Koha" | ||
| namespace = "pramit-d" | ||
| branch = "Koha" | ||
|
|
||
| result = runner.invoke(app, ["validate", "version_file"], input=str(issue_id) + | ||
| "\n"+name+"\n"+namespace+"\n"+branch+"\n") | ||
| result = result.output | ||
| result = result.split("branch")[1] | ||
| result = result.strip("\n")[1:] | ||
| assert result == "Could not find issue with id : 500" | ||
|
|
||
|
|
||
| def test_vdnc_with_invalid_version_tag(): | ||
| """check version tag present under besecure issue details & | ||
| the tag written inside the version details file is not same""" | ||
| issue_id = 148 | ||
| name = "Koha" | ||
| namespace = "pramit-d" | ||
| branch = "Koha" | ||
|
|
||
| result = runner.invoke(app, ["validate", "version_file"], input=str( | ||
| issue_id)+"\n"+name+"\n"+namespace+"\n"+branch+"\n") | ||
| result = result.output | ||
| result = result.split("branch")[1] | ||
| result = result.strip("\n")[1:] | ||
| assert result == "Alert! Mismatch Version tag : Issue- "\ | ||
| "v21.05.18 & Versiondetails file- v21.05.17" | ||
|
|
||
|
|
||
| def test_vdnc_with_invalid_username(): | ||
| """test with invalid username""" | ||
| issue_id = 136 | ||
| name = "fastjson" | ||
| namespace = "prdut" | ||
| branch = "main" | ||
|
|
||
| result = runner.invoke(app, ["validate", "version_file"], input=str(issue_id) + | ||
| "\n"+name+"\n"+namespace+"\n"+branch+"\n") | ||
| result = result.output | ||
| result = result.split("branch")[1] | ||
| result = result.strip("\n")[1:] | ||
| assert result == "Alert! prdut is not valid username" | ||
|
|
||
|
|
||
| def test_vdnc_with_invalid_branch(): | ||
| """test with invalid branch name""" | ||
| issue_id = 197 | ||
| name = "bit" | ||
| namespace = "pramit-d" | ||
| branch = "xyz" | ||
|
|
||
| result = runner.invoke(app, ["validate", "version_file"], input=str(issue_id) + | ||
| "\n"+name+"\n"+namespace+"\n"+branch+"\n") | ||
| result = result.output | ||
| result = result.split("branch")[1] | ||
| result = result.strip("\n")[1:] | ||
| assert result == "Alert! xyz does not "\ | ||
| "exists under besecure-osspoi-datastore for pramit-d" | ||
|
|
||
|
|
||
| def test_vdnc_with_invalid_repo(): | ||
| """besecure-osspoi-datastore does not exists under mentioned user""" | ||
| issue_id = 197 | ||
| name = "bit" | ||
| namespace = "arunpillai6" | ||
| branch = "main" | ||
|
|
||
| result = runner.invoke(app, ["validate", "version_file"], input=str(issue_id) + | ||
| "\n"+name+"\n"+namespace+"\n"+branch+"\n") | ||
| result = result.output | ||
| result = result.split("branch")[1] | ||
| result = result.strip("\n")[1:] | ||
| assert result == "Alert! Could not find "\ | ||
| "besecure-osspoi-datastore under arunpillai6" | ||
|
|
||
|
|
||
| def test_vdnc_with_wrong_project(): | ||
| """besecure-osspoi-datastore does not exists under mentioned user""" | ||
| issue_id = 197 | ||
| name = "Koha" | ||
| namespace = "Be-Secure" | ||
| branch = "main" | ||
|
|
||
| result = runner.invoke(app, ["validate", "version_file"], input=str(issue_id) + | ||
| "\n"+name+"\n"+namespace+"\n"+branch+"\n") | ||
| result = result.output | ||
| result = result.split("branch")[1] | ||
| result = result.strip("\n").replace("\n", "")[1:] | ||
| assert result == "Alert! Mismatch issue_id-project : "\ | ||
| "Issue id 197 does not match the project Koha" | ||
|
|
||
|
|
||
| def test_vdnc_with_invalid_project(): | ||
| """project does not exists under Be-Secure""" | ||
| issue_id = 197 | ||
| name = "bitttt" | ||
| namespace = "Be-Secure" | ||
| branch = "main" | ||
|
|
||
| result = runner.invoke(app, ["validate", "version_file"], input=str(issue_id) + | ||
| "\n"+name+"\n"+namespace+"\n"+branch+"\n") | ||
| result = result.output | ||
| result = result.split("branch")[1] | ||
| result = result.strip("\n")[1:] | ||
| assert result == "Could not find bitttt under Be-Secure" | ||
|
|
||
|
|
||
| def test_vdnc_check_under_OSSPMaster(): | ||
| """check if mentioned project exists under OSSP-master.json file""" | ||
| issue_id = 405 | ||
| name = "OpenIDM" | ||
| namespace = "pramit-d" | ||
| branch = "test-dev-kit" | ||
|
|
||
| result = runner.invoke(app, ["validate", "version_file"], input=str(issue_id) + | ||
| "\n"+name+"\n"+namespace+"\n"+branch+"\n") | ||
| result = result.output | ||
| result = result.split("branch")[1] | ||
| result = result.strip("\n")[1:] | ||
| assert result == "Alert! OpenIDM does not exists "\ | ||
| "under besecure-osspoi-datastore" | ||
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.
Uh oh!
There was an error while loading. Please reload this page.