Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database split part II: KobocatDeploymentBackend refactoring #2186

Merged
merged 31 commits into from
Jul 2, 2019

Conversation

noliveleger
Copy link
Contributor

@noliveleger noliveleger commented Feb 7, 2019

Based on #2155.

Fixes #2036

Because some parts of the code in KobocatDeploymentBackend and KobocatDataProxyViewSetMixin were doing the same thing, KobocatDeploymentBackend has been refactoring to regroup all the logic for kc proxy.

Even SubmissionViewSet has been refactored to use new methods of KobocatDeploymentBackend and to benefit PROs of DRF (permissions, renderers)

A new viewset has been created to handle hook signals from kobocat (Don't merge until kobotoolbox/kobocat#523 is reviewed and merged too)

@noliveleger noliveleger changed the title KobocatDeploymentBackend refactoring Databases split part II: KobocatDeploymentBackend refactoring Mar 11, 2019
@noliveleger noliveleger changed the title Databases split part II: KobocatDeploymentBackend refactoring Database split part II: KobocatDeploymentBackend refactoring Mar 11, 2019
@noliveleger noliveleger changed the base branch from master to 2155-kc-database-connection May 21, 2019 21:23
@noliveleger noliveleger changed the base branch from 2155-kc-database-connection to master May 21, 2019 21:24
Copy link
Member

@jnm jnm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfinished review; submitting so @noliveleger can see my comments

kobo/apps/hook/tests/test_api_hook.py Outdated Show resolved Hide resolved
kpi/deployment_backends/kobocat_backend.py Outdated Show resolved Hide resolved
prepared_drf_response["data"] = json.loads(requests_response.content)
except ValueError as e:
if not requests_response.status_code == status.HTTP_204_NO_CONTENT:
raise Exception(str(e))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Would it be better to re-raise a ValueError instead of a generic Exception?
  • Maybe str(e) should be prefixed with "KoBoCAT returned an unexpected response: " or similar (to avoid the unhelpful No JSON object could be decoded message that people get in the current release)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed the code a little bit.
The error is returned in the response. FE can expose the message to users.
For example, if submission deletion fails, nothing happens. It would be better to display a message to users. (cc @magicznyleszek)

kpi/permissions.py Outdated Show resolved Hide resolved
kpi/tests/test_api_submissions.py Outdated Show resolved Hide resolved

class SubmissionApiTests(BaseTestCase):

def test_create_submission(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say test_cannot_create_submission

kpi/tests/test_api_submissions.py Show resolved Hide resolved

def test_delete_submission_shared_other_write(self):
self._other_user_login(True)
self.asset.assign_perm(self.anotheruser, "change_submissions")
Copy link
Member

@jnm jnm May 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment moved to #2282

"pk": self.submission.get("id")
})

def test_trigger_signal(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which signal?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad test name. Nothing related to signal. I have renamed it.
I also noticed that few others tests were missing (e.g. get edit link for viewers only), so I added them.

kpi/utils/mongo_helper.py Outdated Show resolved Hide resolved
kpi/views.py Outdated Show resolved Hide resolved
kpi/views.py Show resolved Hide resolved
kpi/views.py Show resolved Hide resolved
@noliveleger noliveleger force-pushed the refactor-kobocat-deployment-backend branch from 353d6da to f728b9c Compare May 23, 2019 15:40
@jnm jnm changed the base branch from master to another-master June 25, 2019 17:09
@jnm jnm changed the base branch from another-master to master June 25, 2019 17:09
Copy link
Member

@jnm jnm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's have a call and go through this together

kpi/deployment_backends/kobocat_backend.py Show resolved Hide resolved
kobo/settings/testing.py Show resolved Hide resolved
kpi/deployment_backends/kobocat_backend.py Outdated Show resolved Hide resolved
kpi/deployment_backends/kobocat_backend.py Outdated Show resolved Hide resolved
kpi/deployment_backends/kobocat_backend.py Outdated Show resolved Hide resolved
kpi/utils/mongo_helper.py Outdated Show resolved Hide resolved
kpi/utils/mongo_helper.py Show resolved Hide resolved
kpi/views.py Outdated Show resolved Hide resolved
kpi/views.py Outdated Show resolved Hide resolved
kpi/views.py Outdated Show resolved Hide resolved
@jnm jnm merged commit dbef706 into master Jul 2, 2019
@jnm jnm deleted the refactor-kobocat-deployment-backend branch July 3, 2019 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor SubmissionViewSet to use KobocatBackend.get_submissions()
2 participants