Skip to content

Commit

Permalink
Add tests to assets list and asset
Browse files Browse the repository at this point in the history
  • Loading branch information
patryk-dabrowski committed May 17, 2024
1 parent 50564d8 commit aa7904d
Show file tree
Hide file tree
Showing 6 changed files with 13,300 additions and 6 deletions.
8 changes: 5 additions & 3 deletions backend/hct_mis_api/apps/core/kobo/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class KoboRequestsSession(requests.Session):

def should_strip_auth(self, old_url: str, new_url: str) -> bool:
new_parsed = urlparse(new_url)
if new_parsed.hostname in KoboRequestsSession.AUTH_DOMAINS:
if new_parsed.hostname in KoboRequestsSession.AUTH_DOMAINS: # pragma: no cover
return False
return super().should_strip_auth(old_url, new_url) # type: ignore # FIXME: Call to untyped function "should_strip_auth" in typed context

Expand Down Expand Up @@ -70,7 +70,9 @@ def _get_request(self, url: str) -> Response:
raise
return response

def _post_request(self, url: str, data: Optional[Dict] = None, files: Optional[typing.IO] = None) -> Response:
def _post_request(
self, url: str, data: Optional[Dict] = None, files: Optional[typing.IO] = None
) -> Response: # pragma: no cover
return self._client.post(url=url, data=data, files=files)

def create_template_from_file(
Expand Down Expand Up @@ -154,6 +156,6 @@ def get_project_submissions(self, uid: str, only_active_submissions: bool) -> Li
url = f"{self._kpi_url}/{endpoint}?{query_params}"
return self._get_paginated_request(url)

def get_attached_file(self, url: str) -> BytesIO:
def get_attached_file(self, url: str) -> BytesIO: # pragma: no cover
response = self._get_request(url)
return BytesIO(response.content)
6 changes: 3 additions & 3 deletions backend/hct_mis_api/apps/core/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def resolve_asset(business_area_slug: str, uid: str) -> Dict:
except ObjectDoesNotExist as e:
logger.exception(f"Provided business area: {business_area_slug}, does not exist.")
raise GraphQLError("Provided business area does not exist.") from e
except AttributeError as error:
except AttributeError as error: # pragma: no cover
logger.exception(error)
raise GraphQLError(str(error)) from error

Expand All @@ -304,12 +304,12 @@ def resolve_assets_list(business_area_slug: str, only_deployed: bool = False) ->
)
assets = KoboAPI(token=business_area.get_kobo_token()).get_all_projects_data(business_area.country_code)

if not config.KOBO_ENABLE_SINGLE_USER_ACCESS:
if not config.KOBO_ENABLE_SINGLE_USER_ACCESS: # pragma: no cover
assets = filter_by_owner(assets, business_area.kobo_username)
except ObjectDoesNotExist as e:
logger.exception(f"Provided business area: {business_area_slug}, does not exist.")
raise GraphQLError("Provided business area does not exist.") from e
except AttributeError as error:
except AttributeError as error: # pragma: no cover
logger.exception(error)
raise GraphQLError(str(error)) from error
except CountryCodeNotProvided:
Expand Down
Loading

0 comments on commit aa7904d

Please sign in to comment.