def test_trivial(self): header_titles = ["title"] find_field_by_name = mock.MagicMock() with mock.patch('flooding_lib.excel_import_export.ImportedHeader', return_value=mock.MagicMock( find_field_by_name=find_field_by_name)): eie.import_header(header_titles) find_field_by_name.assert_called_with(0, "title")
def test_trivial(self): header_titles = ["title"] find_field_by_name = mock.MagicMock() with mock.patch( 'flooding_lib.excel_import_export.ImportedHeader', return_value=mock.MagicMock( find_field_by_name=find_field_by_name)): eie.import_header(header_titles) find_field_by_name.assert_called_with(0, "title")
def test_find_field_throws_exception(self): header_titles = ["title"] # Safe it here because otherwise it'll be mocked... real_exception = eie.ImportedHeader.HeaderException def throwing(column, title): raise real_exception("message") find_field_by_name = mock.MagicMock(side_effect=throwing) with mock.patch('flooding_lib.excel_import_export.ImportedHeader', return_value=mock.MagicMock( find_field_by_name=find_field_by_name), HeaderException=real_exception): _, errors = eie.import_header(header_titles) self.assertEquals(errors, ["message"])
def test_find_field_throws_exception(self): header_titles = ["title"] # Safe it here because otherwise it'll be mocked... real_exception = eie.ImportedHeader.HeaderException def throwing(column, title): raise real_exception("message") find_field_by_name = mock.MagicMock(side_effect=throwing) with mock.patch( 'flooding_lib.excel_import_export.ImportedHeader', return_value=mock.MagicMock( find_field_by_name=find_field_by_name), HeaderException=real_exception): _, errors = eie.import_header(header_titles) self.assertEquals(errors, ["message"])