Skip to content

Commit

Permalink
[#3734] Replace my_projects url with the new project listing URL
Browse files Browse the repository at this point in the history
  • Loading branch information
punchagan committed Aug 9, 2019
1 parent 3d00e08 commit 85cf5e2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 66 deletions.
66 changes: 1 addition & 65 deletions akvo/rsr/tests/views/test_my_rsr.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from django.test import TestCase, Client
from lxml import html

from akvo.rsr.models import Employment, Organisation, Project, User, Partnership, UserProjects
from akvo.rsr.models import Employment, Organisation, User
from akvo.rsr.views.my_rsr import manageable_objects
from akvo.utils import check_auth_groups

Expand Down Expand Up @@ -62,43 +62,6 @@ def test_user_management_employments_ordering(self):
(self.user1.id, u'Admins'),
(self.user1.id, u'Users')])

def test_search_with_long_query_strings_works(self):
"""Test that search works with long query strings.
*NOTE*: This test was written to ensure that the search works correctly
when refactoring the code to make searches with long query strings
faster. The test doesn't actually test that the new code is faster and
doesn't timeout, because there's no good way to do this (especially on
a small test database). If ever we start using something like
django_perf_rec, this may be feasible to test.
"""
# Given
title = 'This is a super long project title that will be used as a search query'
Project.objects.create(title=title)
url = '/myrsr/projects?q={}'.format(title.replace(' ', '+'))

# When
response = self.c.get(url, follow=True)

# Then
self.assertEqual(200, response.status_code)
self.assertIn(title, response.content)

def test_search_filters_projects(self):
# Given
title = 'Project Title'
query = 'search query'
Project.objects.create(title=title)
url = '/myrsr/projects?q={}'.format(query.replace(' ', '+'))

# When
response = self.c.get(url, follow=True)

# Then
self.assertEqual(200, response.status_code)
self.assertNotIn(title, response.content)

def _create_user(self, email, password, is_active=True, is_admin=False):
"""Create a user with the given email and password."""

Expand All @@ -113,33 +76,6 @@ def _create_user(self, email, password, is_active=True, is_admin=False):

return user

def test_projects_access_restrictions(self):
# Given an org with two projects
project1 = Project.objects.create(title='Project 1')
project1.publish()
project2 = Project.objects.create(title='Project 2')
project2.publish()
Partnership.objects.create(organisation=self.org, project=project1)
Partnership.objects.create(organisation=self.org, project=project2)
Employment.objects.create(
user=self.user3, organisation=self.org, group=self.user_group, is_approved=True
)

# When project1 is added to user1's project white list
white_list = UserProjects.objects.create(user=self.user3, is_restricted=True,)
white_list.projects.add(project1)

# Then user1's project list should include only project1
self.c.login(username=self.user3.username, password=self.password)
url = '/myrsr/projects'
response = self.c.get(url, follow=True)
from BeautifulSoup import BeautifulSoup
soup = BeautifulSoup(response.content)

self.assertEqual(len(soup.findAll('table')), 1)
# There should be two table rows: one header and one for project1
self.assertEqual(len(soup.findAll('table')[0].findChildren('tr')), 2)

def test_manageable_objects_employments_is_admin_can_manage_all(self):
# Given a user that is_admin
# When employments for two different organisations exist
Expand Down
3 changes: 2 additions & 1 deletion akvo/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.conf.urls.i18n import i18n_patterns
from django.views.static import serve
from django.views.generic import RedirectView

from akvo.rsr import views
from akvo.rsr.views import account
Expand Down Expand Up @@ -134,7 +135,7 @@
my_rsr.my_updates, name='my_updates'),

url(r'^myrsr/projects/$',
my_rsr.my_projects, name='my_projects'),
RedirectView.as_view(url='/my-rsr/projects/'), name='my_projects'),

url(r'^myrsr/project_editor/(?P<project_id>\d+)/$',
my_rsr.project_editor, name='project_editor'),
Expand Down

0 comments on commit 85cf5e2

Please # to comment.