************************* G4 reminder *************************
These new files:
/home/baran/p4clients/projects/gears/googleclient/gears/opensource/gears/test/testcases/cgi/location_provider.py
are missing unit tests.
***************************************************************
Hello steveblock, playmobil,
*** Reviewers, your power to run g4 approve -c 8228214 is required ***
I'd like you to do a code review. Please execute
g4 diff -c 8228214
or point your web browser to
http://mondrian/8228214
to review the following code:
Change 8228214 by [EMAIL PROTECTED] on 2008/09/10 15:05:07 *pending*
Adds a new cgi script, which acts as a dummy location provider for
end-to-end Geolocation
API testing.
It contains hardcoded information and logic that returns the desired
position fix as JSON
string, triggered by special mac address and cell_id values.
This is very primitive, and it should evolve as needed by the test
cases.
PRESUBMIT=passed
R=steveblock,playmobil
CC=ace,[email protected]
DELTA=97 (97 added, 0 deleted, 0 changed)
OCL=8228214
Affected files ...
...
//depot/googleclient/gears/opensource/gears/test/testcases/cgi/location_provider.py#1
add
97 delta lines: 97 added, 0 deleted, 0 changed
Also consider running:
g4 lint -c 8228214
which verifies that the changelist doesn't introduce new style violations.
If you can't do the review, please let me know as soon as possible. During
your review, please ensure that all new code has corresponding unit tests and
that existing unit tests are updated appropriately. Visit
http://www/eng/code_review.html for more information.
This is a semiautomated message from "g4 mail". Complaints or suggestions?
Mail [EMAIL PROTECTED]
Change 8228214 by [EMAIL PROTECTED] on 2008/09/10 15:05:07 *pending*
Adds a new cgi script, which acts as a dummy location provider for
end-to-end Geolocation
API testing.
It contains hardcoded information and logic that returns the desired
position fix as JSON
string, triggered by special mac address and cell_id values.
This is very primitive, and it should evolve as needed by the test
cases.
Affected files ...
...
//depot/googleclient/gears/opensource/gears/test/testcases/cgi/location_provider.py#1
add
====
//depot/googleclient/gears/opensource/gears/test/testcases/cgi/location_provider.py#1
-
/home/baran/p4clients/projects/gears/googleclient/gears/opensource/gears/test/testcases/cgi/location_provider.py
====
# action=add type=xtext
--- /dev/null 1970-01-01 01:00:00.000000000 +0000
+++ googleclient/gears/opensource/gears/test/testcases/cgi/location_provider.py
2008-09-10 15:08:51.000000000 +0100
@@ -0,0 +1,97 @@
+
+
+class FixRequest(object):
+ """ An class to help inspect the fix request content."""
+
+ def __init__(self, request_body):
+ """ The request_body has to be a well formed json string."""
+
+ json_decoder = simplejson.JSONDecoder()
+ self.request = json_decoder.decode(request_body)
+
+ def __has_value_in_fix_request(self, exp_value, key_name, dic_name) :
+ dic = []
+ if self.request.has_key(dic_name) :
+ dic = self.request[dic_name]
+ found = False
+ for item in dic :
+ value = None
+ if item.has_key(key_name) :
+ value = item[key_name]
+ if value == exp_value :
+ found = True
+
+ return found
+
+ def has_mac_address(self, mac_address) :
+ """ Check if the given mac address exist in the fix request. """
+ return self.__has_value_in_fix_request(mac_address,
+ 'mac_address',
+ 'wifi_towers'
+ )
+
+ def has_cell_id(self, cell_id) :
+ """ Check if the given mac address exist in the fix request. """
+ return self.__has_value_in_fix_request(cell_id, 'cell_id', 'cell_towers')
+
+
+# The CGI scriptlet below, acts as a dummy location provider, which returns
+# desired JSON responses triggered by special values in the fix_request.
+# The complexity of this dummy provider will be driven as needed by the test
+# cases, currently the mapping between the desired response to the triggering
+# values are hard coded.
+fix_request = None
+json_response = None
+
+
+# Custom json responses.
+GOOD_JSON_RESPONSE = """{
+ "location": {
+ "latitude": 51.590722643120145,
+ "longitude": -1.494140625,
+ "altitude": 30,
+ "horizontal_accuracy": 1200,
+ "vertical_accuracy": 10,
+ "address": {
+ "street_number": "76",
+ "street": "Buckingham Palace Road",
+ "postal_code": "SW1W 9TQ",
+ "city": "London",
+ "county": "London",
+ "region": "London",
+ "country": "United Kingdom",
+ "country_code": "uk"
+ }
+ }
+}"""
+
+
+NO_LOCATION_JSON_RESPONSE = """{}"""
+
+
+def send_response(out, code, response) :
+ out.send_response(code)
+ if code == 200 :
+ out.send_header('Content-type', 'application/json')
+ out.end_headers()
+ out.outgoing.append (response)
+
+
+# Only respond if the request is a POST
+if self.command == 'POST':
+ if self.body :
+ request_body = self.body.popitem()[0]
+ fix_request = FixRequest(request_body)
+
+ # Hardcoded rules to return desired responses
+ if fix_request.has_mac_address("good_mac_address") :
+ send_response(self, 200, GOOD_JSON_RESPONSE)
+ elif fix_request.has_mac_address("no_location_mac_address") :
+ send_response(self, 200, NO_LOCATION_JSON_RESPONSE)
+ elif fix_request.has_cell_id(88) :
+ send_response(self, 400, "Error in request")
+
+else :
+ send_response(self, 500, "Please provide a POST method")
+
+