|
| 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