Chromium Code Reviews| Index: net/tools/testserver/chromiumsync.py |
| diff --git a/net/tools/testserver/chromiumsync.py b/net/tools/testserver/chromiumsync.py |
| index a8a939c3a68b75eb86c4c950014fbdc21d1bed8a..7cfa837383bcc762d45cd61f3baacb295b7e11ab 100755 |
| --- a/net/tools/testserver/chromiumsync.py |
| +++ b/net/tools/testserver/chromiumsync.py |
| @@ -104,6 +104,9 @@ class StoreBirthdayError(Error): |
| class TransientError(Error): |
| """The client would be sent a transient error.""" |
| +class SyncError(Error): |
| + """The client would be sent an error.""" |
| + |
| def GetEntryType(entry): |
| """Extract the sync type from a SyncEntry. |
| @@ -415,6 +418,10 @@ class SyncDataModel(object): |
| self.migration_history = MigrationHistory() |
| + self.error = sync_pb2.ClientToServerResponse.Error() |
| + |
| + self.send_error = False |
| + |
| def _SaveEntry(self, entry): |
| """Insert or update an entry in the change log, and give it a new version. |
| @@ -922,6 +929,11 @@ class TestServer(object): |
| if self.transient_error: |
| raise TransientError |
| + def CheckSendError(self): |
| + """Raises SyncError if the variable is set.""" |
| + if self.account.send_error: |
| + raise SyncError |
| + |
| def HandleMigrate(self, path): |
| query = urlparse.urlparse(path)[4] |
| code = 200 |
| @@ -944,6 +956,38 @@ class TestServer(object): |
| return (code, '<html><title>Migration: %d</title><H1>%d %s</H1></html>' % |
| (code, code, response)) |
| + def HandleSetError(self, path): |
| + query = urlparse.urlparse(path)[4] |
| + self.account_lock.acquire() |
| + code = 200; |
| + response = 'Success' |
| + try: |
| + error_type = urlparse.parse_qs(query)['error'] |
| + action = urlparse.parse_qs(query)['action'] |
| + self.account.error.error_type = int(error_type[0]) |
| + self.account.error.action = int(action[0]) |
| + self.account.send_error = True |
| + try: |
| + self.account.error.url = (urlparse.parse_qs(query)['url'])[0] |
| + except KeyError: |
| + self.account.error.url = '' |
| + try: |
| + self.account.error.error_description = \ |
| + (urlparse.parse_qs(query)['error_description'])[0] |
| + except KeyError: |
| + self.account.error.error_description = '' |
| + response = ('Error = %d, action = %d, url = %s, description = %s' % |
| + (self.account.error.error_type, self.account.error.action, |
| + self.account.error.url, |
| + self.account.error.error_description)) |
| + except error: |
| + response = 'Could not parse url' |
| + code = 400 |
| + finally: |
| + self.account_lock.release() |
| + return (code, '<html><title>SetError: %d</title><H1>%d %s</H1></html>' % |
| + (code, code, response)) |
| + |
| def HandleCreateBirthdayError(self): |
| self.account.ResetStoreBirthday() |
| return ( |
| @@ -992,6 +1036,7 @@ class TestServer(object): |
| self.CheckStoreBirthday(request) |
| response.store_birthday = self.account.store_birthday |
| self.CheckTransientError(); |
| + self.CheckSendError(); |
| print_context('->') |
| @@ -1030,11 +1075,21 @@ class TestServer(object): |
| response.error_code = sync_pb2.ClientToServerResponse.NOT_MY_BIRTHDAY |
| return (200, response.SerializeToString()) |
| except TransientError, error: |
| + ### This is deprecated now. Would be remvoved once test cases are removed. |
|
Raghu Simha
2011/09/19 22:25:02
I think the Python style guide recommends a single
lipalani1
2011/09/22 20:42:46
Incorrectly ended up in this cl. removed.
On 2011/
Raghu Simha
2011/09/22 21:15:10
My bad -- looks like this came in from a different
|
| print_context('<-') |
| print 'TRANSIENT_ERROR' |
| response.store_birthday = self.account.store_birthday |
| response.error_code = sync_pb2.ClientToServerResponse.TRANSIENT_ERROR |
| return (200, response.SerializeToString()) |
| + except SyncError, error: |
| + print_context('<-') |
| + print 'ERROR' |
| + response.store_birthday = self.account.store_birthday |
| + response.error.error_type = self.account.error.error_type |
| + response.error.url = self.account.error.url |
| + response.error.error_description = self.account.error.error_description |
| + response.error.action = self.account.error.action |
| + return (200, response.SerializeToString()) |
| finally: |
| self.account_lock.release() |