Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

view with tests to check i all the images are generated or not

  • Loading branch information...
commit e24511975bf3a0d6f07fcea33f1200988150bddc 1 parent 2f159a3
@kausikram kausikram authored
Showing with 44 additions and 5 deletions.
  1. +25 −2 make_my_badge/badge/tests.py
  2. +19 −3 make_my_badge/badge/views.py
View
27 make_my_badge/badge/tests.py
@@ -4,13 +4,13 @@
Replace this with more appropriate tests for your application.
"""
-
+import simplejson
from django.test import TestCase
from django.http import HttpRequest
from django.contrib.auth.models import User
from badge.models import Event, Item
-from badge.views import generate_badges
+from badge.views import generate_badges, are_badges_ready
class GenerateBadgeViewTest(TestCase):
def test_generate_badge_returns_ok(self):
@@ -23,3 +23,26 @@ def test_generate_badge_returns_ok(self):
self.assertEquals(200,response.status_code)
self.assertEquals("application/json",response["Content-Type"])
+
+class AreBadgesReadyViewTest(TestCase):
+ def test_generate_badge_returns_false_when_blank_files_exist(self):
+ u = User.objects.create_user("test","test@test.com","pass")
+ e = Event.objects.create(name="Test",user = u)
+ i = Item.objects.create(event=e,name="Blah",properties="{}")
+ request = HttpRequest()
+ request.GET = {}
+ response = are_badges_ready(request,e.id)
+ self.assertEquals(200,response.status_code)
+ self.assertEquals("application/json",response["Content-Type"])
+ self.assertEquals(False,simplejson.loads(response.content)["status"]["ready"])
+
+ def test_generate_badge_returns_true_when_operation_is_complete(self):
+ u = User.objects.create_user("test","test@test.com","pass")
+ e = Event.objects.create(name="Test",user = u)
+ request = HttpRequest()
+ request.GET = {}
+ response = are_badges_ready(request,e.id)
+ self.assertEquals(200,response.status_code)
+ self.assertEquals("application/json",response["Content-Type"])
+ self.assertEquals(True,simplejson.loads(response.content)["status"]["ready"])
+
View
22 make_my_badge/badge/views.py
@@ -3,7 +3,7 @@
from django.views.generic.list_detail import object_list
from django.http import HttpResponse
-from badge.models import Item
+from badge.models import Item, Event
from badge.tasks import generate_badge
def index(request):
@@ -19,8 +19,24 @@ def generate_badges(request,event_id):
for item in item_list:
generate_badge.delay(item)
r = HttpResponse()
- response_obj = {"statu":{"message":"ok"}}
+ response_obj = {"status":{"message":"ok"}}
r.content = simplejson.dumps(response_obj)
r["Content-Type"] = "application/json"
r.status_code = 200
- return r
+ return r
+
+def are_badges_ready(request,event_id):
+ e = Event.objects.get(id=int(event_id))
+ item_count = Item.objects.filter(event=e,generated_image="").count()
+ ready = True
+ if item_count > 0:
+ ready = False
+
+ response_obj = {"status":{"ready":ready}}
+ r = HttpResponse()
+ r.content = simplejson.dumps(response_obj)
+ r["Content-Type"] = "application/json"
+ r.status_code = 200
+ return r
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.