コード例 #1
0
ファイル: test_origin.py プロジェクト: dhersam/sos
    def test_origin_db_valid_setup(self):
        fake_conf = FakeConf(data=['[sos]',
            'origin_cdn_host_suffixes = origin_cdn.com'])
        test_origin = origin.filter_factory(
            {'sos_conf': fake_conf})(FakeApp())
        resp = Request.blank('http://origin_db.com:8080/v1/acc/cont',
            environ={'REQUEST_METHOD': 'POST'}).get_response(test_origin)
        self.assertEquals(resp.status_int, 404)

        fake_conf = FakeConf(data='''[sos]
origin_admin_key = unittest
origin_cdn_host_suffixes = origin_cdn.com
origin_db_hosts = origin_db.com
origin_account = .origin
max_cdn_file_size = 0
'''.split('\n'))
        test_origin = origin.filter_factory(
            {'sos_conf': fake_conf})(FakeApp())
        resp = Request.blank('http://origin_db.com:8080/v1/acc/cont',
            environ={'REQUEST_METHOD': 'POST'}).get_response(test_origin)
        self.assertEquals(resp.status_int, 500)

        fake_conf = FakeConf(data='''[sos]
origin_admin_key = unittest
origin_db_hosts = origin_db.com
origin_account = .origin
max_cdn_file_size = 0
'''.split('\n'))
        factory = origin.filter_factory(
            {'sos_conf': fake_conf})
        self.assertRaises(origin.InvalidConfiguration, factory, FakeApp())
コード例 #2
0
ファイル: test_origin.py プロジェクト: smballe/sos
    def test_valid_setup(self):
        fake_conf = FakeConf(data=['[sos]'])
        test_origin = origin.filter_factory(
            {'sos_conf': fake_conf})(FakeApp())
        self.assertFalse(test_origin._valid_setup())

        fake_conf = FakeConf()
        test_origin = origin.filter_factory(
            {'sos_conf': fake_conf})(FakeApp())
        self.assertTrue(test_origin._valid_setup())
コード例 #3
0
ファイル: test_origin.py プロジェクト: btorch/sos
    def test_origin_db_delete_enabled(self):
        fake_conf = FakeConf(
            data="""[sos]
origin_admin_key = unittest
origin_cdn_host_suffixes = origin_cdn.com
origin_db_hosts = origin_db.com
origin_account = .origin
max_cdn_file_size = 0
hash_path_suffix = testing
""".split(
                "\n"
            )
        )
        test_origin = origin.filter_factory({"sos_conf": fake_conf})
        test_origin = test_origin(FakeApp(iter([("204 No Content", {}, ""), ("204 No Content", {}, "")])))
        req = Request.blank(
            "http://origin_db.com:8080/v1/acc/cont",
            environ={"REQUEST_METHOD": "DELETE"},
            headers={"x-remove-cdn-container": "true"},
        )
        resp = req.get_response(test_origin)
        self.assertEquals(resp.status_int, 204)

        def mock_memcache(env):
            return FakeMemcache()

        was_memcache = utils.cache_from_env

        try:
            utils.cache_from_env = mock_memcache
            fake_conf = FakeConf(
                data="""[sos]
origin_admin_key = unittest
origin_cdn_host_suffixes = origin_cdn.com
origin_db_hosts = origin_db.com
origin_account = .origin
max_cdn_file_size = 0
hash_path_suffix = testing
delete_enabled = true
""".split(
                    "\n"
                )
            )
            test_origin = origin.filter_factory({"sos_conf": fake_conf})
            test_origin = test_origin(FakeApp(iter([("404 No Content", {}, ""), ("204 No Content", {}, "")])))
            req = Request.blank("http://origin_db.com:8080/v1/acc/cont", environ={"REQUEST_METHOD": "DELETE"})
            try:
                resp = req.get_response(test_origin)
            except Exception, e:
                self.assertEquals(str(e), "delete called")
        finally:
            utils.cache_from_env = was_memcache
コード例 #4
0
ファイル: test_origin.py プロジェクト: dhersam/sos
    def test_origin_db_delete_enabled(self):
        fake_conf = FakeConf(data='''[sos]
origin_admin_key = unittest
origin_cdn_host_suffixes = origin_cdn.com
origin_db_hosts = origin_db.com
origin_account = .origin
max_cdn_file_size = 0
hash_path_suffix = testing
delete_enabled = true
'''.split('\n'))
        test_origin = origin.filter_factory(
            {'sos_conf': fake_conf})
        test_origin = test_origin(FakeApp(iter([
            ('404 No Content', {}, ''),
            ('204 No Content', {}, '')
            ])))
        req = Request.blank('http://origin_db.com:8080/v1/acc/cont',
            environ={'REQUEST_METHOD': 'DELETE',})
        resp = req.get_response(test_origin)
        self.assertEquals(resp.status_int, 204)

        def mock_memcache(env):
            return FakeMemcache()
        was_memcache = utils.cache_from_env

        try:
            utils.cache_from_env = mock_memcache
            fake_conf = FakeConf(data='''[sos]
origin_admin_key = unittest
origin_cdn_host_suffixes = origin_cdn.com
origin_db_hosts = origin_db.com
origin_account = .origin
max_cdn_file_size = 0
hash_path_suffix = testing
delete_enabled = true
'''.split('\n'))
            test_origin = origin.filter_factory(
                {'sos_conf': fake_conf})
            test_origin = test_origin(FakeApp(iter([
                ('404 No Content', {}, ''),
                ('204 No Content', {}, '')
                ])))
            req = Request.blank('http://origin_db.com:8080/v1/acc/cont',
                environ={'REQUEST_METHOD': 'DELETE',})
            try:
                resp = req.get_response(test_origin)
            except Exception, e:
                self.assertEquals(str(e), 'delete called')
        finally:
            utils.cache_from_env = was_memcache
コード例 #5
0
ファイル: test_origin.py プロジェクト: dhersam/sos
    def test_cdn_get_fail(self):
        prev_data = json.dumps({'account': 'acc', 'container': 'cont',
                'ttl': 1234, 'logs_enabled': True, 'cdn_enabled': True})
        self.test_origin.app = FakeApp(iter([
            ('204 No Content', {}, prev_data), # call to _get_cdn_data
            ('500', {}, 'Failure.')])) #call to get obj
        req = Request.blank('http://1234.r3.origin_cdn.com:8080/obj1.jpg',
            environ={'REQUEST_METHOD': 'GET',
                     'swift.cdn_hash': 'abcd',
                     'swift.cdn_object_name': 'obj1.jpg'})
        resp = req.get_response(self.test_origin)
        self.assertEquals(resp.status_int, 404)

        fake_conf = FakeConf(data='''[sos]
origin_admin_key = unittest
origin_cdn_host_suffixes = origin_cdn.com
origin_db_hosts = origin_db.com
origin_account = .origin
max_cdn_file_size = 0
hash_path_suffix = testing
[incoming_url_regex]
regex_0 = ^http://origin_cdn\.com.*\/h(?P<cdn_hash>\w+)\/r\d+\/?(?P<object_name>(.+))?$
'''.split('\n'))
        test_origin = origin.filter_factory(
            {'sos_conf': fake_conf})
        test_origin = test_origin(FakeApp(iter([
                ('204 No Content', {}, prev_data), # call to _get_cdn_data
                ('200 Ok', {'Content-Length': 14}, 'Test obj body.')])))
        req = Request.blank('http://1234.r3.origin_cdn.com:8080/obj1.jpg',
            environ={'REQUEST_METHOD': 'GET',
                     'swift.cdn_hash': 'abcd',
                     'swift.cdn_object_name': 'obj1.jpg'})
        resp = req.get_response(test_origin)
        self.assertEquals(resp.status_int, 400)

        fake_conf = FakeConf(data='''[sos]
origin_admin_key = unittest
origin_cdn_host_suffixes = origin_cdn.com
origin_db_hosts = origin_db.com
origin_account = .origin
max_cdn_file_size = 0
hash_path_suffix = testing
'''.split('\n'))
        test_origin = origin.filter_factory(
            {'sos_conf': fake_conf})
        test_origin = test_origin(FakeApp(iter([ ])))
        req = Request.blank('http://1234.r3.origin_cdn.com:8080/obj1.jpg',
            environ={'REQUEST_METHOD': 'GET'})
        resp = req.get_response(test_origin)
        self.assertEquals(resp.status_int, 500)
コード例 #6
0
ファイル: test_origin.py プロジェクト: btorch/sos
    def test_origin_db_valid_setup(self):
        fake_conf = FakeConf(data=["[sos]", "origin_cdn_host_suffixes = origin_cdn.com"])
        test_origin = origin.filter_factory({"sos_conf": fake_conf})(FakeApp())
        resp = Request.blank("http://origin_db.com:8080/v1/acc/cont", environ={"REQUEST_METHOD": "POST"}).get_response(
            test_origin
        )
        self.assertEquals(resp.status_int, 404)

        fake_conf = FakeConf(
            data="""[sos]
origin_admin_key = unittest
origin_cdn_host_suffixes = origin_cdn.com
origin_db_hosts = origin_db.com
origin_account = .origin
max_cdn_file_size = 0
""".split(
                "\n"
            )
        )
        test_origin = origin.filter_factory({"sos_conf": fake_conf})(FakeApp())
        resp = Request.blank("http://origin_db.com:8080/v1/acc/cont", environ={"REQUEST_METHOD": "POST"}).get_response(
            test_origin
        )
        self.assertEquals(resp.status_int, 500)

        fake_conf = FakeConf(
            data="""[sos]
origin_admin_key = unittest
origin_db_hosts = origin_db.com
origin_account = .origin
max_cdn_file_size = 0
""".split(
                "\n"
            )
        )
        factory = origin.filter_factory({"sos_conf": fake_conf})
        self.assertRaises(origin.InvalidConfiguration, factory, FakeApp())
コード例 #7
0
ファイル: test_origin.py プロジェクト: dhersam/sos
    def test_origin_db_delete_disabled(self):
        fake_conf = FakeConf(data='''[sos]
origin_admin_key = unittest
origin_db_hosts = origin_db.com
origin_cdn_host_suffixes = origin_cdn.com
origin_account = .origin
max_cdn_file_size = 0
hash_path_suffix = testing
delete_enabled = false
'''.split('\n'))
        test_origin = origin.filter_factory(
            {'sos_conf': fake_conf})
        test_origin = test_origin(FakeApp(iter([])))
        req = Request.blank('http://origin_db.com:8080/v1/acc/cont',
            environ={'REQUEST_METHOD': 'DELETE',})
        resp = req.get_response(test_origin)
        self.assertEquals(resp.status_int, 405)
コード例 #8
0
ファイル: test_origin.py プロジェクト: dhersam/sos
    def test_origin_db_fail_bad_config(self):
        fake_conf = FakeConf(data='''[sos]
origin_admin_key = unittest
origin_cdn_host_suffixes = origin_cdn.com
origin_db_hosts = origin_db.com
origin_account = .origin
max_cdn_file_size = 0
hash_path_suffix = testing
'''.split('\n'))
        test_origin = origin.filter_factory(
            {'sos_conf': fake_conf})
        listing_data = json.dumps([
            {'name': 'test1', 'content_type': 'x-cdn/true1234-false'},
            {'name': 'test2', 'content_type': 'x-cdn/true-2234-false'}])
        test_origin = test_origin(FakeApp(iter([('200 Ok', {}, listing_data)])))
        req = Request.blank('http://origin_db.com:8080/v1/acc/cont?format=JSON',
            environ={'REQUEST_METHOD': 'GET',})
        resp = req.get_response(test_origin)
        self.assertEquals(resp.status_int, 500)
コード例 #9
0
ファイル: test_origin.py プロジェクト: btorch/sos
    def test_origin_db_delete_bad_request_second(self):
        fake_conf = FakeConf(
            data="""[sos]
origin_admin_key = unittest
origin_cdn_host_suffixes = origin_cdn.com
origin_db_hosts = origin_db.com
origin_account = .origin
max_cdn_file_size = 0
hash_path_suffix = testing
delete_enabled = true
""".split(
                "\n"
            )
        )
        test_origin = origin.filter_factory({"sos_conf": fake_conf})
        test_origin = test_origin(FakeApp(iter([("204 No Content", {}, ""), ("500 Internal Server Error", {}, "")])))
        req = Request.blank("http://origin_db.com:8080/v1/acc/cont", environ={"REQUEST_METHOD": "DELETE"})
        resp = req.get_response(test_origin)
        self.assertEquals(resp.status_int, 405)
コード例 #10
0
ファイル: test_origin.py プロジェクト: btorch/sos
    def test_origin_db_fail_bad_config(self):
        fake_conf = FakeConf(
            data="""[sos]
origin_admin_key = unittest
origin_cdn_host_suffixes = origin_cdn.com
origin_db_hosts = origin_db.com
origin_account = .origin
max_cdn_file_size = 0
hash_path_suffix = testing
""".split(
                "\n"
            )
        )
        test_origin = origin.filter_factory({"sos_conf": fake_conf})
        listing_data = json.dumps(
            [
                {"name": "test1", "content_type": "x-cdn/true1234-false"},
                {"name": "test2", "content_type": "x-cdn/true-2234-false"},
            ]
        )
        test_origin = test_origin(FakeApp(iter([("200 Ok", {}, listing_data)])))
        req = Request.blank("http://origin_db.com:8080/v1/acc/cont?format=JSON", environ={"REQUEST_METHOD": "GET"})
        resp = req.get_response(test_origin)
        self.assertEquals(resp.status_int, 500)
コード例 #11
0
ファイル: test_origin.py プロジェクト: dhersam/sos
 def setUp(self):
     fake_conf = FakeConf()
     self.test_origin = origin.filter_factory(
         {'sos_conf': fake_conf})(FakeApp())
コード例 #12
0
ファイル: test_origin.py プロジェクト: btorch/sos
    def test_cdn_get_fail(self):
        prev_data = json.dumps(
            {"account": "acc", "container": "cont", "ttl": 1234, "logs_enabled": True, "cdn_enabled": True}
        )
        self.test_origin.app = FakeApp(
            iter([("204 No Content", {}, prev_data), (500, {}, "Failure.")])  # call to _get_cdn_data
        )  # call to get obj
        req = Request.blank(
            "http://1234.r3.origin_cdn.com:8080/obj1.jpg",
            environ={"REQUEST_METHOD": "GET", "swift.cdn_hash": "abcd", "swift.cdn_object_name": "obj1.jpg"},
        )
        resp = req.get_response(self.test_origin)
        self.assertEquals(resp.status_int, 404)

        fake_conf = FakeConf(
            data="""[sos]
origin_admin_key = unittest
origin_cdn_host_suffixes = origin_cdn.com
origin_db_hosts = origin_db.com
origin_account = .origin
max_cdn_file_size = 0
hash_path_suffix = testing
[incoming_url_regex]
regex_0 = ^http://origin_cdn\.com.*\/h(?P<cdn_hash>\w+)\/r\d+\/?(?P<object_name>(.+))?$
""".split(
                "\n"
            )
        )
        test_origin = origin.filter_factory({"sos_conf": fake_conf})
        test_origin = test_origin(
            FakeApp(
                iter(
                    [
                        ("204 No Content", {}, prev_data),  # call to _get_cdn_data
                        ("200 Ok", {"Content-Length": 14}, "Test obj body."),
                    ]
                )
            )
        )
        req = Request.blank(
            "http://1234.r3.origin_cdn.com:8080/obj1.jpg",
            environ={"REQUEST_METHOD": "GET", "swift.cdn_hash": "abcd", "swift.cdn_object_name": "obj1.jpg"},
        )
        resp = req.get_response(test_origin)
        self.assertEquals(resp.status_int, 400)

        fake_conf = FakeConf(
            data="""[sos]
origin_admin_key = unittest
origin_cdn_host_suffixes = origin_cdn.com
origin_db_hosts = origin_db.com
origin_account = .origin
max_cdn_file_size = 0
hash_path_suffix = testing
""".split(
                "\n"
            )
        )
        test_origin = origin.filter_factory({"sos_conf": fake_conf})
        test_origin = test_origin(FakeApp(iter([])))
        req = Request.blank("http://1234.r3.origin_cdn.com:8080/obj1.jpg", environ={"REQUEST_METHOD": "GET"})
        resp = req.get_response(test_origin)
        self.assertEquals(resp.status_int, 500)
コード例 #13
0
ファイル: test_origin.py プロジェクト: notmyname/sos
 def setUp(self):
     fake_conf = FakeConf()
     self.test_origin = origin.filter_factory({"sos_conf": fake_conf, "register_info": False})(FakeApp())