summaryrefslogtreecommitdiff
path: root/share/www/script
diff options
context:
space:
mode:
authorJan Lehnardt <jan@apache.org>2008-07-10 19:47:37 +0000
committerJan Lehnardt <jan@apache.org>2008-07-10 19:47:37 +0000
commit197a439cc4c6b61fac3db0e8d60ca16411673e0d (patch)
tree8b904ea8fad181dd5f4f1bd9c8fe9e9254e38001 /share/www/script
parentc48e8ef02d8ba7a93dbb3e72c7be3441cb6bacbf (diff)
Make RESTful attachment API concurrency aware and the code a little more concise (thanks Damien!)
git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@675699 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'share/www/script')
-rw-r--r--share/www/script/couch_tests.js65
1 files changed, 38 insertions, 27 deletions
diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js
index a0e6b2ff..6a1e72c8 100644
--- a/share/www/script/couch_tests.js
+++ b/share/www/script/couch_tests.js
@@ -561,54 +561,65 @@ var tests = {
// test RESTful doc API
- // test without rev, should fail
- var xhr = CouchDB.request("DELETE", "/test_suite_db/bin_doc/foo.txt");
- T(xhr.status == 412);
-
- db.deleteDocAttachment({_id:"bin_doc"}, "foo.txt");
- var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt");
- T(xhr.status == 404);
-
- var xhr = CouchDB.request("PUT", "/test_suite_db/bin_doc/foo.txt", {
- body: "This is not base64 encoded text",
- headers:{"Content-Type":"text/plain;charset=utf-8"}
+ var xhr = CouchDB.request("PUT", "/test_suite_db/bin_doc2/foo2.txt", {
+ body:"This is no base64 encoded text",
+ headers:{"Content-Type": "text/plain;charset=utf-8"}
});
T(xhr.status == 201);
-
- var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt");
- T(xhr.responseText == "This is not base64 encoded text");
+ var rev = JSON.parse(xhr.responseText).rev;
+
+ var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc2/foo2.txt");
+ T(xhr.responseText == "This is no base64 encoded text");
T(xhr.getResponseHeader("Content-Type") == "text/plain;charset=utf-8");
+
+ // test without rev, should fail
+ var xhr = CouchDB.request("DELETE", "/test_suite_db/bin_doc2/foo2.txt");
+ T(xhr.status == 412);
+ // test with rev, should not fail
+ var xhr = CouchDB.request("DELETE", "/test_suite_db/bin_doc2/foo2.txt?rev=" + rev);
+ T(xhr.status == 200);
+
+
// test binary data
- var xhr = CouchDB.request("GET", "/favicon.ico");
- var bin_data = xhr.responseText;
- // bin_data = 123;
- var xhr = CouchDB.request("PUT", "/test_suite_db/bin_doc/favicon.ico", {
- headers:{"Content-Type":"image/vnd.microsoft.icon"},
+ var bin_data = "JHAPDO*AU£PN ){(3u[d 93DQ9¡€])} ææøo'∂ƒæ≤çæππ•¥∫¶®#†π¶®¥π€ª®˙π8np";
+ var xhr = CouchDB.request("PUT", "/test_suite_db/bin_doc3/attachment.txt", {
+ headers:{"Content-Type":"text/plain;charset=utf-8"},
body:bin_data
});
T(xhr.status == 201);
var rev = JSON.parse(xhr.responseText).rev;
-
- var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/favicon.ico");
+
+ var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc3/attachment.txt");
T(xhr.responseText == bin_data);
- T(xhr.getResponseHeader("Content-Type") == "image/vnd.microsoft.icon");
+ T(xhr.getResponseHeader("Content-Type") == "text/plain;charset=utf-8");
- var xhr = CouchDB.request("PUT", "/test_suite_db/bin_doc/favicon.ico", {
- headers:{"Content-Type":"image/vnd.microsoft.icon"},
+ var xhr = CouchDB.request("PUT", "/test_suite_db/bin_doc3/attachment.txt", {
+ headers:{"Content-Type":"text/plain;charset=utf-8"},
body:bin_data
});
T(xhr.status == 412);
- var xhr = CouchDB.request("PUT", "/test_suite_db/bin_doc/favicon.ico?rev="+rev, {
- headers:{"Content-Type":"image/vnd.microsoft.icon"},
+ var xhr = CouchDB.request("PUT", "/test_suite_db/bin_doc3/attachment.txt?rev=" + rev, {
+ headers:{"Content-Type":"text/plain;charset=utf-8"},
body:bin_data
});
T(xhr.status == 201);
var rev = JSON.parse(xhr.responseText).rev;
- var xhr = CouchDB.request("DELETE", "/test_suite_db/bin_doc/foo.txt?rev="+rev);
+ var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc3/attachment.txt");
+ T(xhr.responseText == bin_data);
+ T(xhr.getResponseHeader("Content-Type") == "text/plain;charset=utf-8");
+
+ var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc3/attachment.txt?rev=" + rev);
+ T(xhr.responseText == bin_data);
+ T(xhr.getResponseHeader("Content-Type") == "text/plain;charset=utf-8");
+
+ var xhr = CouchDB.request("DELETE", "/test_suite_db/bin_doc3/attachment.txt?rev=" + rev);
T(xhr.status == 200);
+
+ var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc3/attachment.txt?rev=" + rev);
+ T(xhr.status == 404);
},
content_negotiation: function(debug) {