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

Fix #674: Fix resource count on project dashboard #721

Merged
merged 2 commits into from
Sep 23, 2016
Merged

Conversation

seav
Copy link
Contributor

@seav seav commented Sep 23, 2016

Proposed changes in this pull request

When should this PR be merged

Anytime.

Risks

None foreseen.

Follow up actions

None.

Copy link
Member

@oliverroick oliverroick left a comment

Choose a reason for hiding this comment

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

I think the tests could need some minor improvements for performance. Other than that it's looking good.

@@ -202,12 +206,22 @@ def setup_models(self):
self.user.assign_policies(self.policy)

def setup_template_context(self):
num_locations = self.project.spatial_units.count()
Copy link
Member

Choose a reason for hiding this comment

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

There are four database requests in here that are not necessary to all but one of the tests in this test case. It's slowing down the test run. What I would do is to adapt the response context in self.render_content for that one test. It's quite easy to do, since you know how many entities you have added, you can just add constants there instead of querying the database.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. I've reverted setup_template_context() and moved the test-specific context to render_content().

@@ -363,6 +377,21 @@ def test_get_archived_project_with_org_admin(self):
assert response.status_code == 200
assert response.content == self.render_content(is_administrator=True)

def test_get_with_overview_stats(self):
SpatialUnitFactory.create(project=self.project)
Copy link
Member

Choose a reason for hiding this comment

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

Here you create many records, just to test if the correct count is displayed. The view uses .count() on the queryset, which is a Django method; let's just assume that it works and is well-tested. I can see the case of testing whether .count() is used on all of the querysets in the view and the number is added correctly to the context, but you don't need three parties for that. I would get rid of at on spatial unit and two parties.

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've removed the extra parties and location.

Copy link
Member

@oliverroick oliverroick left a comment

Choose a reason for hiding this comment

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

Looks good, I'll merge when the tests have passed

@oliverroick oliverroick merged commit c340e18 into master Sep 23, 2016
@oliverroick oliverroick deleted the bugfix/#674 branch September 23, 2016 13:28
manoramahp pushed a commit to manoramahp/cadasta-platform that referenced this pull request Sep 27, 2016
* Fix Cadasta#674: Fix resource count on project dashboard

* Resolve review feedback
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.

2 participants