def test_get_field_names(self, test_input): class Field(object): name = "" def __init__(self, name): self.name = name class Model(object): __name__ = "" one = Field(name="one") two = Field(name="two") three = Field(name="three") return_value = [ Model().__getattribute__(field) for field in dir(Model()) if not field.startswith("__") ] Model._meta = mock.MagicMock() Model._meta.get_fields = mock.MagicMock(return_value=return_value) # Choose the second return_value test_input.side_effect = [2, "C"] field_names = get_field_names(Model()) # Test that the second return_value returned self.assertEqual(field_names, [return_value[1].name])
def test_get_field_names(self, test_input): class Field(object): name = "" def __init__(self, name): self.name = name class Model(object): __name__ = "" one = Field(name="one") two = Field(name="two") three = Field(name="three") return_value = [Model().__getattribute__(field) for field in dir(Model()) if not field.startswith("__")] Model._meta = mock.MagicMock() Model._meta.get_fields = mock.MagicMock(return_value=return_value) # Choose the second return_value test_input.side_effect = [2, "C"] field_names = get_field_names(Model()) # Test that the second return_value returned self.assertEqual(field_names, [return_value[1].name])