Skip to content

Feature/policy results for report#45

Open
nam-m wants to merge 5 commits intomainfrom
feature/policy-results-for-report
Open

Feature/policy results for report#45
nam-m wants to merge 5 commits intomainfrom
feature/policy-results-for-report

Conversation

@nam-m
Copy link
Contributor

@nam-m nam-m commented Feb 22, 2024

Description

Issue Link: #18

This PR contains PolicyClient object that works with Policy interface (from which the Policy objects are based on)
Dataflow:

PolicyClient <-----> Policy
                        ^
                        |
                        |
         ValidRegistrationNumberPolicy
         UniqueRegistrationNumberPolicy
                      .
                      .
                      .                  

Example usage, given the following policy:

valid_registration_number_policy.py

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)
  • 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:

  • I have read the CONTRIBUTING document.
  • I have checked that my code adheres to the code style of this project.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • 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

@nam-m nam-m linked an issue Feb 22, 2024 that may be closed by this pull request
@nam-m nam-m added the enhancement New feature or request label Feb 22, 2024
@nam-m nam-m added this to the 1. MVP milestone Feb 22, 2024
@nam-m nam-m marked this pull request as ready for review February 23, 2024 06:58
@nam-m nam-m requested a review from umsu2 as a code owner February 23, 2024 06:58
@nam-m nam-m self-assigned this Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

[MVP] Generate results for report

1 participant