forked from hedyorg/hedy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_translation_error.py
34 lines (23 loc) · 1.22 KB
/
test_translation_error.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from app import app, translate_error
from hedy import exceptions
from hedy_content import ALL_LANGUAGES
from parameterized import parameterized
from tests.Tester import HedyTester
def exception_language_input():
exceptions_ = create_exceptions()
languages = ALL_LANGUAGES.keys()
return [(ex, lang) for lang in languages for ex in exceptions_]
def custom_name_func(testcase_func, _, param):
(ex, lang) = param.args
return parameterized.to_safe_name(f"{testcase_func.__name__}_{ex.__class__.__name__}_to_{lang}_lang")
def create_exceptions():
exception_classes = [cls for cls in exceptions.HedyException.__subclasses__()]
return [create_exception(exception_class) for exception_class in exception_classes]
def create_exception(ex_class):
ex_args = [f'{n}-value' for n in ex_class.__init__.__code__.co_varnames if n not in ['self', 'arguments']]
return ex_class(*ex_args)
class TestsTranslationError(HedyTester):
@parameterized.expand(exception_language_input(), name_func=custom_name_func)
def test_translate_hedy_exception(self, exception, language):
with app.test_request_context(headers={'Accept-Language': language}):
translate_error(exception.error_code, exception.arguments)