Skip to content

Commit

Permalink
Use abstractmethod in Service
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobranco777 committed Nov 4, 2023
1 parent f673f51 commit 72c2373
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 24 deletions.
22 changes: 12 additions & 10 deletions services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
import os
import re
from abc import ABC, abstractmethod
from concurrent.futures import ThreadPoolExecutor
from dataclasses import dataclass
from urllib.parse import urlparse, parse_qs
Expand Down Expand Up @@ -148,7 +149,7 @@ def get_urltag(string: str) -> dict[str, str | bool] | None:
}


class Service:
class Service(ABC):
"""
Service class to abstract methods
"""
Expand All @@ -158,6 +159,7 @@ def __init__(self, url: str):
self.url = url if url.startswith("https://") else f"https://{url}"
self.tag = "".join([s[0] for s in str(urlparse(self.url).hostname).split(".")])

@abstractmethod
def close(self):
"""
Close session
Expand Down Expand Up @@ -245,33 +247,33 @@ def get_issues(is_pr: bool, is_assigned: bool) -> list[Issue]:

return list(set(issues))

def get_issue(self, issue_id: str = "", **kwargs) -> Issue | None:
"""
This method must be overriden if get_issues() isn't overriden
"""
raise NotImplementedError(f"{self.__class__.__name__}: get_issue()")

@abstractmethod
def get_assigned(
self, username: str = "", **_ # pylint: disable=unused-argument
) -> list[Issue]:
"""
Get assigned issues
"""
return []

@abstractmethod
def get_created(
self, username: str = "", **_ # pylint: disable=unused-argument
) -> list[Issue]:
"""
Get created issues
"""
return []

@abstractmethod
def get_user_issues(self, **_) -> list[Issue]:
"""
Get user issues
"""
return []

@abstractmethod
def get_issue(self, issue_id: str = "", **kwargs) -> Issue | None:
"""
This method must be overriden if get_issues() isn't overriden
"""

def get_issues(self, issues: list[dict]) -> list[Issue | None]:
"""
Expand Down
15 changes: 1 addition & 14 deletions tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from datetime import datetime
import pytest
from services import get_urltag, Issue, Service
from services import get_urltag, Issue
from services.guess import guess_service, guess_service2
from services.bugzilla import MyBugzilla
from services.gitea import MyGitea
Expand Down Expand Up @@ -212,19 +212,6 @@ def test_get_urltag_with_unsupported_url():
assert issue is None


# Test cases for the Service class
def test_service_initialization():
url = "example.com"
service = Service(url)
assert service.url == f"https://{url}"


def test_service_repr():
url = "example.com"
service = Service(url)
assert repr(service) == f"Service(url='https://{url}')"


def test_guess_service():
assert guess_service("github.com") is MyGithub
assert guess_service("launchpad.net") is MyLaunchpad
Expand Down

0 comments on commit 72c2373

Please sign in to comment.