def test_that_put_reports_consistent_timestamps(self):
        # This checks for the behaviour reported in Bug 739519, where
        # the timestamp in the body of a PUT response could be different
        # from the one reported in X-Weave-Timestamp.
        wbo = {'id': 'TEST', 'payload': 'DATA'}
        res = self.app.put_json(self.root + '/storage/col2/TEST', wbo)
        for i in xrange(200):
            wbo = self.app.get(self.root + '/storage/col2/TEST').json
            res = self.app.put_json(self.root + '/storage/col2/TEST', wbo)
            self.assertEquals(float(res.body),
                              float(res.headers["X-Weave-Timestamp"]))

    def test_that_expired_items_can_be_overwritten_via_PUT(self):
        # Upload something with a small ttl.
        bso = {"payload": "XYZ", "ttl": 0}
        self.app.put_json(self.root + "/storage/col2/TEST", bso)
        # Wait for it to expire.
        time.sleep(0.02)
        self.app.get(self.root + "/storage/col2/TEST", status=404)
        # Overwriting it should still work.
        bso = {"payload": "XYZ", "ttl": 42}
        self.app.put_json(self.root + "/storage/col2/TEST", bso)


if __name__ == "__main__":
    # When run as a script, this file will execute the
    # functional tests against a live webserver.
    res = run_live_functional_tests(TestOldStorage, sys.argv)
    sys.exit(res)
    def test_that_put_reports_consistent_timestamps(self):
        # This checks for the behaviour reported in Bug 739519, where
        # the timestamp in the body of a PUT response could be different
        # from the one reported in X-Weave-Timestamp.
        wbo = {'id': 'TEST', 'payload': 'DATA'}
        res = self.app.put_json(self.root + '/storage/col2/TEST', wbo)
        for i in xrange(200):
            wbo = self.app.get(self.root + '/storage/col2/TEST').json
            res = self.app.put_json(self.root + '/storage/col2/TEST', wbo)
            self.assertEquals(float(res.body),
                              float(res.headers["X-Weave-Timestamp"]))

    def test_that_expired_items_can_be_overwritten_via_PUT(self):
        # Upload something with a small ttl.
        bso = {"payload": "XYZ", "ttl": 0}
        self.app.put_json(self.root + "/storage/col2/TEST", bso)
        # Wait for it to expire.
        time.sleep(0.02)
        self.app.get(self.root + "/storage/col2/TEST", status=404)
        # Overwriting it should still work.
        bso = {"payload": "XYZ", "ttl": 42}
        self.app.put_json(self.root + "/storage/col2/TEST", bso)


if __name__ == "__main__":
    # When run as a script, this file will execute the
    # functional tests against a live webserver.
    res = run_live_functional_tests(TestOldStorage, sys.argv)
    sys.exit(res)
    @restore_env("MOZSVC_TEST_INI_FILE")
    def setUp(self):
        # Force use of the memcached-specific config file.
        # If we can't initialize due to an ImportError or BackendError,
        # assume that memcache is down and skip the test.
        os.environ["MOZSVC_TEST_INI_FILE"] = "tests-memcached.ini"
        try:
            super(TestAITCMemcached, self).setUp()
            # Check that it's actualy usable
            storage = self.config.registry.get("syncstorage:storage:default")
            storage.cache.get("test")
        except (ImportError, BackendError):
            raise unittest2.SkipTest()
        except webtest.AppError, e:
            if "503" not in str(e):
                raise
            raise unittest2.SkipTest()

    def _cleanup_test_databases(self):
        storage = self.config.registry.get("syncstorage:storage:default")
        if storage:
            storage.cache.flush_all()
        super(TestAITCMemcached, self)._cleanup_test_databases()


if __name__ == "__main__":
    # When run as a script, this file will execute the
    # functional tests against a live webserver.
    res = run_live_functional_tests(TestAITC, sys.argv)
    sys.exit(res)