I am attempting to utilize the Presenter-First approach to a new project. I find myself with unittest below. Am I utilizing poor unit testing practices by including so many assertions in this test? If yes, is the issue with my approach to the test or to the implementation of presenter.setOverview? In otherwords, should the setOverview method call self.setSalesQty rather than self.view.setSalesQty? In this case, I would have a separate test for presenter.setSalesQty and the testSetOverview test would no longer need to worry about testing this.
def testSetOverview(self):
# set up mock objects
p = PropertyMock()
type(self.mock_model).descriptions = p
self.mock_model.getData.side_effect = [5, 10]
self.mock_model.getDescription.side_effect = 'Description'
# get required variables
end = dt.date.today()
start = dt.date(year=end.year, month=1, day=1)
pn = 'abcd'
# call presenter method
self.presenter.setOverview(pn)
# test to make sure proper calls were made
model_getData_calls = [call(pn=pn, start=start, end=end,
data=self.mock_model.SHIPPED_QUANTITY),
call(pn=pn, start=start, end=end,
data=self.mock_model.PRICE_PAID)]
self.mock_model.getData.assert_has_calls(model_getData_calls, any_order=True)
assert self.mock_model.getDescription.called
self.mock_view.setSalesQty.assert_called_with(val=5)
self.mock_view.setSalesDols.assert_called_with(val=10)
self.mock_view.setDescription.assert_called_with(val='Description')
Aucun commentaire:
Enregistrer un commentaire