Instantly share code, notes, and snippets.

@morenoh149 /error Secret
Last active Sep 20, 2018

Embed
What would you like to do?
test django view
======================================================================
FAIL: test_profile_by_facebook_user_id (litt-api.polls.tests.test_views.ProfileViewTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/harrymoreno/programming/gatsby/litt-api/polls/tests/test_views.py", line 211, in test_profile_by_facebook_user_id
self.assertEqual(len(info), 1)
AssertionError: 0 != 1
class ProfileViewTest(TestCase):
def test_profile_by_facebook_user_id(self):
user = get_user_model().objects.create_user(
username="testuser3", password="1X<ISRUkw+tuK"
)
user.save()
profile = Profile.objects.last()
profile.facebook_user_id = 'asldkfjasdf'
profile.save()
self.assertIsNotNone(profile.facebook_user_id)
profile = Profile.objects.last()
print(profile.facebook_user_id)
# fetch profile by fb user id
response = self.client.get(
f"{reverse('polls:profile-list')}?facebook_user_id={profile.facebook_user_id}/"
)
print(response.content)
self.assertEqual(response.status_code, 200)
info = json.loads(response.content)
self.assertEqual(len(info), 1)
from django.urls import path
from . import views
app_name = "polls"
urlpatterns = [
path("profile/", views.ProfileView.as_view(), name="profile-list"),
]
@method_decorator(csrf_exempt, name="dispatch")
class ProfileView(ListView):
model = Profile
def get(self, request, *args, **kwargs):
facebook_user_id = request.GET.get("facebook_user_id")
if facebook_user_id:
profile_list = Profile.objects.filter(facebook_user_id=facebook_user_id)
else:
profile_list = []
response = serializers.serialize("json", profile_list)
return HttpResponse(response, content_type="application/json")
def get_success_url(self):
return u"/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment