From 5a1de03a12a386e83a5c579fefd8e6ffbedc2794 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Rekucki?= Date: Mon, 28 Sep 2009 16:18:02 +0200 Subject: [PATCH] Fixed text update. --- apps/api/handlers/library_handlers.py | 12 ++++---- apps/api/tests/__init__.py | 41 ++++++++++++++------------- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/apps/api/handlers/library_handlers.py b/apps/api/handlers/library_handlers.py index ae61389a..b30f2e78 100644 --- a/apps/api/handlers/library_handlers.py +++ b/apps/api/handlers/library_handlers.py @@ -276,20 +276,22 @@ class DocumentTextHandler(BaseHandler): f = lib._fileopen(resolve('xml'), 'w+') f.write(data) f.close() - + + ndoc = None ndoc = current.invoke_and_commit(\ xml_update_action, lambda d: (msg, current.owner) ) try: # return the new revision number - return { + return response.SuccessAllOk().django_response({ "document": ndoc.id, "subview": "xml", "previous_revision": current.revision, - "updated_revision": ndoc.revision - } + "updated_revision": ndoc.revision, + "url": reverse("doctext_view", args=[ndoc.id, ndoc.revision]) + }) except Exception, e: - lib._rollback() + if ndoc: lib._rollback() raise e except RevisionNotFound, e: return response.EntityNotFound().django_response(e) diff --git a/apps/api/tests/__init__.py b/apps/api/tests/__init__.py index f28b3b2f..751a085c 100644 --- a/apps/api/tests/__init__.py +++ b/apps/api/tests/__init__.py @@ -32,10 +32,11 @@ def temprepo(name): finally: if not clean and self.response: print "RESULT", func.__name__, ">>>" - print self.response + print self.response.content print "<<<" - - # shutil.rmtree(temp, True) + else: + shutil.rmtree(temp, True) + settings.REPOSITORY_PATH = '' return decorated @@ -141,24 +142,26 @@ class SimpleTest(TestCase): self.response = self.client.get(resp['text_url']) self.assertEqual(self.response.status_code, 200) self.assertEqual(self.response.content, "Ala ma kota\n") -# -# -# @temprepo('simple') -# def test_document_text_update(self): -# self.assertTrue(self.client.login(username='admin', password='admin')) -# TEXT = u"Ala ma kota i psa" -# -# self.response = self.client.put( \ -# reverse("doctext_view", args=['testfile']), {'contents': TEXT }) -# self.assertEqual(self.response.status_code, 200) -# -# self.response = self.client.get( \ -# reverse("doctext_view", args=['testfile']) ) -# self.assertEqual(self.response.status_code, 200) -# self.assertEqual(self.response.content, TEXT) + + + @temprepo('simple') + def test_document_text_update(self): + self.assertTrue(self.client.login(username='admin', password='admin')) + TEXT = u"Ala ma kota i psa" + + self.response = self.client.get( + reverse("document_view", args=['sample']) ) + + resp = self.assert_json_response() + + self.response = self.client.put(resp['text_url'], {'contents': TEXT }) + result = self.assert_json_response(must_have={u'document': u'sample'} ) + + #self.response = self.client.get(result['url']) + #self.assertEqual(self.response.content, TEXT) def assert_json_response(self, must_have={}, exclude=[], code=200): - self.assertEqual(self.response.status_code, code) + self.assertEqual(self.response.status_code, code) result = json.loads(self.response.content) for (k,v) in must_have.items(): -- 2.20.1