nebraska: behaviour-based "noupdate" unit test
Instead of testing the internal implementation of how Nebraska handles
update requests when the is no update available, we test the behaviour:
- create an update request of a valid app that does not have an update
- ensure that the response contains <updatecheck status="noupdate"/>
Also use GIVEN/WHEN/THEN format to document the test.
BUG=chromium:920404
TEST=./run_unittests
Change-Id: I63274254cab866e38b5dfb5e7b805aba3be6aa73
Reviewed-on: https://chromium-review.googlesource.com/1650716
Tested-by: Nicolas Norvez <norvez@chromium.org>
Commit-Ready: Nicolas Norvez <norvez@chromium.org>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Jae Hoon Kim <kimjae@chromium.org>
Reviewed-by: Xiaochu Liu <xiaochu@chromium.org>
Reviewed-by: Amin Hassani <ahassani@chromium.org>
diff --git a/nebraska/response_unittest.py b/nebraska/response_unittest.py
index 0c58037..d62a65d 100755
--- a/nebraska/response_unittest.py
+++ b/nebraska/response_unittest.py
@@ -131,19 +131,18 @@
def testAppResponseNoUpdate(self):
"""Tests AppResponse generation for update request with no new versions."""
- app_request = unittest_common.GenerateAppRequest()
+ # GIVEN an update request.
+ app_request = unittest_common.GenerateAppRequest(
+ request_type=nebraska.Request.RequestType.UPDATE)
+ # GIVEN Nebraska does not find an update.
self._properties.update_app_index.Find.return_value = None
+ # GIVEN it is a valid app.
self._properties.update_app_index.Contains.return_value = True
+ # WHEN Nebraska sends a response.
response = nebraska.Response.AppResponse(app_request, self._properties)
- self.assertTrue(response._app_request == app_request)
- self.assertFalse(response._err_not_found)
- self.assertTrue(response._app_data is None)
-
- self._properties.update_app_index.Find.assert_called_once_with(app_request)
- self._properties.install_app_index.Find.assert_not_called()
-
+ # THEN the response contains <updatecheck status="noupdate"/>.
update_check_tag = response.Compile().findall('updatecheck')[0]
self.assertTrue(update_check_tag.attrib['status'] == 'noupdate')