Skip to content

Commit ef99849

Browse files
Tomas-PytelTomas-Pytel
authored andcommitted
#4 Type Hints: Add tests
1 parent a2ecdf5 commit ef99849

2 files changed

Lines changed: 88 additions & 0 deletions

File tree

tests/conftest.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,17 @@
1111
@pytest.fixture(scope="module")
1212
def featureflags():
1313
return FeatureFlags
14+
15+
16+
@pytest.fixture(scope="module")
17+
def ff_from_dict(featureflags):
18+
featureflags.load_conf_from_dict(
19+
{
20+
"dict_only": False,
21+
"file_1": True,
22+
"file_2": False,
23+
"file_3": True,
24+
"file_4": True,
25+
}
26+
)
27+
return FeatureFlags

tests/test_types.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
from fastapi_featureflags import FeatureFlags, feature_enabled
2+
3+
4+
def test_empty_config():
5+
empty_ff = FeatureFlags.reload_feature_flags()
6+
assert type(empty_ff) is bool
7+
8+
9+
def test_config_from_dict(featureflags):
10+
conf_from_dict = featureflags.load_conf_from_dict(
11+
{
12+
"json_only": False,
13+
"file_1": True,
14+
"file_2": False,
15+
"file_3": True,
16+
"file_4": True,
17+
}
18+
)
19+
assert type(conf_from_dict) is bool
20+
21+
22+
def test_reload_ff(featureflags, ff_from_dict):
23+
reload_ff = featureflags.reload_feature_flags()
24+
assert type(reload_ff) is bool
25+
26+
reload_ff = ff_from_dict.reload_feature_flags()
27+
assert type(reload_ff) is bool
28+
29+
30+
def test_get_features(ff_from_dict):
31+
get_features = ff_from_dict.get_features()
32+
assert type(get_features) is dict
33+
34+
35+
def test_is_enabled(ff_from_dict):
36+
is_enabled = ff_from_dict.is_enabled("dict_only")
37+
assert type(is_enabled) is bool
38+
39+
is_enabled = ff_from_dict.is_enabled("non-existent")
40+
assert type(is_enabled) is bool
41+
42+
43+
def test_enable_feature(ff_from_dict):
44+
enable_feature = ff_from_dict.enable_feature("dict_only")
45+
assert type(enable_feature) is bool
46+
47+
enable_feature = ff_from_dict.enable_feature("non-existent")
48+
assert type(enable_feature) is bool
49+
50+
51+
def test_disable_feature(ff_from_dict):
52+
disable_feature = ff_from_dict.disable_feature("dict_only")
53+
assert type(disable_feature) is bool
54+
55+
disable_feature = ff_from_dict.disable_feature("non-existent")
56+
assert type(disable_feature) is bool
57+
58+
59+
def test_feature_enabled():
60+
is_feature_enabled = feature_enabled("dict_only")
61+
assert type(is_feature_enabled) is bool
62+
63+
is_feature_enabled = feature_enabled("non-existent")
64+
assert type(is_feature_enabled) is bool
65+
66+
67+
def test_config_from_json(featureflags):
68+
conf_from_json = featureflags.load_conf_from_json("tests/features.json")
69+
assert type(conf_from_json) is bool
70+
71+
72+
def test_config_from_url(featureflags):
73+
conf_from_url = featureflags.load_conf_from_url("https://pastebin.com/raw/4Ai3j2DC")
74+
assert type(conf_from_url) is bool

0 commit comments

Comments
 (0)