Ejemplo n.º 1
0
    def createFromText(text, playUrlTitle):
        """ Creates and saves a review from the passed text and playUrlTitle, setting other fields appropriately."""

        # Create the new review
        newReview = Review()
        newReview.text = text
        # This shiould be handled at the DB level.
        # newReview.timestamp = datetime.now()
        newReview.rating = text_processing.rateReview(text)
        newReview.play = Play.objects.get(url_title=playUrlTitle)
        # newReview.playRatingSum = None
        # newReview.playReviewCount = None

        # Save it
        with transaction.atomic():

            # Lock the play
            newReview.play = Play.objects.select_for_update().get(url_title=playUrlTitle)

            # Ensure the new review is accounted for.
            newReview.save()

            playRatingQuery = newReview.play.review_set.aggregate(play_rating=models.Avg("rating"))
            newReview.play.rating = playRatingQuery["play_rating"]
            newReview.play.save()

            # lastReview = newReview.play.review_set.latest(field_name="timestamp")
            #
            # newReview.playRatingSum = lastReview.playRatingSum + newReview.rating
            # newReview.playReviewCount = lastReview.playReviewCount + 1


        # Give back the (now saved) review.
        return newReview
Ejemplo n.º 2
0
    def testSimplePositive(self):
        """Tests simple, positive text, making sure we get a positive result."""

        result = text_processing.rateReview(SentimentTestHelper.POSITIVE_REVIEW_TEXT)

        # Overtly positive text should return a result above 0.
        self.assertGreater(result, 0)
Ejemplo n.º 3
0
    def testSimpleNegative(self):
        """Tests simple, negative text, making sure we get a negative result."""

        result = text_processing.rateReview(SentimentTestHelper.NEGATIVE_REVIEW_TEXT)

        # Overtly negative text should return a result below 0.
        self.assertLess(result, 0)
Ejemplo n.º 4
0
    def testSimpleText(self):
        """Tests some simple text, checking that we get some result."""

        result = text_processing.rateReview("Simple test text.")
        self.assertIsNotNone(result)