Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_parse_invalid_date(invalid_date, error_string):
assert isinstance(invalid_date, str) or invalid_date is None # Why? 'cos I've screwed up the parametrize before :)
with pytest.raises(iso8601.ParseError) as exc:
iso8601.parse_date(invalid_date)
assert exc.errisinstance(iso8601.ParseError)
assert str(exc.value).startswith(error_string)
def test_parse_invalid_date(invalid_date, error_string):
assert isinstance(invalid_date, str) or invalid_date is None # Why? 'cos I've screwed up the parametrize before :)
with pytest.raises(iso8601.ParseError) as exc:
iso8601.parse_date(invalid_date)
assert exc.errisinstance(iso8601.ParseError)
assert str(exc.value).startswith(error_string)
def test_parse_invalid_date(invalid_date, error_string):
assert isinstance(invalid_date, str) or invalid_date is None # Why? 'cos I've screwed up the parametrize before :)
with pytest.raises(iso8601.ParseError) as exc:
iso8601.parse_date(invalid_date)
assert exc.errisinstance(iso8601.ParseError)
assert str(exc.value).startswith(error_string)
def update_expiry_field(self):
"""
Updates the expiry_field attribute. It uses the expiry field of the
contributions category and sets the date according to the value set
for the current contribution.
"""
expiry_field = self.category.expiry_field
value = None
if expiry_field and self.properties:
try:
value = parse_date(self.properties.get(expiry_field.key))
except ParseError:
pass
self.expiry_field = value
def validate_phone_datetime(datetime_string, none_ok=False):
if none_ok:
if datetime_string is None:
return None
if not _soft_assert(datetime_string != '',
'phone datetime should never be empty'):
return None
try:
return iso8601.parse_date(datetime_string)
except iso8601.ParseError:
raise PhoneDateValueError('{!r}'.format(datetime_string))
self.logger.debug("_check_create_representation: %s", values)
# TODO: move this to expiration time handler plugin
# but needs to be set to a value even if plugin is disabled
if issubclass(self.resource_type, ExpiringResource):
expiration_time = values.get("expirationTime")
if not expiration_time:
expiration_time = self.now + self.global_config[
"default_lifetime"]
self.fields.append("expirationTime")
else:
if not isinstance(expiration_time, datetime):
try:
expiration_time = parse_date(expiration_time)
except ParseError as e:
raise CSEValueError(
"Illegal value for expirationTime: %s" % (e,))
if expiration_time < self.now + self.global_config["min_lifetime"]:
self.logger.warn("expirationTime is too low. Adjusting")
expiration_time = self.now + self.global_config["min_lifetime"]
self.fields.append("expirationTime")
elif expiration_time > self.now + self.global_config["max_lifetime"]:
self.logger.warn("expirationTime is too high. Adjusting")
expiration_time = self.now + self.global_config["max_lifetime"]
self.fields.append("expirationTime")
values["expirationTime"] = expiration_time
rt_attributes = rt.attributes
ignore_extra = True # todo(rst): check this later with flexContainer
is_flex = ignore_extra and issubclass(self.resource_type,
def validateInput(self, value):
"""
Checks if the provided value is a valid and ISO8601 compliant date string.
"""
try:
iso8601.parse_date(value)
return True
except iso8601.iso8601.ParseError:
return False
def _clean_date(date: str):
try:
return str(iso8601.parse_date(date).date())
except iso8601.ParseError:
return None
def is_DSS_VERSION(val):
"""
Verifies `val` is compliant with expected format. See for more info on connexion custom type formats
https://connexion.readthedocs.io/en/latest/cookbook.html#custom-type-format.
:param val: the value to verify
:return: the verified value
"""
from iso8601 import iso8601
# convert it to date-time so we can format exactly as the system requires (with microsecond precision)
try:
timestamp = iso8601.parse_date(val)
except iso8601.ParseError:
raise DSSException(
requests.codes.bad_request,
"illegal_version",
f"version should be an RFC3339 compliant timestamp")
timestamp = datetime_to_version_format(timestamp)
if timestamp != val:
raise DSSException(
requests.codes.bad_request,
"illegal_version",
f"version should be a DSS_VERSION with the format 'YYYY-MM-DDTHHmmSS.zzzzzzZ'")
return val