def test_load_should_delegate_to_registered_providers(self): s_symbol = "" providerMock1 = mock(AbstractProvider) providerMock2 = mock(AbstractProvider) providerMock3 = mock(AbstractProvider) when(providerMock1).load(s_symbol).thenReturn(None) when(providerMock2).load(s_symbol).thenReturn(None) when(providerMock3).load(s_symbol).thenReturn(None) provider = Provider(providerMock1, providerMock2, providerMock3) provider.load(s_symbol) inorder.verify(providerMock1, times=1).load(s_symbol) inorder.verify(providerMock2, times=1).load(s_symbol) inorder.verify(providerMock3, times=1).load(s_symbol)
def test_load_should_delegate_sequentially_till_one_returns_data(self): s_symbol = "" l_data = ["Sample data"] providerMock1 = mock(AbstractProvider) providerMock2 = mock(AbstractProvider) providerMock3 = mock(AbstractProvider) when(providerMock1).load(s_symbol).thenReturn(None) when(providerMock2).load(s_symbol).thenReturn(l_data) when(providerMock3).load(s_symbol).thenReturn(None) provider = Provider(providerMock1, providerMock2, providerMock3) result = provider.load(s_symbol) assert result == l_data inorder.verify(providerMock1, times=1).load(s_symbol) inorder.verify(providerMock2, times=1).load(s_symbol) inorder.verify(providerMock3, times=0).load(s_symbol)
def test_load_should_update_providers_that_had_no_data(self): s_symbol = "" l_data = ["Sample data"] providerMock1 = mock(AbstractProvider) providerMock2 = mock(AbstractProvider) providerMock3 = mock(AbstractProvider) when(providerMock1).load(s_symbol).thenReturn(None) when(providerMock2).load(s_symbol).thenReturn(None) when(providerMock3).load(s_symbol).thenReturn(l_data) provider = Provider(providerMock1, providerMock2, providerMock3) result = provider.load(s_symbol) assert result == l_data inorder.verify(providerMock1, times=1).load(s_symbol) inorder.verify(providerMock2, times=1).load(s_symbol) inorder.verify(providerMock3, times=1).load(s_symbol) inorder.verify(providerMock3, times=0).update(anyv(), anyv()) inorder.verify(providerMock2, times=1).update(s_symbol, l_data) inorder.verify(providerMock1, times=1).update(s_symbol, l_data)
def test_load_should_return_None_if_no_providers_where_registered(self): provider = Provider() assert provider.load("") is None
def test_should_subclass_abstractProvider(self): provider = Provider() assert isinstance(provider, AbstractProvider)