import re
from models.listing import Listing
from models.policy import Policy
class ValidRegistrationNumberPolicy(Policy):
def __init__(self, listing: Listing):
self.listing = listing
def evaluate(self) -> bool:
valid_registration_pattern = re.compile(r"^[0-9]{2}-[0-9]{6}$")
if valid_registration_pattern.match(self.listing.licence_number):
return True
else:
return False
main.py
from models.address import Address
from models.listing import Listing
from models.policy_client import PolicyClient
from policy.valid_registration_number_policy import (
ValidRegistrationNumberPolicy,
)
listing = Listing("1234", address=Address(city="Van"), licence_number="20-12345")
registration_number_policies = ValidRegistrationNumberPolicy(listing)
client = PolicyClient(registration_number_policies)
print(client.get_all_violation_results())
## return []
client.get_violation_result()
print(client.get_all_violation_results())
## return [{'ValidRegistrationNumberPolicy': False}]
Type of Change
Please delete options that are not relevant.
[ ] Bug fix (non-breaking change which fixes an issue)
[x] New feature (non-breaking change which adds functionality)
[ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
[ ] This change requires a documentation update
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.
[ ] Unit Test
[ ] Integration Test
[ ] E2E Test
Checklist:
Before you submit your pull request, please make sure you have completed the following:
[x] I have read the CONTRIBUTING document.
[x] I have checked that my code adheres to the code style of this project.
[x] I have performed a self-review of my own code.
[x] I have commented my code, particularly in hard-to-understand areas.
[ ] I have made corresponding changes to the documentation.
[x] My changes generate no new warnings.
[ ] I have added tests that prove my fix is effective or that my feature works.
[x] New and existing unit tests pass locally with my changes.
[x] Any dependent changes have been merged and published in downstream modules.
Screenshots (if applicable)
Include any relevant screenshots or screen recordings demonstrating your changes.
Additional Notes
Detailed implementation of the Policy might be changed, per #40
With this change, the Policies implementation may also need changes regarding the Policy interface
Description
Issue Link: #18
This PR contains PolicyClient object that works with Policy interface (from which the Policy objects are based on) Dataflow:
Example usage, given the following policy:
valid_registration_number_policy.py
main.py
Type of Change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.
Checklist:
Before you submit your pull request, please make sure you have completed the following:
Screenshots (if applicable)
Include any relevant screenshots or screen recordings demonstrating your changes.
Additional Notes
Detailed implementation of the Policy might be changed, per #40 With this change, the Policies implementation may also need changes regarding the Policy interface