From 5b0bee78cfa09818bdff61a4ad3119eec8ed2f21 Mon Sep 17 00:00:00 2001 From: Carmen Alvarez Date: Sat, 20 Jul 2024 17:02:45 +0200 Subject: [PATCH] test(coverage): Add test coverage github action. Exclude `@abstractmethod`s from code coverage. --- .coveragerc | 4 ++++ .github/workflows/check.yml | 6 ++++++ .../localrepository/localfitbitrepository.py | 14 +++++++++++++- .../remoterepository/remotefitbitrepository.py | 6 +++++- .../remoterepository/remoteslackrepository.py | 3 ++- .../remoterepository/remotewithingsrepository.py | 5 ++++- 6 files changed, 34 insertions(+), 4 deletions(-) diff --git a/.coveragerc b/.coveragerc index 6b4419d7..e617b727 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,2 +1,6 @@ [run] concurrency = thread,gevent + +[report] +exclude_lines = + @abstractmethod diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 458d1652..6365c4c0 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -8,6 +8,7 @@ jobs: Check: runs-on: ubuntu-latest permissions: + pull-requests: write checks: write steps: - uses: actions/checkout@v4 @@ -29,6 +30,11 @@ jobs: if: always() # always run even if the previous step fails with: report_paths: 'reports/junit.xml' + - name: Post coverage report + uses: 5monkeys/cobertura-action@v14 + with: + path: reports/coverage.xml + minimum_coverage: 80 - name: Archive reports if: always() uses: actions/upload-artifact@v4 diff --git a/slackhealthbot/domain/localrepository/localfitbitrepository.py b/slackhealthbot/domain/localrepository/localfitbitrepository.py index 066ef1c2..bb0db894 100644 --- a/slackhealthbot/domain/localrepository/localfitbitrepository.py +++ b/slackhealthbot/domain/localrepository/localfitbitrepository.py @@ -1,6 +1,6 @@ import dataclasses import datetime -from abc import ABC +from abc import ABC, abstractmethod from slackhealthbot.core.models import OAuthFields from slackhealthbot.domain.models.activity import ActivityData, TopActivityStats @@ -20,6 +20,7 @@ class User: class LocalFitbitRepository(ABC): + @abstractmethod async def create_user( self, slack_alias: str, @@ -28,27 +29,32 @@ async def create_user( ) -> User: pass + @abstractmethod async def get_user_identity_by_fitbit_userid( self, fitbit_userid: str, ) -> UserIdentity | None: pass + @abstractmethod async def get_all_user_identities(self) -> list[UserIdentity]: pass + @abstractmethod async def get_oauth_data_by_fitbit_userid( self, fitbit_userid: str, ) -> OAuthFields: pass + @abstractmethod async def get_user_by_fitbit_userid( self, fitbit_userid: str, ) -> User: pass + @abstractmethod async def get_latest_activity_by_user_and_type( self, fitbit_userid: str, @@ -56,6 +62,7 @@ async def get_latest_activity_by_user_and_type( ) -> ActivityData | None: pass + @abstractmethod async def get_activity_by_user_and_log_id( self, fitbit_userid: str, @@ -63,6 +70,7 @@ async def get_activity_by_user_and_log_id( ) -> ActivityData | None: pass + @abstractmethod async def create_activity_for_user( self, fitbit_userid: str, @@ -70,6 +78,7 @@ async def create_activity_for_user( ): pass + @abstractmethod async def update_sleep_for_user( self, fitbit_userid: str, @@ -77,12 +86,14 @@ async def update_sleep_for_user( ): pass + @abstractmethod async def get_sleep_by_fitbit_userid( self, fitbit_userid: str, ) -> SleepData | None: pass + @abstractmethod async def update_oauth_data( self, fitbit_userid: str, @@ -90,6 +101,7 @@ async def update_oauth_data( ): pass + @abstractmethod async def get_top_activity_stats_by_user_and_activity_type( self, fitbit_userid: str, diff --git a/slackhealthbot/domain/remoterepository/remotefitbitrepository.py b/slackhealthbot/domain/remoterepository/remotefitbitrepository.py index a5b617cb..e69893ee 100644 --- a/slackhealthbot/domain/remoterepository/remotefitbitrepository.py +++ b/slackhealthbot/domain/remoterepository/remotefitbitrepository.py @@ -1,5 +1,5 @@ import datetime -from abc import ABC +from abc import ABC, abstractmethod from slackhealthbot.core.models import OAuthFields from slackhealthbot.domain.models.activity import ActivityData @@ -7,17 +7,20 @@ class RemoteFitbitRepository(ABC): + @abstractmethod async def subscribe( self, oauth_fields: OAuthFields, ): pass + @abstractmethod async def get_activity( self, oauth_fields: OAuthFields, when: datetime.datetime ) -> tuple[str, ActivityData] | None: pass + @abstractmethod async def get_sleep( self, oauth_fields: OAuthFields, @@ -25,6 +28,7 @@ async def get_sleep( ) -> SleepData | None: pass + @abstractmethod def parse_oauth_fields( self, response_data: dict[str, str], diff --git a/slackhealthbot/domain/remoterepository/remoteslackrepository.py b/slackhealthbot/domain/remoterepository/remoteslackrepository.py index 58d97acd..f8ea23f4 100644 --- a/slackhealthbot/domain/remoterepository/remoteslackrepository.py +++ b/slackhealthbot/domain/remoterepository/remoteslackrepository.py @@ -1,6 +1,7 @@ -from abc import ABC +from abc import ABC, abstractmethod class RemoteSlackRepository(ABC): + @abstractmethod async def post_message(self, message: str): pass diff --git a/slackhealthbot/domain/remoterepository/remotewithingsrepository.py b/slackhealthbot/domain/remoterepository/remotewithingsrepository.py index 7009e9c2..c735e0c6 100644 --- a/slackhealthbot/domain/remoterepository/remotewithingsrepository.py +++ b/slackhealthbot/domain/remoterepository/remotewithingsrepository.py @@ -1,16 +1,18 @@ -from abc import ABC +from abc import ABC, abstractmethod from slackhealthbot.core.models import OAuthFields class RemoteWithingsRepository(ABC): + @abstractmethod async def subscribe( self, oauth_fields: OAuthFields, ): pass + @abstractmethod async def get_last_weight_kg( self, oauth_fields: OAuthFields, @@ -19,6 +21,7 @@ async def get_last_weight_kg( ) -> float | None: pass + @abstractmethod def parse_oauth_fields( self, response_data: dict[str, str],