Browse Source

ContentRevision clonning update created and updated date

Bastien Sevajol 9 years ago
parent
commit
06c50be930
2 changed files with 18 additions and 1 deletions
  1. 3 0
      tracim/tracim/model/data.py
  2. 15 1
      tracim/tracim/tests/models/test_content.py

+ 3 - 0
tracim/tracim/model/data.py View File

@@ -538,6 +538,9 @@ class ContentRevisionRO(DeclarativeBase):
538 538
             column_value = getattr(revision, column_name)
539 539
             setattr(new_rev, column_name, column_value)
540 540
 
541
+        new_rev.created = datetime.now()
542
+        new_rev.updated = datetime.now()
543
+
541 544
         return new_rev
542 545
 
543 546
     def __setattr__(self, key, value):

+ 15 - 1
tracim/tracim/tests/models/test_content.py View File

@@ -1,5 +1,6 @@
1 1
 # -*- coding: utf-8 -*-
2
-from nose.tools import raises
2
+import time
3
+from nose.tools import raises, ok_
3 4
 from sqlalchemy.sql.elements import and_
4 5
 from sqlalchemy.testing import eq_
5 6
 
@@ -63,6 +64,7 @@ class TestContent(TestStandard):
63 64
         eq_(1, DBSession.query(ContentRevisionRO).filter(ContentRevisionRO.label == 'TEST_CONTENT_1').count())
64 65
 
65 66
         with new_revision(content):
67
+            time.sleep(0.00001)
66 68
             content.description = 'TEST_CONTENT_DESCRIPTION_1_UPDATED'
67 69
         DBSession.flush()
68 70
 
@@ -70,6 +72,7 @@ class TestContent(TestStandard):
70 72
         eq_(1, DBSession.query(Content).filter(Content.id == created_content.id).count())
71 73
 
72 74
         with new_revision(content):
75
+            time.sleep(0.00001)
73 76
             content.description = 'TEST_CONTENT_DESCRIPTION_1_UPDATED_2'
74 77
             content.label = 'TEST_CONTENT_1_UPDATED_2'
75 78
         DBSession.flush()
@@ -77,6 +80,17 @@ class TestContent(TestStandard):
77 80
         eq_(1, DBSession.query(ContentRevisionRO).filter(ContentRevisionRO.label == 'TEST_CONTENT_1_UPDATED_2').count())
78 81
         eq_(1, DBSession.query(Content).filter(Content.id == created_content.id).count())
79 82
 
83
+        revision_1 = DBSession.query(ContentRevisionRO)\
84
+            .filter(ContentRevisionRO.description == 'TEST_CONTENT_DESCRIPTION_1').one()
85
+        revision_2 = DBSession.query(ContentRevisionRO)\
86
+            .filter(ContentRevisionRO.description == 'TEST_CONTENT_DESCRIPTION_1_UPDATED').one()
87
+        revision_3 = DBSession.query(ContentRevisionRO)\
88
+            .filter(ContentRevisionRO.description == 'TEST_CONTENT_DESCRIPTION_1_UPDATED_2').one()
89
+
90
+        # Updated dates must be different
91
+        ok_(revision_1.updated < revision_2.updated < revision_3.updated)
92
+        ok_(revision_1.created < revision_2.created < revision_3.created)
93
+
80 94
     def test_creates(self):
81 95
         eq_(0, DBSession.query(ContentRevisionRO).filter(ContentRevisionRO.label == 'TEST_CONTENT_1').count())
82 96
         eq_(0, DBSession.query(Workspace).filter(Workspace.label == 'TEST_WORKSPACE_1').count())