Exemple #1
0
    def test_list_view_returns_sorted_correctly(self):
        # should return greatest to smallest, that way easier to truncate
        WriteUpPromptFactory.create_batch(
            100, share_state=PromptShareStates.PUBLISHED)
        url = reverse(self.VIEW_NAME)
        response = self.registered_user_client.get(url)
        data = response.data

        score = [item["score"] for item in data]

        sorted_score = sorted(score, reverse=True)
        self.assertEqual(score, sorted_score)
Exemple #2
0
    def test_list_view_query_count(self):
        WriteUpPromptFactory.create_batch(
            100, share_state=PromptShareStates.PUBLISHED)
        WriteUpPromptFactory.create_batch(
            5, share_state=PromptShareStates.PUBLISHED_LINK_ACCESS_ONLY)
        WriteUpPromptFactory.create_batch(
            5, share_state=PromptShareStates.UNSHARED)
        url = reverse(self.VIEW_NAME)

        # it's currently five queries for the view / auth login / some permission checking
        with self.assertNumQueriesLessThan(6):
            response = self.registered_user_client.get(url)
            self.assertEqual(response.status_code, 200)
Exemple #3
0
    def test_list_view_returns_published_stuff(self):
        WriteUpPromptFactory.create_batch(
            5, share_state=PromptShareStates.PUBLISHED)
        WriteUpPromptFactory.create_batch(
            5, share_state=PromptShareStates.PUBLISHED_LINK_ACCESS_ONLY)
        WriteUpPromptFactory.create_batch(
            5, share_state=PromptShareStates.UNSHARED)

        url = reverse(self.VIEW_NAME)
        response = self.registered_user_client.get(url)
        data = response.data

        # should only see 5, the ones that are PUBLISHED
        self.assertEqual(5, len(response.data))

        # we synthetically generate score on prompts
        result = data[0]
        self.assertIsNotNone(result["score"])