def test_get_status(self): """ Get the latest status for each user. """ api = Api() self.assertEqual(self.statuses['lewpen-evening'], api.get_status('lewpen')) self.assertEqual(self.statuses['lisa-happy'], api.get_status('lisa')) self.assertEqual(self.statuses['smiley-mic'], api.get_status('smileyface'))
def test_add_status_with_unknown_user(self): """ Add a status with the username specified as a string. The call will raise NoSuchUserError as the user does not exist. """ self.assertEqual([], list(Status.objects)) api = Api() with self.assertRaises(NoSuchUserError): api.add_status(status='Confused. Do I not exist?', user='******')
def test_list_statuses(self): api = Api() statuses = api.list_statuses() self.assertEqual( [ self.statuses['lisa-happy'], self.statuses['smiley-mic'], self.statuses['lewpen-evening'] ], statuses, )
def test_add_status_with_emotion(self): """Add a status with an emotion.""" self.assertEqual([], list(Status.objects)) api = Api() api.add_status(status='I was wanting you to love me.', user=self.user, emotion=self.sad_emotion) # verify that the status was inserted successfully. status = Status.objects.first() self.assertIsNotNone(status) self.assertEqual(status.status, 'I was wanting you to love me.') self.assertEqual(status.user, self.user) self.assertEqual(status.emotion, self.sad_emotion)
def test_add_status_sends_post_request(self): """ Verify that add_status() sends a post request to the registered listener. """ self.assertEqual([], list(Status.objects)) notifier = MockNotifier() api = Api(notifier=notifier) api.add_status(status='Feeling kinda groovy, working on a movie.', user=self.user) self.assertEqual(1, len(notifier.notifications)) self.assertEqual([{'username': self.user.username}], notifier.notifications)
def test_add_status_with_emotion_as_string(self): """ Add a status with the emotion specified as a string. """ self.assertEqual([], list(Status.objects)) api = Api() api.add_status(status='Very sad indeed.', user=self.user, emotion='sad') # verify that the status was inserted successfully. status = Status.objects.first() self.assertIsNotNone(status) self.assertEqual(status.status, 'Very sad indeed.') self.assertEqual(status.user, self.user) self.assertEqual(status.emotion, self.sad_emotion)
def test_add_status_with_username_as_string(self): """ Add a status with the username specified as a string. """ self.assertEqual([], list(Status.objects)) api = Api() api.add_status(status='Sated and happy.', user='******') # verify that the status was inserted successfully. status = Status.objects.first() self.assertIsNotNone(status) self.assertEqual(status.status, 'Sated and happy.') self.assertEqual(status.user, self.user) self.assertEqual(status.emotion, None)
def test_add_status_with_nonexisting_emotion_as_string(self): """ Add a status with the emotion specified as a string. The emotion will be created as it does not exist. """ self.assertEqual([], list(Status.objects)) api = Api() api.add_status(status='Lots of energy on the keyboard.', user=self.user, emotion='happy') # verify that the status was inserted successfully. status = Status.objects.first() self.assertIsNotNone(status) self.assertEqual(status.status, 'Lots of energy on the keyboard.') self.assertEqual(status.user, self.user) self.assertEqual(status.emotion.name, 'happy')