예제 #1
0
    def testCollision_Upload(self):
        """Test when upload_json tries to update an old version."""
        gsutil = FakeGSUtil()
        build = 42
        version = 'v1'
        success = False
        generations = [555, 444]
        orig = gsutil.upload_json

        def fake_upload(path, cache, generation):
            if generation == '555':
                return orig(path, cache, generation=generation)
            raise subprocess.CalledProcessError(128, ['gsutil'], None)

        orig_stat = gsutil.stat

        def fake_stat(*a, **kw):
            gsutil.generation = generations.pop()
            return orig_stat(*a, **kw)

        def fake_call(*a, **kw):
            return '[{"hello": 111}]'

        with Stub(bootstrap, 'random_sleep', Pass):
            with Stub(gsutil, 'stat', fake_stat):
                with Stub(gsutil, 'upload_json', fake_upload):
                    with Stub(bootstrap, 'call', fake_call):
                        bootstrap.append_result(gsutil, 'fake_path', build,
                                                version, success)
        self.assertIn('generation', gsutil.jsons[-1][1], gsutil.jsons)
        self.assertEquals('555', gsutil.jsons[-1][1]['generation'],
                          gsutil.jsons)
예제 #2
0
 def Try(success):
     gsutil = FakeGSUtil()
     with Stub(bootstrap, 'call', lambda *a, **kw: ''):
         bootstrap.append_result(gsutil, 'fake_path', build, version,
                                 success)
     cache = gsutil.jsons[0][0][1]
     self.assertTrue(isinstance(cache[0]['passed'], bool))
예제 #3
0
 def testCollision_Upload(self):
     """Test when upload_json tries to update an old version."""
     gsutil = FakeGSUtil()
     build = 42
     version = 'v1'
     success = False
     generations = [555, 444]
     orig = gsutil.upload_json
     def fake_upload(path, cache, generation):
         if generation == '555':
             return orig(path, cache, generation=generation)
         raise subprocess.CalledProcessError(128, ['gsutil'], None)
     orig_stat = gsutil.stat
     def fake_stat(*a, **kw):
         gsutil.generation = generations.pop()
         return orig_stat(*a, **kw)
     def fake_call(*a, **kw):
         return '[{"hello": 111}]'
     with Stub(bootstrap, 'random_sleep', Pass):
         with Stub(gsutil, 'stat', fake_stat):
             with Stub(gsutil, 'upload_json', fake_upload):
                 with Stub(bootstrap, 'call', fake_call):
                     bootstrap.append_result(
                         gsutil, 'fake_path', build, version, success)
     self.assertIn('generation', gsutil.jsons[-1][1], gsutil.jsons)
     self.assertEquals('555', gsutil.jsons[-1][1]['generation'], gsutil.jsons)
예제 #4
0
    def testCollision_Cat(self):
        """cat fails if the cache has been updated."""
        gsutil = FakeGSUtil()
        build = 42
        version = 'v1'
        success = False
        generations = ['555', '444']
        orig_stat = gsutil.stat

        def fake_stat(*a, **kw):
            gsutil.generation = generations.pop()
            return orig_stat(*a, **kw)

        def fake_cat(_, gen):
            if gen == '555':  # Which version is requested?
                return '[{"hello": 111}]'
            raise subprocess.CalledProcessError(1, ['gsutil'], None)

        with Stub(bootstrap, 'random_sleep', Pass):
            with Stub(gsutil, 'stat', fake_stat):
                with Stub(gsutil, 'cat', fake_cat):
                    bootstrap.append_result(gsutil, 'fake_path', build,
                                            version, success)
        self.assertIn('generation', gsutil.jsons[-1][1], gsutil.jsons)
        self.assertEquals('555', gsutil.jsons[-1][1]['generation'],
                          gsutil.jsons)
예제 #5
0
 def testTruncate(self):
     old = json.dumps({n: True for n in range(100000)})
     gsutil = FakeGSUtil()
     build = 123
     version = 'v.interesting'
     success = True
     with Stub(bootstrap, 'call', lambda *a, **kw: old):
         bootstrap.append_result(gsutil, 'fake_path', build, version, success)
     cache = gsutil.jsons[0][0][1]
     self.assertLess(len(cache), len(old))
예제 #6
0
 def testHandleJunk(self):
     gsutil = FakeGSUtil()
     build = 123
     version = 'v.interesting'
     success = True
     with Stub(bootstrap, 'call', lambda *a, **kw: '!@!$!@$@!$'):
         bootstrap.append_result(gsutil, 'fake_path', build, version, success)
     cache = gsutil.jsons[0][0][1]
     self.assertEquals(1, len(cache))
     self.assertIn(build, cache[0].values())
     self.assertIn(version, cache[0].values())
예제 #7
0
 def testNewJob(self):
     """Stat fails when the job doesn't exist."""
     gsutil = FakeGSUtil()
     build = 123
     version = 'v.interesting'
     success = True
     def fake_stat(*a, **kw):
         raise subprocess.CalledProcessError(1, ['gsutil'], None)
     gsutil.stat = fake_stat
     bootstrap.append_result(gsutil, 'fake_path', build, version, success)
     cache = gsutil.jsons[0][0][1]
     self.assertEquals(1, len(cache))
예제 #8
0
 def testCollision_Cat(self):
     """cat fails if the cache has been updated."""
     gsutil = FakeGSUtil()
     build = 42
     version = 'v1'
     success = False
     generations = ['555', '444']
     orig_stat = gsutil.stat
     def fake_stat(*a, **kw):
         gsutil.generation = generations.pop()
         return orig_stat(*a, **kw)
     def fake_cat(_, gen):
         if gen == '555':  # Which version is requested?
             return '[{"hello": 111}]'
         raise subprocess.CalledProcessError(1, ['gsutil'], None)
     with Stub(bootstrap, 'random_sleep', Pass):
         with Stub(gsutil, 'stat', fake_stat):
             with Stub(gsutil, 'cat', fake_cat):
                 bootstrap.append_result(
                     gsutil, 'fake_path', build, version, success)
     self.assertIn('generation', gsutil.jsons[-1][1], gsutil.jsons)
     self.assertEquals('555', gsutil.jsons[-1][1]['generation'], gsutil.jsons)
예제 #9
0
 def Try(success):
     gsutil = FakeGSUtil()
     with Stub(bootstrap, 'call', lambda *a, **kw: ''):
         bootstrap.append_result(gsutil, 'fake_path', build, version, success)
     cache = gsutil.jsons[0][0][1]
     self.assertTrue(isinstance(cache[0]['passed'], bool))