diff --git a/klab/public/tests.py b/klab/public/tests.py index 6b22938..7d12ff1 100644 --- a/klab/public/tests.py +++ b/klab/public/tests.py @@ -1,5 +1,8 @@ import string +import mock from random import choice +from klab import flickr +from xml.etree import ElementTree from klab.tests import Helpers from klab.blog.models import Post from klab.members.models import Application, Member @@ -54,15 +57,22 @@ def setUp(self): created_by=self.user, modified_by=self.user) - def test_main_page_with_post_past_event(self): + self.data = ElementTree.fromstring(' ') + + + @mock.patch('flickrapi.FlickrAPI.walk') + def test_main_page_with_post_past_event(self, mock_flickr): self.create_event(-1, "$500k Investment Lessons From Seedstars World 2016", "This Thursday meet Louis Antoine Muhire, CEO& Founder of Mergims, who is going to clear;y highlight and broadly describe the $500k Investment lessons From Seedstars World 2016.") + mock_flickr.return_value = self.data response = self.client.get(reverse('public_home')) self.assertEqual(response.status_code, 200) self.assertQuerysetEqual(response.context['recent'], ['']) self.assertQuerysetEqual(response.context['upcoming'], []) - def test_main_page_with_post_event(self): + @mock.patch('flickrapi.FlickrAPI.walk') + def test_main_page_with_post_event(self, mock_flickr): self.create_event(0, "Demo Night by Skyline Digital", "This Wednesday,kLab based startup Skyline Digital that is to officially launch 2 platforms,namely rwandait.rw, which will be covering all IT news in Rwanda") + mock_flickr.return_value = self.data response = self.client.get(reverse('public_home')) self.assertEqual(response.status_code, 200) self.assertQuerysetEqual(response.context['recent'], ['']) @@ -73,7 +83,9 @@ def test_event_detail(self): response = self.client.get(reverse('solo_event', args=(event.id, ))) self.assertContains(response, event.title, status_code=200) - def test_post_detail(self): + @mock.patch('flickrapi.FlickrAPI.walk') + def test_post_detail(self, mock_flickr): + mock_flickr.return_value = self.data response = self.client.get(reverse('public_post', args=(self.post.id, ))) self.assertContains(response, self.post.title, status_code=200) diff --git a/klab/public/views.py b/klab/public/views.py index 0730b0f..64e6f43 100644 --- a/klab/public/views.py +++ b/klab/public/views.py @@ -33,7 +33,6 @@ class ContactForm(forms.Form): email = forms.EmailField() message = forms.CharField(widget=forms.widgets.Textarea()) - def home(request): try: @@ -100,7 +99,7 @@ def blog(request): def post(request, post_id): post = get_object_or_404(Post, pk=post_id) - + context = dict(post=post) return render(request, 'public/post.html', context) @@ -111,7 +110,7 @@ def projects(request, project_type): else: projects = Project.objects.filter(is_active=True).order_by('-created_on') - + search = request.REQUEST.get("search",None) if search: tokens = search.strip().split() @@ -144,7 +143,7 @@ def members(request, member_type): members = Member.objects.filter(is_active=True, is_alumni=True).order_by('membership_type') else: members = Member.objects.filter(is_active=True, is_alumni=False).order_by('membership_type') - + search = request.REQUEST.get("search",None) if search: tokens = search.strip().split() @@ -160,8 +159,8 @@ def members(request, member_type): def member(request, member_id): member = get_object_or_404(Member, pk=member_id) - - + + context = dict(member=member,project=project) return render(request, 'public/member.html', context)