Skip to content

Commit

Permalink
Fix valid values used by validators
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-k committed Feb 23, 2023
1 parent fed1723 commit f68de31
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 9 deletions.
47 changes: 47 additions & 0 deletions tests/test_appconfig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import unittest

from troposphere.appconfig import DeploymentStrategy, Validators


class TestAppconfigDeploymentStrategy(unittest.TestCase):
def test_deploymentstrategy_growthtype_bad_value(self):
with self.assertRaisesRegex(ValueError, "GrowthType must be one of"):
DeploymentStrategy(
"DeploymentStrategy",
DeploymentDurationInMinutes=1,
GrowthFactor=1,
GrowthType="LINEA",
Name="DeploymentStrategy",
ReplicateTo="NONE",
)

def test_deploymentstrategy_replicateto_bad_value(self):
with self.assertRaisesRegex(ValueError, "ReplicateTo must be one of"):
DeploymentStrategy(
"DeploymentStrategy",
DeploymentDurationInMinutes=1,
GrowthFactor=1,
Name="DeploymentStrategy",
ReplicateTo="none",
)

def test_deploymentstrategy(self):
for replicate_to in ("NONE", "SSM_DOCUMENT"):
DeploymentStrategy(
"DeploymentStrategy",
DeploymentDurationInMinutes=1,
GrowthFactor=1,
GrowthType="LINEAR",
Name="DeploymentStrategy",
ReplicateTo=replicate_to,
)


class TestAppconfigValidators(unittest.TestCase):
def test_validators_type_bad_value(self):
with self.assertRaisesRegex(ValueError, "Validator Type must be one of"):
Validators(Type="JSON_SCHEM")

def test_validators_type(self):
for validator_type in ("JSON_SCHEMA", "LAMBDA"):
Validators(Type=validator_type)
34 changes: 34 additions & 0 deletions tests/test_codebuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,37 @@ def test_filter_fail(self):
[None],
]
).validate()


class TestCodeBuildRegistryCredential(unittest.TestCase):
def test_registrycredential_provider_bad_value(self):
with self.assertRaisesRegex(ValueError, "CredentialProvider must be one of"):
codebuild.RegistryCredential(
Credential="Foo",
CredentialProvider="SECRETS",
)

def test_registrycredential(self):
codebuild.RegistryCredential(
Credential="Foo",
CredentialProvider="SECRETS_MANAGER",
)


class TestCodeBuildProjectFileSystemLocation(unittest.TestCase):
def test_projectfilesystemlocation_type_bad_value(self):
with self.assertRaisesRegex(ValueError, "Type must be one of"):
codebuild.ProjectFileSystemLocation(
Identifier="foo",
Location="bar",
MountPoint="baz",
Type="EF",
)

def test_projectfilesystemlocation(self):
codebuild.ProjectFileSystemLocation(
Identifier="foo",
Location="bar",
MountPoint="baz",
Type="EFS",
)
16 changes: 16 additions & 0 deletions tests/test_dlm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import unittest

from troposphere.dlm import CreateRule


class TestDlmCreateRule(unittest.TestCase):
def test_createrule_interval_bad_value(self):
with self.assertRaisesRegex(ValueError, "Interval must be one of"):
CreateRule("CreateRule", Interval=25)

def test_createrule_intervalunit_bad_value(self):
with self.assertRaisesRegex(ValueError, "Interval unit must be one of"):
CreateRule("CreateRule", Interval=24, IntervalUnit="HOUR")

def test_createrule(self):
CreateRule("CreateRule", Interval=24, IntervalUnit="HOURS")
6 changes: 3 additions & 3 deletions troposphere/validators/appconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ def validate_growth_type(growth_type):
Property: DeploymentStrategy.GrowthType
"""

VALID_GROWTH_TYPE = "LINEAR"
VALID_GROWTH_TYPES = ("LINEAR",)

if growth_type not in VALID_GROWTH_TYPE:
if growth_type not in VALID_GROWTH_TYPES:
raise ValueError(
"DeploymentStrategy GrowthType must be one of: %s"
% ", ".join(VALID_GROWTH_TYPE)
% ", ".join(VALID_GROWTH_TYPES)
)
return growth_type

Expand Down
8 changes: 4 additions & 4 deletions troposphere/validators/codebuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def validate_credentials_provider(credential_provider):
Property: RegistryCredential.CredentialProvider
"""

VALID_CREDENTIAL_PROVIDERS = "SECRETS_MANAGER"
VALID_CREDENTIAL_PROVIDERS = ("SECRETS_MANAGER",)

if credential_provider not in VALID_CREDENTIAL_PROVIDERS:
raise ValueError(
Expand Down Expand Up @@ -89,12 +89,12 @@ def validate_projectfilesystemlocation_type(projectfilesystemlocation_type):
Property: ProjectFileSystemLocation.Type
"""

VALID_PROJECTFILESYSTEMLOCATION_TYPE = "EFS"
VALID_PROJECTFILESYSTEMLOCATION_TYPES = ("EFS",)

if projectfilesystemlocation_type not in VALID_PROJECTFILESYSTEMLOCATION_TYPE:
if projectfilesystemlocation_type not in VALID_PROJECTFILESYSTEMLOCATION_TYPES:
raise ValueError(
"ProjectFileSystemLocation Type must be one of: %s"
% ", ".join(VALID_PROJECTFILESYSTEMLOCATION_TYPE)
% ", ".join(VALID_PROJECTFILESYSTEMLOCATION_TYPES)
)
return projectfilesystemlocation_type

Expand Down
7 changes: 5 additions & 2 deletions troposphere/validators/dlm.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ def validate_interval(interval):
VALID_INTERVALS = (2, 3, 4, 6, 8, 12, 24)

if interval not in VALID_INTERVALS:
raise ValueError("Interval must be one of : %s" % ", ".join(VALID_INTERVALS))
raise ValueError(
"Interval must be one of : %s"
% ", ".join([str(i) for i in VALID_INTERVALS])
)
return interval


Expand All @@ -35,7 +38,7 @@ def validate_interval_unit(interval_unit):
Property: CreateRule.IntervalUnit
"""

VALID_INTERVAL_UNITS = "HOURS"
VALID_INTERVAL_UNITS = ("HOURS",)

if interval_unit not in VALID_INTERVAL_UNITS:
raise ValueError(
Expand Down

0 comments on commit f68de31

Please sign in to comment.