コード例 #1
0
    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)
コード例 #2
0
    def test_add_comment_view_with_existing_hash(self):

        node = DocumentNodeFactory()
        user = UserFactory(username="******", password="******")

        comment_text = "Here's a comment added through the comment view."

        post_data = {
            "node": node.latest_hash(),
            "commit": node.latest_hash(),
            "project": node.project.slug,
            "version": node.version.slug,
            "document_page": node.page,
            "text": comment_text,
        }

        self.client.login(username="******", password="******")
        response = self.client.post("/api/v2/comments/", post_data)

        comment_from_orm = node.comments.filter(text=comment_text)
        self.assertTrue(comment_from_orm.exists())

        self.assertEqual(
            comment_from_orm[0].node,
            node,
            "The comment exists, but lives in a different node!  Not supposed to happen.",
        )
コード例 #3
0
    def test_update_node_view(self):

        node = DocumentNodeFactory()

        # Our node has one snapshot.
        self.assertEqual(node.snapshots.count(), 1)

        new_hash = "CRAZYnewHASHtoUPDATEnode"
        commit = "COOLNEWGITCOMMITHASH"

        post_data = {
            "old_hash": node.latest_hash(),
            "new_hash": new_hash,
            "commit": commit,
            "project": node.project.slug,
            "version": node.version.slug,
            "page": node.page,
        }

        request = self.request_factory.post("/_update_node/", post_data)
        response = update_node(request)
        response.render()

        self.assertEqual(response.data["current_hash"], new_hash)

        # We now have two snapshots.
        self.assertEqual(node.snapshots.count(), 2)
        # And the latest hash is the one we just set.
        self.assertEqual(node.latest_hash(), new_hash)
コード例 #4
0
    def test_get_metadata_view(self):

        node = DocumentNodeFactory()

        get_data = {"project": node.project.slug, "version": node.version.slug, "page": node.page}
        request = self.request_factory.get("/_get_metadata/", get_data)
        response = get_metadata(request)
        response.render()

        number_of_comments = response.data[node.latest_hash()]

        # There haven't been any comments yet.
        self.assertEqual(number_of_comments, 0)

        # Now we'll make one.
        comment = DocumentCommentFactory(node=node, text="Our first comment!")

        second_request = self.request_factory.get("/_get_metadata/", get_data)
        second_response = get_metadata(request)
        second_response.render()

        number_of_comments = second_response.data[node.latest_hash()]

        # And sure enough - one comment.
        self.assertEqual(number_of_comments, 1)
コード例 #5
0
    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)
コード例 #6
0
    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)