def testPutModWhenError(self):
    """Test _PutMod."""
    mod_type = 'owner'
    target = 'foouser'
    pkg_name = 'Foo%20Pkg-1.2'
    install_types = ['optional_installs']

    mock_entity = self.mox.CreateMockAnything()

    # This code partially replicates self.c._ParseParameters.
    # It is hard to reuse that function for testing because it uses
    # self.request...
    self.c.mod_type = mod_type
    # Instead of dyn_man.models.MANIFEST_MOD_MODELS.get(mod_type, None)
    # plug our mock in immediately.
    self.c.model = self.mox.CreateMockAnything()
    self.c.target = urllib.unquote(target)
    self.c.pkg_name = urllib.unquote(pkg_name)
    self.c.key_name = '%s##%s' % (self.c.target, self.c.pkg_name)
    self.c.install_types = install_types
    self.c.manifests = []
    # End partially replicated section.

    self.c.model(key_name=self.c.key_name).AndReturn(mock_entity)
    self.mox.StubOutWithMock(
        dyn_man.models.BaseManifestModification, 'ResetModMemcache')

    mock_entity.put().AndRaise(dyn_man.db.Error)

    self.mox.ReplayAll()
    self.assertRaises(dyn_man.db.Error, self.c._PutMod)
    self.mox.VerifyAll()
dataset/ETHPy150Open google/simian/src/tests/simian/mac/api/dynamic_manifest_test.py/DynamicManifestHandlersTest.testPutModWhenError/original