[blipit] r171 committed - Adding a test for the send method in task

0 views
Skip to first unread message

bli...@googlecode.com

unread,
Jan 16, 2011, 1:15:40 PM1/16/11
to bli...@googlegroups.com
Revision: 171
Author: dipt...@gmail.com
Date: Sun Jan 16 10:14:50 2011
Log: Adding a test for the send method in task
http://code.google.com/p/blipit/source/detail?r=171

Modified:
/trunk/blipitsms/geocoder/app.py
/trunk/blipitsms/geocoder/blip.py
/trunk/blipitsms/geocoder/tasks.py
/trunk/blipitsms/geocoder/tests.py

=======================================
--- /trunk/blipitsms/geocoder/app.py Sun Jan 16 00:53:32 2011
+++ /trunk/blipitsms/geocoder/app.py Sun Jan 16 10:14:50 2011
@@ -13,8 +13,11 @@
channel_list.append(blip.Channel(channel.channel_id))

if len(channel_list) is not 0:
- tasks.send(msg.connection.identity,
msg_txt[1].replace(","," "), channel_list, msg)
- msg.respond("We are processing your request")
+ result = tasks.send(msg.connection.identity,
msg_txt[1].replace(","," "), channel_list, msg)
+ if result:
+ msg.respond("We have added your request to our queue")
+ else:
+ msg.respond("Sorry the Geo-Coding service has failed.")
return

msg.respond("Sorry, we do not have a channel called %s" %
(msg_txt[0],))
=======================================
--- /trunk/blipitsms/geocoder/blip.py Sun Jan 16 05:45:54 2011
+++ /trunk/blipitsms/geocoder/blip.py Sun Jan 16 10:14:50 2011
@@ -8,6 +8,8 @@
def __init__(self, latitude, longitude):
self['latitude'] = latitude
self['longitude'] = longitude
+
+import json

class Blip(dict):

@@ -18,7 +20,10 @@
self['title'] = title
self['creatorId'] = creatorId

-import urllib2, json
+ def get_json(self):
+ return json.dumps(self)
+
+import urllib2
from django.conf import settings

class BlipItPost:
@@ -29,7 +34,6 @@
self.blip = blip

def post(self):
- json_data = json.dumps(self.blip)
- request = urllib2.Request(self.url, json_data)
+ request = urllib2.Request(self.url, self.blip.get_json())
response = urllib2.urlopen(request)
return
=======================================
--- /trunk/blipitsms/geocoder/tasks.py Sun Jan 16 06:14:05 2011
+++ /trunk/blipitsms/geocoder/tasks.py Sun Jan 16 10:14:50 2011
@@ -18,7 +18,7 @@


@task
-def send(phone_number, address, channel_list, msg):
+def send(phone_number, address, channel_list):
url = settings.GEOCODER_SVC_URL + urllib.quote_plus(address)
url_request = urllib2.urlopen(url)
response = url_request.read()
@@ -29,9 +29,9 @@
blip = Blip(channel_list, "PANIC SMS", GeoPoint(latitude,
longitude), "PANIC SMS", phone_number)
blipItPost = BlipItPost(blip)
blipItPost.post()
- msg.respond("We have added your request to our queue")
- return
-
- msg.respond("Sorry the Geo-Coding service has failed.")
+
+ return True
+
+ return False


=======================================
--- /trunk/blipitsms/geocoder/tests.py Sun Jan 16 06:16:50 2011
+++ /trunk/blipitsms/geocoder/tests.py Sun Jan 16 10:14:50 2011
@@ -2,6 +2,7 @@
from mock import Mock

import tasks
+from blip import Channel

class GeoCoderTest(unittest.TestCase):
test_json_data
= '[{"key":{"kind":"Channel","id":3001},"name":"panic1","category":{"category":"PANIC"}},\
@@ -17,3 +18,15 @@
urlopen.read = Mock(return_value = self.test_json_data)
channel_objs = tasks.scan_channels(urlopen)
self.assertEqual(len(channel_objs.all()), 7)
+
+ def test_send_correct_address(self):
+ addr = "1600 Amphitheatre Parkway,Mountain+View,CA"
+ channel_list = [Channel(12), Channel(13)]
+ result = tasks.send(123, addr, channel_list)
+ self.assertEqual(result,True)
+
+ def test_send_wrong_address(self):
+ addr = "1600 KoramanagalIndi"
+ channel_list = [Channel(12), Channel(13)]
+ result = tasks.send(123, addr, channel_list)
+ self.assertEqual(result,False)

Reply all
Reply to author
Forward
0 new messages