Merge lp:~thisfred/u1db/quota-error-handling into lp:u1db

Proposed by Eric Casteleijn
Status: Merged
Approved by: Eric Casteleijn
Approved revision: 350
Merged at revision: 350
Proposed branch: lp:~thisfred/u1db/quota-error-handling
Merge into: lp:u1db
Diff against target: 86 lines (+25/-0)
5 files modified
include/u1db/u1db.h (+1/-0)
u1db/errors.py (+6/-0)
u1db/remote/http_errors.py (+1/-0)
u1db/tests/c_backend_wrapper.pyx (+3/-0)
u1db/tests/test_http_client.py (+14/-0)
To merge this branch: bzr merge lp:~thisfred/u1db/quota-error-handling
Reviewer Review Type Date Requested Status
John O'Brien (community) Approve
Review via email: mp+114472@code.launchpad.net

Commit message

added quota error client tests for quota and document too big

Description of the change

added quota error client tests for quota and document too big

To post a comment you must log in.
Revision history for this message
John O'Brien (jdobrien) wrote :

This looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/u1db/u1db.h'
2--- include/u1db/u1db.h 2012-07-09 17:43:47 +0000
3+++ include/u1db/u1db.h 2012-07-11 17:26:19 +0000
4@@ -75,6 +75,7 @@
5 #define U1DB_INVALID_GENERATION -21
6 #define U1DB_TARGET_UNAVAILABLE -22
7 #define U1DB_DOCUMENT_TOO_BIG -23
8+#define U1DB_USER_QUOTA_EXCEEDED -24
9 #define U1DB_INTERNAL_ERROR -999
10
11 // Used by put_doc_if_newer
12
13=== modified file 'u1db/errors.py'
14--- u1db/errors.py 2012-07-09 17:43:47 +0000
15+++ u1db/errors.py 2012-07-11 17:26:19 +0000
16@@ -49,6 +49,12 @@
17 wire_description = "document too big"
18
19
20+class UserQuotaExceeded(U1DBError):
21+ """Document exceeds the maximum document size for this database."""
22+
23+ wire_description = "user quota exceeded"
24+
25+
26 class InvalidTransactionId(U1DBError):
27 """Invalid transaction for generation."""
28
29
30=== modified file 'u1db/remote/http_errors.py'
31--- u1db/remote/http_errors.py 2012-07-09 21:00:06 +0000
32+++ u1db/remote/http_errors.py 2012-07-11 17:26:19 +0000
33@@ -26,6 +26,7 @@
34 (errors.InvalidDocId.wire_description, 400),
35 (errors.Unauthorized.wire_description, 401),
36 (errors.DocumentTooBig.wire_description, 403),
37+ (errors.UserQuotaExceeded.wire_description, 403),
38 (errors.DatabaseDoesNotExist.wire_description, 404),
39 (errors.DocumentDoesNotExist.wire_description, 404),
40 (errors.DocumentAlreadyDeleted.wire_description, 404),
41
42=== modified file 'u1db/tests/c_backend_wrapper.pyx'
43--- u1db/tests/c_backend_wrapper.pyx 2012-07-10 17:55:45 +0000
44+++ u1db/tests/c_backend_wrapper.pyx 2012-07-11 17:26:19 +0000
45@@ -130,6 +130,7 @@
46 int U1DB_NOT_IMPLEMENTED
47 int U1DB_INVALID_JSON
48 int U1DB_DOCUMENT_TOO_BIG
49+ int U1DB_USER_QUOTA_EXCEEDED
50 int U1DB_INVALID_VALUE_FOR_INDEX
51 int U1DB_INVALID_GLOBBING
52 int U1DB_BROKEN_SYNC_STREAM
53@@ -608,6 +609,8 @@
54 raise errors.InvalidJSON
55 if status == U1DB_DOCUMENT_TOO_BIG:
56 raise errors.DocumentTooBig
57+ if status == U1DB_USER_QUOTA_EXCEEDED:
58+ raise errors.UserQuotaExceeded
59 raise RuntimeError('%s (status: %s)' % (context, status))
60
61
62
63=== modified file 'u1db/tests/test_http_client.py'
64--- u1db/tests/test_http_client.py 2012-06-25 14:25:49 +0000
65+++ u1db/tests/test_http_client.py 2012-07-11 17:26:19 +0000
66@@ -275,6 +275,20 @@
67 self.assertTrue("content-type" in e.headers)
68 self.assertEqual(5, self.errors)
69
70+ def test_document_too_big(self):
71+ cli = self.getClient()
72+ self.assertRaises(errors.DocumentTooBig,
73+ cli._request_json, 'POST', ['error'], {},
74+ {'status': "403 Forbidden",
75+ 'response': {"error": "document too big"}})
76+
77+ def test_user_quota_exceeded(self):
78+ cli = self.getClient()
79+ self.assertRaises(errors.UserQuotaExceeded,
80+ cli._request_json, 'POST', ['error'], {},
81+ {'status': "403 Forbidden",
82+ 'response': {"error": "user quota exceeded"}})
83+
84 def test_generic_u1db_error(self):
85 cli = self.getClient()
86 self.assertRaises(errors.U1DBError,

Subscribers

People subscribed via source and target branches