Skip to content

Commit

Permalink
refactor: [AXM-1227, AXM-1235, AXM-1242] refactor tests a bit, fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrylo-kh committed Dec 20, 2024
1 parent eec0606 commit 00e51d9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 13 deletions.
9 changes: 1 addition & 8 deletions credentials/apps/badges/accredible/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ def get_api_config(self) -> AccredibleAPIConfig:
Returns the API configuration object for the Accredible API.
"""
try:
api_config = AccredibleAPIConfig.objects.get(id=self.api_config_id)
return api_config
return AccredibleAPIConfig.objects.get(id=self.api_config_id)
except AccredibleAPIConfig.DoesNotExist:
raise AccredibleError(f"AccredibleAPIConfig with the id {self.api_config_id} does not exist!")

Expand All @@ -50,7 +49,6 @@ def _get_headers(self) -> dict:
"""
Returns the headers for making API requests to Accredible.
"""

return {
"Accept": "application/json",
"Content-Type": "application/json",
Expand All @@ -61,14 +59,12 @@ def fetch_all_groups(self) -> dict:
"""
Fetch all groups.
"""

return self.perform_request("get", "issuer/all_groups")

def fetch_design_image(self, design_id: int) -> str:
"""
Fetches the design and return the URL of image.
"""

design_raw = self.perform_request("get", f"designs/{design_id}")
return design_raw.get("design", {}).get("rasterized_content_url")

Expand All @@ -79,7 +75,6 @@ def issue_badge(self, issue_badge_data: AccredibleBadgeData) -> dict:
Args:
issue_badge_data (IssueBadgeData): Data required to issue the badge.
"""

return self.perform_request("post", "credentials", asdict(issue_badge_data))

def revoke_badge(self, badge_id, data: AccredibleExpireBadgeData) -> dict:
Expand All @@ -90,7 +85,6 @@ def revoke_badge(self, badge_id, data: AccredibleExpireBadgeData) -> dict:
badge_id (str): ID of the badge to revoke.
data (dict): Additional data for the revocation.
"""

return self.perform_request("patch", f"credentials/{badge_id}", asdict(data))

def sync_groups(self, site_id: int) -> int:
Expand All @@ -103,7 +97,6 @@ def sync_groups(self, site_id: int) -> int:
Returns:
int | None: processed items.
"""

try:
site = Site.objects.get(id=site_id)
except Site.DoesNotExist:
Expand Down
2 changes: 0 additions & 2 deletions credentials/apps/badges/accredible/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def get_accredible_api_base_url(settings) -> str:
set to a truthy value in the configuration;
otherwise, it will be the production environment's URL.
"""

accredible_config = settings.BADGES_CONFIG["accredible"]

if accredible_config.get("USE_SANDBOX"):
Expand All @@ -37,7 +36,6 @@ def get_accredible_base_url(settings) -> str:
set to a truthy value in the configuration;
otherwise, it will be the production environment's URL.
"""

credly_config = settings.BADGES_CONFIG["accredible"]

if credly_config.get("USE_SANDBOX"):
Expand Down
6 changes: 3 additions & 3 deletions credentials/apps/badges/tests/test_management_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ def setUp(self):
@mock.patch("credentials.apps.badges.management.commands.sync_accredible_groups.AccredibleAPIClient")
def test_handle_no_arguments(self, mock_accredible_api_client):
call_command("sync_accredible_groups")
self.assertEqual(mock_accredible_api_client.call_count, 6)
self.assertEqual(mock_accredible_api_client.return_value.sync_groups.call_count, 6)
self.assertEqual(mock_accredible_api_client.call_count, AccredibleAPIConfig.objects.all().count())
self.assertEqual(mock_accredible_api_client.return_value.sync_groups.call_count, AccredibleAPIConfig.objects.all().count())

@mock.patch("credentials.apps.badges.management.commands.sync_accredible_groups.AccredibleAPIClient")
def test_handle_with_api_config_id(self, mock_accredible_api_client):
call_command("sync_accredible_groups", "--api_config_id", 1)
call_command("sync_accredible_groups", "--api_config_id", self.api_config.id)
mock_accredible_api_client.assert_called_once_with(1)
mock_accredible_api_client.return_value.sync_groups.assert_called_once_with(1)

0 comments on commit 00e51d9

Please sign in to comment.