[PATCH 2 of 2] db: add explicit constraint for the implicit invariant that all status changes have a comment

Mads Kiilerich mads at kiilerich.com
Thu Jun 18 13:58:26 EDT 2015


# HG changeset patch
# User Mads Kiilerich <madski at unity3d.com>
# Date 1434650132 -7200
#      Thu Jun 18 19:55:32 2015 +0200
# Node ID 4c64c061bd3b4f4162fbfe57eedcade1be5290d3
# Parent  7b75c8877364c24c72281759d9959255def3b159
db: add explicit constraint for the implicit invariant that all status changes have a comment

diff --git a/kallithea/model/db.py b/kallithea/model/db.py
--- a/kallithea/model/db.py
+++ b/kallithea/model/db.py
@@ -2233,7 +2233,7 @@ class ChangesetStatus(Base, BaseModel):
     user_id = Column(Integer(), ForeignKey('users.user_id'), nullable=False, unique=None)
     revision = Column(String(40), nullable=False)
     status = Column(String(128), nullable=False, default=DEFAULT)
-    changeset_comment_id = Column(Integer(), ForeignKey('changeset_comments.comment_id'))
+    changeset_comment_id = Column(Integer(), ForeignKey('changeset_comments.comment_id'), nullable=False)
     modified_at = Column(DateTime(), nullable=False, default=datetime.datetime.now)
     version = Column(Integer(), nullable=False, default=0)
     pull_request_id = Column(Integer(), ForeignKey('pull_requests.pull_request_id'), nullable=True)
diff --git a/kallithea/tests/other/test_validators.py b/kallithea/tests/other/test_validators.py
--- a/kallithea/tests/other/test_validators.py
+++ b/kallithea/tests/other/test_validators.py
@@ -8,7 +8,7 @@ from kallithea.model.user_group import U
 
 from kallithea.model.meta import Session
 from kallithea.model.repo_group import RepoGroupModel
-from kallithea.model.db import ChangesetStatus, Repository
+from kallithea.model.db import ChangesetStatus, ChangesetComment, Repository
 from kallithea.model.changeset_status import ChangesetStatusModel
 from kallithea.tests.fixture import Fixture
 
@@ -233,16 +233,23 @@ class TestRepoGroups(BaseTestCase):
         self.assertEqual('DN_attr', validator.to_python('DN_attr'))
 
     def test_NotReviewedRevisions(self):
-        repo_id = Repository.get_by_repo_name(HG_REPO).repo_id
-        validator = v.NotReviewedRevisions(repo_id)
+        user = ChangesetStatusModel()._get_user(TEST_USER_ADMIN_LOGIN)
+        repo = Repository.get_by_repo_name(HG_REPO)
+        validator = v.NotReviewedRevisions(repo.repo_id)
         rev = '0' * 40
         # add status for a rev, that should throw an error because it is already
         # reviewed
+        new_comment = ChangesetComment()
+        new_comment.repo = repo
+        new_comment.author = user
+        new_comment.text = u''
+        Session().add(new_comment)
+        Session().flush()
         new_status = ChangesetStatus()
-        new_status.author = ChangesetStatusModel()._get_user(TEST_USER_ADMIN_LOGIN)
-        new_status.repo = ChangesetStatusModel()._get_repo(HG_REPO)
+        new_status.author = user
+        new_status.repo = repo
         new_status.status = ChangesetStatus.STATUS_APPROVED
-        new_status.comment = None
+        new_status.comment = new_comment
         new_status.revision = rev
         Session().add(new_status)
         Session().commit()


More information about the kallithea-general mailing list