Ejemplo n.º 1
0
    def testGetApiFields(self):
        review = Review()
        review.play = Play()
        review.timestamp = datetime.today()
        review.text = "foo"

        apiDict = review.getApiFields()

        self.assertEqual(apiDict, {"text": "foo", "timestamp": datetime.today().isoformat()})
Ejemplo n.º 2
0
    def testAveragingTwoReviewRatings(self):
        """ Make sure rating a play twice, differently, correctly averages those ratings."""

        Review.createFromText(SentimentTestHelper.NEGATIVE_REVIEW_TEXT, self.play_url_title)
        Review.createFromText(SentimentTestHelper.POSITIVE_REVIEW_TEXT, self.play_url_title)

        expectedRating = (self.positive_rating + self.negative_rating) / 2

        # Allow rounding errors more than 7 decimal places out.
        self.assertAlmostEqual(self.getPlay().rating, expectedRating, places=7)
Ejemplo n.º 3
0
    def testCreateFromText(self):

        startTimeStamp = datetime.now()

        # Set up a play to reference.
        play = PlayTestHelper.makePlay(PlayTestHelper.Play1Vals)
        play.save()

        theReview = Review.createFromText("The play was foo.", play.url_title)

        self.assertEqual(theReview.text, "The play was foo.")
        self.assertIsNotNone(theReview.rating)
        self.assertEqual(theReview.play, play)

        # Check the timestamp against some bounds.
        endTimeStamp = datetime.now()
        self.assertGreaterEqual(theReview.timestamp, startTimeStamp)
        self.assertLessEqual(theReview.timestamp, endTimeStamp)
Ejemplo n.º 4
0
    def setUp(self):
        """ Create the list with which we'll test. """

        # region play list setup.
        # Save and store a reference to two new plays.
        self.positivePlay = PlayTestHelper.makePlay(PlayTestHelper.Play1Vals)
        self.positivePlay.save()

        self.neutralPlay = PlayTestHelper.makePlay(PlayTestHelper.PlayPrepersistedVals)
        self.neutralPlay.save()

        self.negativePlay = PlayTestHelper.makePlay(PlayTestHelper.Play2Vals)
        self.negativePlay.save()

        self.allPlayList = PlayList()
        self.allPlayList.title = "All ReviewToRankTestCase Plays"
        self.allPlayList.url_title = self.PLAY_LIST_URL_TITLE
        self.allPlayList.is_dynamically_ordered = True
        self.allPlayList.num_to_order_dynamically = 10  # Order them all.
        self.allPlayList.save()

        positivePlayEntry = PlayListEntry()
        positivePlayEntry.play = self.positivePlay
        positivePlayEntry.play_list = self.allPlayList
        positivePlayEntry.play_list_order = None
        positivePlayEntry.save()

        neutralPlayEntry = PlayListEntry()
        neutralPlayEntry.play = self.neutralPlay
        neutralPlayEntry.play_list = self.allPlayList
        neutralPlayEntry.play_list_order = 200
        neutralPlayEntry.save()

        negativePlayEntry = PlayListEntry()
        negativePlayEntry.play = self.negativePlay
        negativePlayEntry.play_list = self.allPlayList
        negativePlayEntry.play_list_order = 1
        negativePlayEntry.save()

        # We should now have a list of three plays.
        self.assertEqual(self.allPlayList.plays.count(), 3)
        # endregion

        # region review plays
        Review.createFromText(SentimentTestHelper.POSITIVE_REVIEW_TEXT, self.positivePlay.url_title)
        Review.createFromText(SentimentTestHelper.POSITIVE_REVIEW_TEXT, self.positivePlay.url_title)

        Review.createFromText(SentimentTestHelper.POSITIVE_REVIEW_TEXT, self.neutralPlay.url_title)
        Review.createFromText(SentimentTestHelper.NEGATIVE_REVIEW_TEXT, self.neutralPlay.url_title)

        Review.createFromText(SentimentTestHelper.NEGATIVE_REVIEW_TEXT, self.negativePlay.url_title)
        Review.createFromText(SentimentTestHelper.NEGATIVE_REVIEW_TEXT, self.negativePlay.url_title)

        # We should now have six reviews in the system.
        self.assertEqual(Review.objects.count(), 6)
        # endregion

        self.allPlayList.refresh_from_db()
        self.positivePlay.refresh_from_db()
        self.neutralPlay.refresh_from_db()
        self.negativePlay.refresh_from_db()
Ejemplo n.º 5
0
    def testSingleNegativeReviewRating(self):
        """ Make sure rating one play negatively works as expected. """

        Review.createFromText(SentimentTestHelper.POSITIVE_REVIEW_TEXT, self.play_url_title)
        self.assertEqual(self.getPlay().rating, self.positive_rating)