class TestCsvActionFactory(TestCase): def setUp(self): self.model = MagicMock() self.sut = CsvActionFactory(self.model) @patch('nsync.management.commands.utils.CsvSyncActionsDecoder') def test_from_dict_maps_to_build_correctly(self, ActionDecoder): action_flags_mock = MagicMock() match_on_mock = MagicMock() external_key_mock = MagicMock() with patch.object(self.sut, 'build') as build_method: result = self.sut.from_dict({ 'action_flags': action_flags_mock, 'match_on': match_on_mock, 'external_key': external_key_mock, 'other_key': 'value' }) ActionDecoder.decode.assert_called_with(action_flags_mock) match_on_mock.split.assert_called_with( CsvActionFactory.match_on_delimiter) build_method.assert_called_with(ActionDecoder.decode.return_value, match_on_mock.split.return_value, external_key_mock, {'other_key': 'value'}) self.assertEqual(build_method.return_value, result) def test_returns_an_empty_list_if_no_actions_in_input(self): self.assertEqual([], self.sut.from_dict(None)) def test_it_raises_an_error_if_the_action_flag_key_is_not_in_values(self): with self.assertRaises(KeyError): self.sut.from_dict({'not_matched': 'value'}) def test_it_raises_an_error_if_the_match_field_key_is_not_in_values(self): with self.assertRaises(KeyError): self.sut.from_dict({'action_flags': ''})
class TestCsvActionFactory(TestCase): def setUp(self): self.model = MagicMock() self.sut = CsvActionFactory(self.model) @patch('nsync.management.commands.utils.CsvSyncActionsDecoder') def test_from_dict_maps_to_build_correctly(self, ActionDecoder): action_flags_mock = MagicMock() match_on_mock = MagicMock() external_key_mock = MagicMock() with patch.object(self.sut, 'build') as build_method: result = self.sut.from_dict({ 'action_flags': action_flags_mock, 'match_on': match_on_mock, 'external_key': external_key_mock, 'other_key': 'value'}) ActionDecoder.decode.assert_called_with(action_flags_mock) match_on_mock.split.assert_called_with( CsvActionFactory.match_on_delimiter) build_method.assert_called_with( ActionDecoder.decode.return_value, match_on_mock.split.return_value, external_key_mock, {'other_key': 'value'}) self.assertEqual(build_method.return_value, result) def test_returns_an_empty_list_if_no_actions_in_input(self): self.assertEqual([], self.sut.from_dict(None)) def test_it_raises_an_error_if_the_action_flag_key_is_not_in_values(self): with self.assertRaises(KeyError): self.sut.from_dict({'not_matched': 'value'}) def test_it_raises_an_error_if_the_match_field_key_is_not_in_values(self): with self.assertRaises(KeyError): self.sut.from_dict({'action_flags': ''})
def setUp(self): self.model = MagicMock() self.sut = CsvActionFactory(self.model)
def setUp(self): self.model = MagicMock() self.sut = CsvActionFactory(self.model)