Created
July 18, 2017 17:06
-
-
Save jpotts18/e9673813675a2dc6e9d37fb1be88fedc to your computer and use it in GitHub Desktop.
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
class BaseValidator(object): | |
def validate(rules_definition): | |
errors = [] | |
for rule in rules_definition.rules: | |
response = rule.validate() | |
if response[1]: | |
errors.append(response[1]) | |
if len(errors) > 0 | |
return Cloudwatch | |
else | |
class HttpRequest(object): | |
# Isolate all of the request specific validation that needs to happen into here | |
# Knows how to make http requests and pass res to validate function | |
class RecommendationCanary(HttpRequest): | |
# Isolate the specific test information that happens here | |
self.BASE_URL | |
self.PATH | |
self.REQUEST_OPTIONS | |
def __init__(self): | |
self.BASE_URL = 'subdomain.example.com' | |
self.PATH = '/path' | |
self.OPTIONS = {} | |
resp = request.post(BASE_URL, PATH, OPTIONS) | |
build_rules(resp) | |
def build_rules(req): | |
# add any validations that need to happen | |
rules = [ | |
css_rule(req, '.h2', 'Hello'), | |
css_gte(req, '.h2', 3), | |
css_lte(req, 'ul.li', 4), | |
] | |
return rules | |
class BaseRule(object): | |
pass | |
class CSSEqualsRule(object): | |
@classmethod | |
def validate(cls, req, selector, comparison): | |
x = req.css_select(selector) | |
if x == comparison: | |
return (true, ) | |
else: | |
return (false, 'CSS selector {} does not equal {}'.format(selector, comparison)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment