|
@@ -26,6 +26,8 @@ from desktop.lib.django_test_util import make_logged_in_client
|
|
|
from desktop.lib.test_utils import grant_access
|
|
from desktop.lib.test_utils import grant_access
|
|
|
from desktop.models import Directory, Document, Document2
|
|
from desktop.models import Directory, Document, Document2
|
|
|
|
|
|
|
|
|
|
+from notebook.api import _historify
|
|
|
|
|
+
|
|
|
|
|
|
|
|
class TestNotebookApi(object):
|
|
class TestNotebookApi(object):
|
|
|
|
|
|
|
@@ -112,27 +114,30 @@ class TestNotebookApi(object):
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_historify(self):
|
|
def test_historify(self):
|
|
|
- # Test that only users with access permissions can create a history doc
|
|
|
|
|
- response = self.client_not_me.post(reverse('notebook:historify'), {'notebook': self.notebook_json})
|
|
|
|
|
- data = json.loads(response.content)
|
|
|
|
|
- assert_equal(-1, data['status'], data)
|
|
|
|
|
-
|
|
|
|
|
- # Test that historify creates new Doc2 and linked Doc1
|
|
|
|
|
|
|
+ # Starts with no history
|
|
|
assert_equal(0, Document2.objects.filter(name__contains=self.notebook['name'], is_history=True).count())
|
|
assert_equal(0, Document2.objects.filter(name__contains=self.notebook['name'], is_history=True).count())
|
|
|
assert_equal(1, Document.objects.filter(name__contains=self.notebook['name']).count())
|
|
assert_equal(1, Document.objects.filter(name__contains=self.notebook['name']).count())
|
|
|
|
|
|
|
|
- response = self.client.post(reverse('notebook:historify'), {'notebook': self.notebook_json})
|
|
|
|
|
- data = json.loads(response.content)
|
|
|
|
|
- assert_equal(0, data['status'], data)
|
|
|
|
|
|
|
+ history_doc = _historify(self.notebook, self.user)
|
|
|
|
|
+
|
|
|
|
|
+ assert_true(history_doc.id > 0)
|
|
|
|
|
+
|
|
|
|
|
+ # Test that historify creates new Doc2 and linked Doc1
|
|
|
assert_equal(1, Document2.objects.filter(name__contains=self.notebook['name'], is_history=True).count())
|
|
assert_equal(1, Document2.objects.filter(name__contains=self.notebook['name'], is_history=True).count())
|
|
|
assert_equal(2, Document.objects.filter(name__contains=self.notebook['name']).count())
|
|
assert_equal(2, Document.objects.filter(name__contains=self.notebook['name']).count())
|
|
|
|
|
|
|
|
|
|
+ # Historify again
|
|
|
|
|
+ history_doc = _historify(self.notebook, self.user)
|
|
|
|
|
+
|
|
|
|
|
+ assert_equal(2, Document2.objects.filter(name__contains=self.notebook['name'], is_history=True).count())
|
|
|
|
|
+ assert_equal(3, Document.objects.filter(name__contains=self.notebook['name']).count())
|
|
|
|
|
+
|
|
|
|
|
|
|
|
def test_get_history(self):
|
|
def test_get_history(self):
|
|
|
assert_equal(0, Document2.objects.filter(name__contains=self.notebook['name'], is_history=True).count())
|
|
assert_equal(0, Document2.objects.filter(name__contains=self.notebook['name'], is_history=True).count())
|
|
|
- self.client.post(reverse('notebook:historify'), {'notebook': self.notebook_json})
|
|
|
|
|
- self.client.post(reverse('notebook:historify'), {'notebook': self.notebook_json})
|
|
|
|
|
- self.client.post(reverse('notebook:historify'), {'notebook': self.notebook_json})
|
|
|
|
|
|
|
+ _historify(self.notebook, self.user)
|
|
|
|
|
+ _historify(self.notebook, self.user)
|
|
|
|
|
+ _historify(self.notebook, self.user)
|
|
|
assert_equal(3, Document2.objects.filter(name__contains=self.notebook['name'], is_history=True).count())
|
|
assert_equal(3, Document2.objects.filter(name__contains=self.notebook['name'], is_history=True).count())
|
|
|
|
|
|
|
|
# History should not return history objects that don't have the given doc type
|
|
# History should not return history objects that don't have the given doc type
|
|
@@ -150,9 +155,9 @@ class TestNotebookApi(object):
|
|
|
|
|
|
|
|
def test_clear_history(self):
|
|
def test_clear_history(self):
|
|
|
assert_equal(0, Document2.objects.filter(name__contains=self.notebook['name'], is_history=True).count())
|
|
assert_equal(0, Document2.objects.filter(name__contains=self.notebook['name'], is_history=True).count())
|
|
|
- self.client.post(reverse('notebook:historify'), {'notebook': self.notebook_json})
|
|
|
|
|
- self.client.post(reverse('notebook:historify'), {'notebook': self.notebook_json})
|
|
|
|
|
- self.client.post(reverse('notebook:historify'), {'notebook': self.notebook_json})
|
|
|
|
|
|
|
+ _historify(self.notebook, self.user)
|
|
|
|
|
+ _historify(self.notebook, self.user)
|
|
|
|
|
+ _historify(self.notebook, self.user)
|
|
|
assert_equal(3, Document2.objects.filter(name__contains=self.notebook['name'], is_history=True).count())
|
|
assert_equal(3, Document2.objects.filter(name__contains=self.notebook['name'], is_history=True).count())
|
|
|
|
|
|
|
|
# Clear history should not clear history objects that don't have the given doc type
|
|
# Clear history should not clear history objects that don't have the given doc type
|