Ejemplo n.º 1
0
    def test_get_ideas_by_category(self):
        '''
        Testing the method get_ideas_by_category
        '''

        # Existing category
        category_a_ideas = IdeaService.get_ideas_by_category(self.category.id)
        self.assertEqual(len(category_a_ideas), 2)

        # Make sure it contains only the desired fields
        idea = category_a_ideas[0]
        self.assertIn('id', idea)
        self.assertIn('title', idea)
        self.assertIn('user__first_name', idea)
        self.assertIn('created_date', idea)
        self.assertIn('excerpt', idea)
        self.assertIn('votes', idea)

        # Category without idea
        category_a_ideas = IdeaService.get_ideas_by_category(2)
        self.assertEqual(len(category_a_ideas), 0)

        # Category does not exist
        category_a_ideas = IdeaService.get_ideas_by_category(999)
        self.assertEqual(len(category_a_ideas), 0)

        # Using none
        category_a_ideas = IdeaService.get_ideas_by_category(None)
        self.assertEqual(len(category_a_ideas), 0)
Ejemplo n.º 2
0
Archivo: tests.py Proyecto: hnb2/ideas
    def test_get_ideas_by_category(self):
        '''
        Testing the method get_ideas_by_category
        '''

        # Existing category
        category_a_ideas = IdeaService.get_ideas_by_category(
            self.category.id
        )
        self.assertEqual(len(category_a_ideas), 2)

        # Make sure it contains only the desired fields
        idea = category_a_ideas[0]
        self.assertIn('id', idea)
        self.assertIn('title', idea)
        self.assertIn('user__first_name', idea)
        self.assertIn('created_date', idea)
        self.assertIn('excerpt', idea)
        self.assertIn('votes', idea)

        # Category without idea
        category_a_ideas = IdeaService.get_ideas_by_category(2)
        self.assertEqual(len(category_a_ideas), 0)

        # Category does not exist
        category_a_ideas = IdeaService.get_ideas_by_category(999)
        self.assertEqual(len(category_a_ideas), 0)

        # Using none
        category_a_ideas = IdeaService.get_ideas_by_category(None)
        self.assertEqual(len(category_a_ideas), 0)
Ejemplo n.º 3
0
Archivo: ideas.py Proyecto: hnb2/ideas
 def get_queryset(self):
     '''
     Return a dictionnary of fields, it will not be objects.
     '''
     return IdeaService.get_ideas_by_category(
         self.kwargs['category_id']
     )
Ejemplo n.º 4
0
Archivo: ideas.py Proyecto: hnb2/ideas
 def get_queryset(self):
     '''
     Return a dictionnary of fields, it will not be objects.
     '''
     return IdeaService.get_ideas_by_category(self.kwargs['category_id'])