def test_disable_ops(self):
"""Verify that disable-ops works as expected."""
# For this disabled case, /catalog/1/ should return
# a NOT_FOUND error.
self.__dc.set_disable_ops(["catalog/1"])
self.__dc.set_port(self.next_free_port)
self.__dc.start()
durl = self.__dc.get_depot_url()
try:
urlopen("{0}/catalog/1/".format(durl))
except HTTPError as e:
self.assertEqual(e.code, http_client.NOT_FOUND)
self.__dc.stop()
# For this disabled case, all /catalog/ operations should return
# a NOT_FOUND error.
self.__dc.set_disable_ops(["catalog"])
self.__dc.set_port(self.next_free_port)
self.__dc.start()
durl = self.__dc.get_depot_url()
for ver in (0, 1):
try:
urlopen("{0}/catalog/{1:d}/".format(durl, ver))
except HTTPError as e:
self.assertEqual(e.code, http_client.NOT_FOUND)
self.__dc.stop()
# In the normal case, /catalog/1/ should return
# a FORBIDDEN error.
self.__dc.unset_disable_ops()
self.__dc.start()
durl = self.__dc.get_depot_url()
try:
urlopen("{0}/catalog/1/".format(durl))
except HTTPError as e:
self.assertEqual(e.code, http_client.FORBIDDEN)
self.__dc.stop()
# A bogus operation should prevent the depot from starting.
self.__dc.set_disable_ops(["no_such_op/0"])
self.__dc.start_expected_fail()
self.assertFalse(self.__dc.is_alive())
评论列表
文章目录