Skip to content

[C4GT Community]: Raise NotImplementedError in InterfaceProtocolCheckMixin if either classes lack the declared method. #33

@codecakes

Description

@codecakes

Ticket Contents

Description

InterfaceProtocolCheckMixin checks for correct signature used by the implementation class. You can drop in the mixin wherever an implementation is subclassed with an interface definition.

For instance, a service interface is defined here
And It's implementation is here

InterfaceProtocolCheckMixin however doesn't exactly check if both the implementation and interface have the declared method.

Goals

Goals

  • Raise NotImplementedError in InterfaceProtocolCheckMixin if both the implementation and interface do not have the declared method.
  • Implement test cases.

Expected Outcome

During runtime:

  1. Implementing an interface with InterfaceProtocolCheckMixin that lacks a method defined in interface will raise NotImplementedError.
  2. Implementing an interface with InterfaceProtocolCheckMixin that has a method defined in interface but not in the implementation will raise NotImplementedError.

Acceptance Criteria

  • Test checks for an stub implementation and a test interface for it and both have the methods.
  • Test checks for an stub implementation and a test interface and raises NotImplementedError if either of them lack the method declaration.

Implementation Details

Check if both classes have the method declared here: https://github.com/Xcov19/project-healthcare/blob/964861545c969258caa5e86dfc63e413bf545fca/xcov19/utils/mixins.py#L18

UPDATE
If you have an Interface class BaseClass and an implementation class IncorrectImplementation :

class BaseClass:
    def method_with_params(self, param1: int, param2: str):
        pass


class IncorrectImplementation(BaseClass, InterfaceProtocolCheckMixin):
    def method2(self, param1: int):
        pass

Then, Running IncorrectImplementation should raise NotImplementedError because method method_with_params is missing from IncorrectImplementation and method2 is not defined in the Interface BaseClass

Mockups/Wireframes

No response

Product Name

project-healthcare

Organisation Name

XCoV19

Domain

Healthcare

Tech Skills Needed

Debugging, Python, Test, Testing Library

Mentor(s)

@codecakes

Complexity

Low

Category

Backend, Beginner Friendly, Testing

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions