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 test by mocking real flickrapi response #30

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions klab/public/tests.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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('<photos page="2" pages="89" perpage="10" total="881"><photo id="2636" owner="47058503995@N01" secret="a123456" server="2" title="test_04" ispublic="1" isfriend="0" isfamily="0" /> <photo id="2635" owner="47058503995@N01" secret="b123456" server="2" title="test_03" ispublic="0" isfriend="1" isfamily="1" /><photo id="2633" owner="47058503995@N01" secret="c123456" server="2" title="test_01" ispublic="1" isfriend="0" isfamily="0" /><photo id="2610" owner="12037949754@N01" secret="d123456" server="2" title="00_tall" ispublic="1" isfriend="0" isfamily="0" /></photos>')


@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'], ['<Post: Apply for Global Entrepreneurship Summit>'])
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'], ['<Post: Apply for Global Entrepreneurship Summit>'])
Expand All @@ -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)

Expand Down
11 changes: 5 additions & 6 deletions klab/public/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class ContactForm(forms.Form):
email = forms.EmailField()
message = forms.CharField(widget=forms.widgets.Textarea())


def home(request):

try:
Expand Down Expand Up @@ -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)

Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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)

Expand Down