def testPostWithFailure(self):
    self.mox.StubOutWithMock(uploadpkg.handlers, 'IsBlobstore')
    uploadpkg.handlers.IsBlobstore().AndReturn(True)
    self.MockDoMunkiAuth(require_level=uploadpkg.gaeserver.LEVEL_UPLOADPKG)
    self.MockSelf('get_uploads')
    self.mox.StubOutWithMock(uploadpkg.gae_util, 'GetBlobAndDel')
    self.mox.StubOutWithMock(uploadpkg.plist_lib, 'MunkiPackageInfoPlist')
    self.mox.StubOutWithMock(uploadpkg.blobstore, 'BlobInfo')
    mock_plist = self.mox.CreateMockAnything()
    blob = self.mox.CreateMockAnything()
    blob2 = self.mox.CreateMockAnything()
    upload_files = [blob]
    pkginfo_files = [blob2]
    name = 'fooname'
    filename = 'filename.dmg'
    pkginfo_str = '<plist></plist>'
    install_types = ['managed_installs', 'managed_updates']
    catalogs = ['unstable']
    pkginfo_dict = {
        'installer_item_location': filename,
        'installer_item_hash': 'hash'}
    blobstore_key = 'fookey'

    blob2.key().AndReturn('pkginfoblobkey')
    self.request.get('user').AndReturn('foouser')
    self.request.get('name').AndReturn(filename)
    self.request.get('install_types').AndReturn(','.join(install_types))
    self.request.get('catalogs', None).AndReturn(','.join(catalogs))
    self.request.get('manifests', None).AndReturn(None)
    self.c.get_uploads('file').AndReturn(upload_files)
    self.c.get_uploads('pkginfo').AndReturn(pkginfo_files)
    uploadpkg.gae_util.GetBlobAndDel('pkginfoblobkey').AndReturn(pkginfo_str)
    uploadpkg.plist_lib.MunkiPackageInfoPlist(pkginfo_str).AndReturn(
        mock_plist)
    mock_plist.Parse().AndReturn(None)
    blob.key().AndReturn(blobstore_key)
    mock_plist.__getitem__('installer_item_location').AndReturn(filename)
    mock_plist.__getitem__('installer_item_hash').AndReturn('hash')
    uploadpkg.blobstore.BlobInfo.get(blobstore_key).AndReturn(True)

    self.mox.StubOutWithMock(uploadpkg.gae_util, 'ObtainLock')
    uploadpkg.gae_util.ObtainLock(
        'pkgsinfo_%s' % filename, timeout=5.0).AndReturn(True)

    pkg = self.MockModelStatic('PackageInfo', 'get_or_insert', filename)
    pkg.IsSafeToModify().AndReturn(True)
    pkg.blobstore_key = None
    pkg.name = name
    pkg.filename = filename
    mock_plist.GetPackageName().AndReturn(name)
    pkg.put().AndRaise(uploadpkg.db.Error)

    self.mox.StubOutWithMock(uploadpkg.logging, 'exception')
    uploadpkg.logging.exception('error on PackageInfo.put()').AndReturn(None)
    self.mox.StubOutWithMock(uploadpkg.gae_util, 'SafeBlobDel')
    uploadpkg.gae_util.SafeBlobDel(blobstore_key).AndReturn(None)
    self.mox.StubOutWithMock(uploadpkg.gae_util, 'SafeEntityDel')
    uploadpkg.gae_util.SafeEntityDel(pkg)
    self.mox.StubOutWithMock(uploadpkg.gae_util, 'ReleaseLock')
    uploadpkg.gae_util.ReleaseLock('pkgsinfo_%s' % filename).AndReturn(True)
    self.MockRedirect('/uploadpkg?mode=error')

    self.mox.ReplayAll()
    self.c.post()
    self.mox.VerifyAll()
If the getpwnam function raises a KeyError, the login fails with an
dataset/ETHPy150Open google/simian/src/tests/simian/mac/munki/handlers/uploadpkg_test.py/UploadPackageTest.testPostWithFailure--crossover with--dataset/ETHPy150Open nlloyd/SubliminalCollaborator/libs/twisted/conch/test/test_checkers.py/UNIXPasswordDatabaseTests.test_failOnKeyError