Exemple #1
0
 def test_get_followed_artists_exists(self):
     """
     If _followed_artists is not None, followed_artists() should
     return it.
     """
     u = UserData(None)
     test_data = ['hello', 'goodbye']
     u._followed_artists = test_data
     self.assertEqual(u.followed_artists(), test_data)
    def test_question_followed_artists_no_valid_incorrect_choices(self):
        """
        question_followed_artists() should return None if there are not
        enough artists from "top_artists" to fill incorrect choices.
        """
        u = UserData(self.session)

        artists = create_artists(3)
        json_add_field(artists, 'name', ['Cassius', 'Ben', 'James'], arr=True)

        u._followed_artists = artists
        u._top_artists['long_term'] = artists

        quiz = Quiz.objects.create(user_id='cassius')
        q = question_followed_artists(quiz, u)

        self.assertIsNone(q)
    def test_question_followed_artists(self):
        """
        question_followed_artists() should return a question about the
        user's followed artists.
        """
        u = UserData(self.session)

        artists = create_artists(11)
        json_add_field(artists,
                       'name', [
                           'Cash', 'Ben', 'Cassius', 'Benjamin', 'James',
                           'Jim', 'John', 'Lucy', 'Lewis', 'Lucifer', 'Lewd'
                       ],
                       arr=True)
        json_add_to_field(artists, 'images', create_image())

        u._followed_artists = artists[:7]
        u._top_artists['long_term'] = artists[7:]

        quiz = Quiz.objects.create(user_id='cassius')

        q = question_followed_artists(quiz, u)

        self.assertEqual(q.choices.count(), 4)
        self.assertGreater(q.answers().count(), 0)
        self.assertLessEqual(q.answers().count(), 4)
        self.assertEqual(q.incorrect_answers().count(),
                         4 - q.answers().count())

        for c in q.answers():
            title = c.primary_text
            found = False
            for t in u._followed_artists:
                if t['name'] == title:
                    found = True
            self.assertTrue(found)
            self.assertEqual(c.image_url, '200url')

        for c in q.incorrect_answers():
            title = c.primary_text
            found = False
            for a in u._top_artists['long_term']:
                if a['name'] == title:
                    found = True
            self.assertTrue(found)
            self.assertEqual(c.image_url, '200url')
    def test_question_followed_artists_only_one_correct_answer(self):
        """
        question_followed_artists() should create a question, even if
        there is only one available artist that can be correct, as long
        as there are enough artists in "top_artists" to fill the
        incorrect choices.
        """
        u = UserData(self.session)

        artists = create_artists(4)
        json_add_field(artists,
                       'name', ['Cassius', 'Ben', 'John', 'Jim'],
                       arr=True)
        json_add_to_field(artists, 'images', create_image())

        u._followed_artists = [artists[0]]
        u._top_artists['long_term'] = artists[1:]

        quiz = Quiz.objects.create(user_id='cassius')
        q = question_followed_artists(quiz, u)

        self.assertEqual(q.choices.count(), 4)
        self.assertEqual(q.answers().count(), 1)
        self.assertEqual(q.incorrect_answers().count(), 3)

        c = q.answers()[0]
        self.assertEqual(u._followed_artists[0]['name'], c.primary_text)

        for c in q.choices.all():
            self.assertIsNotNone(c.image_url)

        for c in q.incorrect_answers():
            title = c.primary_text
            found = False
            for a in u._top_artists['long_term']:
                if a['name'] == title:
                    found = True
            self.assertTrue(found)