Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
opaduchak committed Nov 1, 2024
1 parent 81471a5 commit df09420
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
28 changes: 28 additions & 0 deletions osf_tests/external/gravy_valet/gv_fakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ def _serialize_relationships(self):
accounts_relationship = self._format_relationship_entry(relationship_path='authorized_storage_accounts')
return {'authorized_storage_accounts': accounts_relationship}

@dataclasses.dataclass(frozen=True)
class _FakeWBCredentials(_FakeGVEntity):

RESOURCE_TYPE = 'waterbutler-credentials'
config: dict

def _serialize_attributes(self):
return {'config': self.config}

def _serialize_relationships(self):
return {}

@dataclasses.dataclass(frozen=True)
class _FakeResourceReference(_FakeGVEntity):

Expand Down Expand Up @@ -209,6 +221,7 @@ class FakeGravyValet:
r'v1/resource-references(/(?P<pk>\d+)|(\?filter\[resource_uri\]=(?P<resource_uri>[^&]+)))': '_get_resource',
r'v1/authorized-storage-accounts/(?P<pk>\d+)': '_get_account',
r'v1/configured-storage-addons/(?P<pk>\d+)': '_get_addon',
r'v1/configured-storage-addons/(?P<pk>\d+)/waterbutler-credentials': '_get_wb_settings',
r'v1/user-references/(?P<user_pk>\d+)/authorized_storage_accounts': '_get_user_accounts',
r'v1/resource-references/(?P<resource_pk>\d+)/configured_storage_addons': '_get_resource_addons',
}
Expand Down Expand Up @@ -374,6 +387,21 @@ def _get_user(
include_param=include_param,
)

def _get_wb_settings(
self,
headers: dict,
pk: str,
include_param: str = '',
) -> str:
creds = _FakeWBCredentials(
pk=10,
config={
'folder': pk,
'service': 'box',
}
)
return _format_response_body(creds)

def _get_resource(
self,
headers: dict,
Expand Down
20 changes: 10 additions & 10 deletions osf_tests/test_gv_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,13 +532,13 @@ def test_make_ephemeral_node_settings(self, contributor, project, fake_box_addon
requesting_user=contributor,
requested_resource=project,
)
ephemeral_config = translations.make_ephemeral_node_settings(
addon_data, requesting_user=contributor, requested_resource=project
)
assert ephemeral_config.short_name == 'box'
assert ephemeral_config.gv_id == fake_box_addon.pk
assert ephemeral_config.config.name == 'addons.box'
assert ephemeral_config.serialize_waterbutler_settings() == {
'folder': fake_box_addon.root_folder.split(':')[1],
'service': 'box'
}
ephemeral_config = translations.make_ephemeral_node_settings(
addon_data, requesting_user=contributor, requested_resource=project
)
assert ephemeral_config.short_name == 'box'
assert ephemeral_config.gv_id == fake_box_addon.pk
assert ephemeral_config.config.name == 'addons.box'
assert ephemeral_config.serialize_waterbutler_settings() == {
'folder': fake_box_addon.root_folder.split(':')[1],
'service': 'box'
}

0 comments on commit df09420

Please sign in to comment.