def test_add_comment_view_with_changed_hash(self):

        first_hash = "THEoriginalHASH"
        second_hash = "ANEWCRAZYHASH"

        comment_text = "This comment will follow its node despite hash changing."

        # Create a comment on a node whose latest hash is the first one.
        node = DocumentNodeFactory(hash=first_hash)
        comnent = DocumentCommentFactory(node=node, text=comment_text)

        # Now change the node's hash.
        node.update_hash(second_hash, "ANEWCRAZYCOMMIT")

        node_from_orm = DocumentNode.objects.from_hash(
            version_slug=node.version.slug, page=node.page, node_hash=node.latest_hash(), project_slug=node.project.slug
        )

        # It's the same node.
        self.assertEqual(node, node_from_orm)

        # Get all the comments with the second hash.
        query_params = {
            "node": second_hash,
            "document_page": node.page,
            "project": node.project.slug,
            "version": node.version.slug,
        }

        response = self.client.get("/api/v2/comments/", query_params)

        self.assertEqual(response.data["results"][0]["text"], comment_text)
    def test_update_with_same_hash_does_not_create_new_snapshot(self):
        node = DocumentNodeFactory()

        hash = "SOMEHASH"
        commit = "SOMEGITCOMMIT"

        # We initially have just one snapshot.
        self.assertEqual(node.snapshots.count(), 1)

        # ...but when we update the hash, we have two.
        node.update_hash(hash, commit)
        self.assertEqual(node.snapshots.count(), 2)

        # If we update with the same exact hash and commit, it doesn't create a new snapshot.
        node.update_hash(hash, commit)
        self.assertEqual(node.snapshots.count(), 2)
    def test_node_can_be_sought_From_new_hash(self):

        first_hash = "THEoriginalHASH"
        second_hash = "ANEWCRAZYHASH"

        node = DocumentNodeFactory(hash=first_hash)
        comnent = DocumentCommentFactory()
        node.update_hash(second_hash, "ANEWCRAZYCOMMIT")

        node_from_orm = DocumentNode.objects.from_hash(
            node.version.slug, node.page, node.latest_hash(), project_slug=node.project.slug
        )
        self.assertEqual(node, node_from_orm)

        node.update_hash(first_hash, "AthirdCommit")

        node_from_orm2 = DocumentNode.objects.from_hash(node.version.slug, node.page, first_hash, node.project.slug)
        self.assertEqual(node, node_from_orm2)