Ejemplo n.º 1
0
 def test_print_config(self):
     r = config()
     assert r["status"] == "info"
Ejemplo n.º 2
0
    ACTION_ADD: add,
    ACTION_DELETE: delete,
    ACTION_SEARCH: search,
    ACTION_CONFIG: config,
    ACTION_DOWNLOAD: download_prepare,
    ACTION_AUTH: auth_,
    ACTION_MARK: mark,
    ACTION_STATUS: status_,
    ACTION_FILTER: filter_,
}  # type: Dict[str, Callable]

API_MAP_GET = {
    ACTION_CAL: lambda: {
        "data": cal()
    },
    ACTION_CONFIG: lambda: config(None, None),
}

NO_AUTH_ACTION = (ACTION_CAL, ACTION_AUTH)


def auth(f):  # type: ignore
    @functools.wraps(f)
    def wrapped(self: RequestHandler, *args: Any, **kwargs: Any) -> Any:
        if kwargs.get("action", None) in NO_AUTH_ACTION:
            return f(self, *args, **kwargs)

        token = self.request.headers.get("bgmi-token")
        if token == ADMIN_TOKEN:
            return f(self, *args, **kwargs)
        else:
Ejemplo n.º 3
0
 def test_wrong_DOWNLOAD_DELEGATE(self):
     r = config("DOWNLOAD_DELEGATE", "WRONG_METHOD")
     assert r["status"] == "error"
Ejemplo n.º 4
0
 def test_DOWNLOAD_DELEGATE(self):
     config("DOWNLOAD_DELEGATE", "aria2-rpc")
     config("DOWNLOAD_DELEGATE", "rr!")
     config("WGET_PATH", "some_place")
Ejemplo n.º 5
0
 def test_source(self):
     r = config("DATA_SOURCE", "233")
     assert r["status"] == "error"
Ejemplo n.º 6
0
 def test_wrong_config_name(self):
     r = config("WRONG_CONFIG_NAME", "233")
     assert r["status"] == "error"
Ejemplo n.º 7
0
 def test_readonly(self):
     r = config("DB_PATH", "/tmp/233")
     assert r["status"] == "error"
Ejemplo n.º 8
0
 def test_writable(self):
     r = config('DANMAKU_API_URL', '233')
     self.assertEqual(r['status'], 'success')
     from bgmi.config import DANMAKU_API_URL
     self.assertEqual(DANMAKU_API_URL, '233')
Ejemplo n.º 9
0
 def test_DOWNLOAD_DELEGATE(self):
     r = config('DOWNLOAD_DELEGATE', 'aria2-rpc')
     r = config('DOWNLOAD_DELEGATE', 'rr!')
     r = config('WGET_PATH', 'some_place')
Ejemplo n.º 10
0
 def test_print_config(self):
     r = config()
     self.assertEqual(r['status'], 'info')
Ejemplo n.º 11
0
 def test_wrong_DOWNLOAD_DELEGATE(self):
     r = config('DOWNLOAD_DELEGATE', 'WRONG_METHOD')
     self.assertEqual(r['status'], 'error')
Ejemplo n.º 12
0
 def test_wrong_config_name(self):
     r = config('WRONG_CONFIG_NAME', '233')
     self.assertEqual(r['status'], 'error')
Ejemplo n.º 13
0
 def test_source(self):
     r = config('DATA_SOURCE', '233')
     self.assertEqual(r['status'], 'error')
Ejemplo n.º 14
0
 def test_readonly(self):
     r = config("DB_PATH", "/tmp/233")
     self.assertEqual(r["status"], "error")
Ejemplo n.º 15
0
    def test_writable(self):
        r = config("DANMAKU_API_URL", "233")
        assert r["status"] == "success"
        from bgmi.config import DANMAKU_API_URL

        assert DANMAKU_API_URL == "233"
Ejemplo n.º 16
0
API_MAP_POST = {
    ACTION_ADD: add,
    ACTION_DELETE: delete,
    ACTION_SEARCH: search,
    ACTION_CONFIG: config,
    ACTION_DOWNLOAD: download_prepare,
    ACTION_AUTH: auth_,
    ACTION_MARK: mark,
    ACTION_STATUS: status_,
    ACTION_FILTER: filter_,
}

API_MAP_GET = {
    ACTION_CAL: lambda: {'data': cal()},
    ACTION_CONFIG: lambda: config(None, None)
}

NO_AUTH_ACTION = (ACTION_CAL, ACTION_AUTH)


def auth(f):
    @functools.wraps(f)
    def wrapper(*args, **kwargs):
        if kwargs.get('action', None) in NO_AUTH_ACTION:
            return f(*args, **kwargs)

        token = args[0].request.headers.get('bgmi-token')
        if token == ADMIN_TOKEN:
            return f(*args, **kwargs)
        else:
Ejemplo n.º 17
0
 def test_readonly(self):
     r = config('DB_PATH', '/tmp/233')
     self.assertEqual(r['status'], 'error')