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

Require stable API version for submitting an add-on using stable channel #33

Merged
merged 3 commits into from
Oct 11, 2023
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
14 changes: 14 additions & 0 deletions _tests/testData/nvdaAPIVersions.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,19 @@
"minor": 1,
"patch": 0
}
},
{
"description": "NVDA 2024.1",
"apiVer": {
"major": 2024,
"minor": 1,
"patch": 0
},
"backCompatTo": {
"major": 2024,
"minor": 1,
"patch": 0
},
"experimental": true
}
]
48 changes: 47 additions & 1 deletion _tests/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def test_getExistingVersions(self):
formattedVersions = list(validate.getExistingVersions(self.verFilename))
self.assertEqual(
formattedVersions,
["0.0.0", "2022.1.0", "2023.1.0"]
["0.0.0", "2022.1.0", "2023.1.0", "2024.1.0"]
)


Expand Down Expand Up @@ -352,6 +352,29 @@ def test_invalidNew(self):
["Last tested version error: 9999.3.0 doesn't exist"]
)

def test_validExperimental(self):
self.submissionData["lastTestedVersion"]["major"] = 2024
self.submissionData["lastTestedVersion"]["minor"] = 1
self.submissionData["lastTestedVersion"]["patch"] = 0
self.submissionData["channel"] = "beta"
self.assertEqual(
list(validate.checkLastTestedVersionExist(self.submissionData, self.verFilename)),
[]
)

def test_invalidExperimental(self):
self.submissionData["lastTestedVersion"]["major"] = 2024
self.submissionData["lastTestedVersion"]["minor"] = 1
self.submissionData["lastTestedVersion"]["patch"] = 0
self.submissionData["channel"] = "stable"
self.assertEqual(
list(validate.checkLastTestedVersionExist(self.submissionData, self.verFilename)),
[
"Last tested version error: 2024.1.0 is not stable yet. "
"Please submit add-on using the beta or dev channel."
]
)


class validate_checkMinRequiredVersionExists(unittest.TestCase):
"""Test for the checkMinRequiredVersionExists function."""
Expand Down Expand Up @@ -399,6 +422,29 @@ def test_invalidNew(self):
["Minimum required version error: 9999.3.0 doesn't exist"]
)

def test_validExperimental(self):
self.submissionData["minNVDAVersion"]["major"] = 2024
self.submissionData["minNVDAVersion"]["minor"] = 1
self.submissionData["minNVDAVersion"]["patch"] = 0
self.submissionData["channel"] = "beta"
self.assertEqual(
list(validate.checkMinRequiredVersionExist(self.submissionData, self.verFilename)),
[]
)

def test_invalidExperimental(self):
self.submissionData["minNVDAVersion"]["major"] = 2024
self.submissionData["minNVDAVersion"]["minor"] = 1
self.submissionData["minNVDAVersion"]["patch"] = 0
self.submissionData["channel"] = "stable"
self.assertEqual(
list(validate.checkMinRequiredVersionExist(self.submissionData, self.verFilename)),
[
"Minimum required version error: 2024.1.0 is not stable yet. "
"Please submit add-on using the beta or dev channel."
]
)


class Validate_checkMinNVDAVersionMatches(unittest.TestCase):
"""Tests for the checkMinNVDAVersionMatches function.
Expand Down
28 changes: 27 additions & 1 deletion _validate/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,22 @@ def getExistingVersions(verFilename: str) -> List[str]:
"""Loads API versions file and returns list of versions formatted as strings.
"""
with open(verFilename) as f:
data: JsonObjT = json.load(f)
data: List[JsonObjT] = json.load(f)
return [_formatVersionString(version["apiVer"].values()) for version in data]


def getExistingStableVersions(verFilename: str) -> List[str]:
"""Loads API versions file and returns list of stable versions formatted as strings.
"""
with open(verFilename) as f:
data: List[JsonObjT] = json.load(f)
return [
_formatVersionString(version["apiVer"].values())
for version in data
if not version.get("experimental", False)
]


def _validateJson(data: JsonObjT) -> None:
""" Ensure that the loaded metadata conforms to the schema.
Raise error if not
Expand Down Expand Up @@ -277,13 +289,27 @@ def checkLastTestedVersionExist(submission: JsonObjT, verFilename: str) -> Valid
if formattedLastTestedVersion not in getExistingVersions(verFilename):
yield f"Last tested version error: {formattedLastTestedVersion} doesn't exist"

elif (
submission["channel"] == "stable"
and formattedLastTestedVersion not in getExistingStableVersions(verFilename)
):
yield f"Last tested version error: {formattedLastTestedVersion} is not stable yet. " + \
"Please submit add-on using the beta or dev channel."


def checkMinRequiredVersionExist(submission: JsonObjT, verFilename: str) -> ValidationErrorGenerator:
minRequiredVersion: JsonObjT = submission["minNVDAVersion"]
formattedMinRequiredVersion: str = _formatVersionString(minRequiredVersion.values())
if formattedMinRequiredVersion not in getExistingVersions(verFilename):
yield f"Minimum required version error: {formattedMinRequiredVersion} doesn't exist"

elif (
submission["channel"] == "stable"
and formattedMinRequiredVersion not in getExistingStableVersions(verFilename)
):
yield f"Minimum required version error: {formattedMinRequiredVersion} is not stable yet. " + \
"Please submit add-on using the beta or dev channel."


def checkVersions(
manifest: AddonManifest,
Expand Down