From 5ffdbd99e85828d03cb2cfca1d6048d8bcd52867 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Wed, 22 Jan 2020 13:16:06 +0100 Subject: [PATCH] adapt python bindings, remove tests until we really have data --- python/src/deltachat/provider.py | 32 ++++++------------------------ python/tests/test_lowlevel.py | 11 ---------- python/tests/test_provider_info.py | 21 +------------------- 3 files changed, 7 insertions(+), 57 deletions(-) diff --git a/python/src/deltachat/provider.py b/python/src/deltachat/provider.py index ad98daf96..40591748a 100644 --- a/python/src/deltachat/provider.py +++ b/python/src/deltachat/provider.py @@ -11,27 +11,18 @@ class ProviderNotFoundError(Exception): class Provider(object): """Provider information. - :param domain: The domain to get the provider info for, this is - normally the part following the `@` of the domain. + :param domain: The email to get the provider info for. """ - def __init__(self, domain): + def __init__(self, addr): provider = ffi.gc( - lib.dc_provider_new_from_domain(as_dc_charpointer(domain)), + lib.dc_provider_new_from_email(as_dc_charpointer(addr)), lib.dc_provider_unref, ) if provider == ffi.NULL: raise ProviderNotFoundError("Provider not found") self._provider = provider - @classmethod - def from_email(cls, email): - """Create provider info from an email address. - - :param email: Email address to get provider info for. - """ - return cls(email.split('@')[-1]) - @property def overview_page(self): """URL to the overview page of the provider on providers.delta.chat.""" @@ -39,21 +30,10 @@ class Provider(object): lib.dc_provider_get_overview_page(self._provider)) @property - def name(self): - """The name of the provider.""" - return from_dc_charpointer(lib.dc_provider_get_name(self._provider)) - - @property - def markdown(self): - """Content of the information page, formatted as markdown.""" + def get_before_login_hints(self): + """Should be shown to the user on login.""" return from_dc_charpointer( - lib.dc_provider_get_markdown(self._provider)) - - @property - def status_date(self): - """The date the provider info was last updated, as a string.""" - return from_dc_charpointer( - lib.dc_provider_get_status_date(self._provider)) + lib.dc_provider_get_before_login_hints(self._provider)) @property def status(self): diff --git a/python/tests/test_lowlevel.py b/python/tests/test_lowlevel.py index 915631895..41506bbaf 100644 --- a/python/tests/test_lowlevel.py +++ b/python/tests/test_lowlevel.py @@ -102,17 +102,6 @@ def test_get_special_message_id_returns_empty_message(acfactory): assert msg.id == 0 -def test_provider_info(): - provider = lib.dc_provider_new_from_email(cutil.as_dc_charpointer("ex@example.com")) - assert cutil.from_dc_charpointer( - lib.dc_provider_get_overview_page(provider) - ) == "https://providers.delta.chat/example.com" - assert cutil.from_dc_charpointer(lib.dc_provider_get_name(provider)) == "Example" - assert cutil.from_dc_charpointer(lib.dc_provider_get_markdown(provider)) == "\n..." - assert cutil.from_dc_charpointer(lib.dc_provider_get_status_date(provider)) == "2018-09" - assert lib.dc_provider_get_status(provider) == const.DC_PROVIDER_STATUS_PREPARATION - - def test_provider_info_none(): assert lib.dc_provider_new_from_email(cutil.as_dc_charpointer("email@unexistent.no")) == ffi.NULL diff --git a/python/tests/test_provider_info.py b/python/tests/test_provider_info.py index 10c9fb27d..af7f437ed 100644 --- a/python/tests/test_provider_info.py +++ b/python/tests/test_provider_info.py @@ -1,27 +1,8 @@ import pytest -from deltachat import const from deltachat import provider -def test_provider_info_from_email(): - example = provider.Provider.from_email("email@example.com") - assert example.overview_page == "https://providers.delta.chat/example.com" - assert example.name == "Example" - assert example.markdown == "\n..." - assert example.status_date == "2018-09" - assert example.status == const.DC_PROVIDER_STATUS_PREPARATION - - -def test_provider_info_from_domain(): - example = provider.Provider("example.com") - assert example.overview_page == "https://providers.delta.chat/example.com" - assert example.name == "Example" - assert example.markdown == "\n..." - assert example.status_date == "2018-09" - assert example.status == const.DC_PROVIDER_STATUS_PREPARATION - - def test_provider_info_none(): with pytest.raises(provider.ProviderNotFoundError): - provider.Provider.from_email("email@unexistent.no") + provider.Provider("email@unexistent.no")