def test_get_latest_ideas(self): ''' Testing the method get_latest_ideas ''' # Retrieving all the ideas ideas = IdeaService.get_latest_ideas(10) self.assertEqual(len(ideas), 2) # Make sure it contains only the desired fields idea = 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) # Make sure it is sorted by created date DESC self.assertGreater( ideas[0]['created_date'], ideas[1]['created_date'] ) # Using None ideas = IdeaService.get_latest_ideas(None) self.assertEqual(len(ideas), 2)
def test_get_latest_ideas(self): ''' Testing the method get_latest_ideas ''' # Retrieving all the ideas ideas = IdeaService.get_latest_ideas(10) self.assertEqual(len(ideas), 2) # Make sure it contains only the desired fields idea = 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) # Make sure it is sorted by created date DESC self.assertGreater(ideas[0]['created_date'], ideas[1]['created_date']) # Using None ideas = IdeaService.get_latest_ideas(None) self.assertEqual(len(ideas), 2)
def get_queryset(self): ''' Return a dictionnary of fields, it will not be objects. ''' return IdeaService.get_latest_ideas(8)