def test_shareonfacebook_command(self): """The command should be called with the correct message and attachment""" mock = self.call_mocked_command() attach = Command.get_attachment(self.pet, self.url) msg = Command.get_message(self.pet) mock.assert_called_once_with(msg, attachment=attach)
def call_mocked_command(self): mock = MagicMock() mock.fb_share_token = 'token' mock.fb_share_link = self.url cmd = Command() cmd.config = mock with patch('facebook.GraphAPI.put_wall_post') as mock: cmd.handle() return mock
def call_mocked_command(self): mock = MagicMock() mock.fb_share_token = 'token' mock.fb_share_link = self.url cmd = Command() cmd.config = mock with patch('facebook.GraphAPI.put_object') as mock: cmd.handle() return mock
def test_get_attachment(self): """The attachment should be a dict with the 'link' key being the absolute url to the pet""" attach = Command.get_attachment(self.pet, self.url) expected = self.url.format(self.pet.get_absolute_url()) self.assertEqual(expected, attach.get('link', ''))
def test_get_message(self): """The message in the post should always contains the display status, the name of the pet, and the name of the city""" msg = Command.get_message(self.pet) expected = '{0}: {1}, {2}'.format(self.pet.status.description, self.pet.name, self.pet.city) self.assertEqual(expected, msg)
def test_shareonfacebook_command(self): pet = self.create_pet('Dog', published=False) link = { 'link': 'http://www.test.com/{}'.format(pet.get_absolute_url()) } mock = MagicMock() mock.get_renewed_token.return_value = 'token' mock.get_attachment.return_value = link cmd = Command() cmd.get_attachment = mock.get_attachment cmd.get_renewed_token = mock.get_renewed_token with patch('facebook.GraphAPI.put_wall_post') as mock: cmd.handle() mock.assert_called_once_with(pet.name, attachment=link)
def test_get_message(self): """The message in the post should always contains the display status, the name of the pet, and the name of the city""" msg = Command.get_message(self.pet) expected = '{0}: {1}, {2}'.format( self.pet.status.description, self.pet.name, self.pet.city ) self.assertEqual(expected, msg)
def test_shareonfacebook_command(self): """The command should be called with the correct message and attachment""" mock = self.call_mocked_command() msg = Command.get_message(self.pet) mock.assert_called_once_with( parent_object='me', connection_name='feed', message=msg, link=self.url.format(self.pet.get_absolute_url()), )
def call_mocked_command(self, link): mock = MagicMock() mock.get_renewed_token.return_value = 'token' mock.get_attachment.return_value = link cmd = Command() cmd.get_attachment = mock.get_attachment cmd.get_renewed_token = mock.get_renewed_token with patch('facebook.GraphAPI.put_wall_post') as mock: cmd.handle() return mock