예제 #1
0
    def testHappyCaseConversion(self):

        # Create (and save) the PlayList we're working with.
        theList = PlayList()
        theList.title = "Test Play List"
        theList.url_title = "test-play-list"
        theList.save()

        # Create (and save) a pair of plays to populate the Play
        play1 = PlayTestHelper.makePlay(PlayTestHelper.Play1Vals);
        play2 = PlayTestHelper.makePlay(PlayTestHelper.Play2Vals);
        play1.save()
        play2.save()

        # Create* a pair of entries to bind the plays to the list
        playListEntry1 = PlayListEntry()
        playListEntry1.play = play1
        playListEntry1.play_list = theList
        playListEntry1.play_list_order = 1

        playListEntry2 = PlayListEntry()
        playListEntry2.play = play2
        playListEntry2.play_list = theList
        playListEntry2.play_list_order = 2

        # *(and save)
        playListEntry1.save()
        playListEntry2.save()

        # Update the list, so that it picks up changes
        theList.refresh_from_db()

        # Convert it to API Fields
        apiList = theList.getApiFields()

        # Check things.
        self.assertEquals(len(apiList), 2)
예제 #2
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)
예제 #3
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()
예제 #4
0
 def setUp(self):
     """ Persist a play we can use for testing. """
     PlayTestHelper.makePlay(PlayTestHelper.PlayPrepersistedVals).save()