Code Monkey home page Code Monkey logo

mailpit-api-client's People

Contributors

corvan avatar dependabot[bot] avatar lal-solute avatar

Stargazers

 avatar  avatar

Watchers

 avatar

mailpit-api-client's Issues

If milliseconds are exactly 0, they are omitted by Mailpit

References lines:

def millis_to_3_digit(isoformat: str) -> str:
"""replaces milliseconds with
three-digits long value using zero padding before"""
millis = _re.search(r"\.\d{0,3}", isoformat)
if not millis:
raise ValueError("No milliseconds provided in isoformat string")

Error:

============================= test session starts ==============================
platform linux -- Python 3.9.16, pytest-7.3.1, pluggy-1.0.0 -- /usr/local/bin/python
cachedir: .pytest_cache
rootdir: /root/mailpit-api-client
configfile: pyproject.toml
plugins: docker-1.0.1, anyio-3.7.0, respx-0.20.1
collecting ... collected 28 items

root/mailpit-api-client/tests/integration/test_api_message.py::TestMessageApiGet::test_get_message 
-------------------------------- live log setup --------------------------------
11:14:51 - INFO - /root/mailpit-api-client/tests/integration/conftest.py - line: 31 - smtp_server() - connecting to smtp_server
11:14:51 - INFO - /root/mailpit-api-client/tests/integration/conftest.py - line: 41 - sent_message_id_without_attachment() - reading mail from file
11:14:51 - INFO - /root/mailpit-api-client/tests/integration/conftest.py - line: 44 - sent_message_id_without_attachment() - sending message
ERROR---------------------------- live log sessionfinish ----------------------------
11:14:51 - INFO - /root/mailpit-api-client/tests/integration/conftest.py - line: 34 - smtp_server() - closing smtp server connection
Traceback (most recent call last):
  File "/usr/local/bin/pytest", line 8, in <module>
    sys.exit(console_main())
  File "/usr/local/lib/python3.9/site-packages/_pytest/config/__init__.py", line 189, in console_main
    code = main()
  File "/usr/local/lib/python3.9/site-packages/_pytest/config/__init__.py", line 166, in main
    ret: Union[ExitCode, int] = config.hook.pytest_cmdline_main(
  File "/usr/local/lib/python3.9/site-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/usr/local/lib/python3.9/site-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/usr/local/lib/python3.9/site-packages/pluggy/_callers.py", line 60, in _multicall
    return outcome.get_result()
  File "/usr/local/lib/python3.9/site-packages/pluggy/_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/usr/local/lib/python3.9/site-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/usr/local/lib/python3.9/site-packages/_pytest/main.py", line 316, in pytest_cmdline_main
    return wrap_session(config, _main)
  File "/usr/local/lib/python3.9/site-packages/_pytest/main.py", line 304, in wrap_session
    config.hook.pytest_sessionfinish(
  File "/usr/local/lib/python3.9/site-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/usr/local/lib/python3.9/site-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/usr/local/lib/python3.9/site-packages/pluggy/_callers.py", line 55, in _multicall
    gen.send(outcome)
  File "/usr/local/lib/python3.9/site-packages/_pytest/terminal.py", line 812, in pytest_sessionfinish
    outcome.get_result()
  File "/usr/local/lib/python3.9/site-packages/pluggy/_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/usr/local/lib/python3.9/site-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/usr/local/lib/python3.9/site-packages/_pytest/runner.py", line 108, in pytest_sessionfinish
    session._setupstate.teardown_exact(None)
  File "/usr/local/lib/python3.9/site-packages/_pytest/runner.py", line 537, in teardown_exact
    raise exceptions[0]
  File "/usr/local/lib/python3.9/site-packages/_pytest/runner.py", line 526, in teardown_exact
    fin()
  File "/usr/local/lib/python3.9/site-packages/_pytest/fixtures.py", line 686, in <lambda>
    subrequest.node.addfinalizer(lambda: fixturedef.finish(request=subrequest))
  File "/usr/local/lib/python3.9/site-packages/_pytest/fixtures.py", line 1038, in finish
    raise exc
  File "/usr/local/lib/python3.9/site-packages/_pytest/fixtures.py", line 1031, in finish
    func()
  File "/usr/local/lib/python3.9/site-packages/_pytest/fixtures.py", line 918, in _teardown_yield_fixture
    next(it)
  File "/root/mailpit-api-client/tests/integration/conftest.py", line 24, in api
    messages = client_api.get_messages()
  File "/root/mailpit-api-client/mailpit/client/api.py", line 46, in get_messages
    return _models.Messages.from_json(response.text)  # type: ignore
  File "/usr/local/lib/python3.9/site-packages/dataclasses_json/api.py", line 65, in from_json
    return cls.from_dict(kvs, infer_missing=infer_missing)
  File "/usr/local/lib/python3.9/site-packages/dataclasses_json/api.py", line 72, in from_dict
    return _decode_dataclass(cls, kvs, infer_missing)
  File "/usr/local/lib/python3.9/site-packages/dataclasses_json/core.py", line 201, in _decode_dataclass
    init_kwargs[field.name] = _decode_generic(field_type,
  File "/usr/local/lib/python3.9/site-packages/dataclasses_json/core.py", line 263, in _decode_generic
    res = _get_type_cons(type_)(xs)
  File "/usr/local/lib/python3.9/site-packages/dataclasses_json/core.py", line 317, in <genexpr>
    items = (_decode_dataclass(type_arg, x, infer_missing)
  File "/usr/local/lib/python3.9/site-packages/dataclasses_json/core.py", line 187, in _decode_dataclass
    init_kwargs[field.name] = overrides[field.name].decoder(
  File "/root/mailpit-api-client/mailpit/client/models.py", line 250, in datetime_decoder
    result = zulu_to_utc_shift(millis_to_3_digit(isoformat))
  File "/root/mailpit-api-client/mailpit/client/models.py", line 233, in millis_to_3_digit
    raise ValueError("No milliseconds provided in isoformat string")
ValueError: No milliseconds provided in isoformat string

combine separate modules in models package to single models module

Tried this in the referenced branch, but got

============================= test session starts ==============================
platform linux -- Python 3.9.16, pytest-7.3.1, pluggy-1.0.0
rootdir: /root/mailpit-api-client
configfile: pyproject.toml
plugins: anyio-3.7.0, respx-0.20.1
collected 14 items

root/mailpit-api-client/tests/unit/test_api_message.py ...F

=================================== FAILURES ===================================
________________________ TestHeadersAPI.test_header_get ________________________

self = <unit.test_api_message.TestHeadersAPI object at 0x7fa8b257c370>
api = <mailpit.client.api.API object at 0x7fa8b253b310>
response = {'Content-Type': ['multipart/related; type="multipart/alternative"; boundary="----=_NextPart_000_0013_01C6A60C.47EEAB8...ered-To': ['[email protected]', '[email protected]'], 'From': ['"User Name" \\[email protected]\\u003e'], ...}

    @respx.mock
    def test_header_get(self, api, response):
        route = respx.get(
            "https://example.com/api/v1/message/"
            "d7a5543b-96dd-478b-9b60-2b465c9884de/headers"
        )
    
        route.mock(return_value=httpx.Response(200, json=response))
    
>       headers = api.get_message_headers("d7a5543b-96dd-478b-9b60-2b465c9884de")

api        = <mailpit.client.api.API object at 0x7fa8b253b310>
response   = {'Content-Type': ['multipart/related; type="multipart/alternative"; boundary="----=_NextPart_000_0013_01C6A60C.47EEAB8...ered-To': ['[email protected]', '[email protected]'], 'From': ['"User Name" \\[email protected]\\u003e'], ...}
route      = <Route <Scheme eq 'https'> AND <Host eq 'example.com'> AND <Path eq '/api/v1/message/d7a5543b-96dd-478b-9b60-2b465c9884de/headers'> AND <Method eq 'GET'>>
self       = <unit.test_api_message.TestHeadersAPI object at 0x7fa8b257c370>

root/mailpit-api-client/tests/unit/test_api_message.py:282: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
root/mailpit-api-client/mailpit/client/api.py:127: in get_message_headers
    return _models.Headers.from_json(response.text)  # type: ignore
        message_id = 'd7a5543b-96dd-478b-9b60-2b465c9884de'
        response   = <Response [200 OK]>
        self       = <mailpit.client.api.API object at 0x7fa8b253b310>
usr/local/lib/python3.9/site-packages/dataclasses_json/api.py:65: in from_json
    return cls.from_dict(kvs, infer_missing=infer_missing)
        cls        = <class 'mailpit.client.models.Headers'>
        infer_missing = False
        kvs        = {'Content-Type': ['multipart/related; type="multipart/alternative"; boundary="----=_NextPart_000_0013_01C6A60C.47EEAB8...ered-To': ['[email protected]', '[email protected]'], 'From': ['"User Name" \\[email protected]\\u003e'], ...}
        kw         = {}
        parse_constant = None
        parse_float = None
        parse_int  = None
        s          = '{"Content-Type": ["multipart/related; type=\\"multipart/alternative\\"; boundary=\\"----=_NextPart_000_0013_01C6A60C....\\\[email protected]\\\\u003e"], "Message-Id": ["\\\\u003c001701c6a5a7$b3205580$0201010a@HomeOfficeSM\\\\u003e"]}'
usr/local/lib/python3.9/site-packages/dataclasses_json/api.py:72: in from_dict
    return _decode_dataclass(cls, kvs, infer_missing)
        cls        = <class 'mailpit.client.models.Headers'>
        infer_missing = False
        kvs        = {'Content-Type': ['multipart/related; type="multipart/alternative"; boundary="----=_NextPart_000_0013_01C6A60C.47EEAB8...ered-To': ['[email protected]', '[email protected]'], 'From': ['"User Name" \\[email protected]\\u003e'], ...}
usr/local/lib/python3.9/site-packages/dataclasses_json/core.py:149: in _decode_dataclass
    kvs = _handle_undefined_parameters_safe(cls, kvs, usage="from")
        cls        = <class 'mailpit.client.models.Headers'>
        decode_names = {'Content-Type': 'content_type', 'Date': 'date', 'Delivered-To': 'delivered_to', 'From': 'from_', ...}
        field      = Field(name='additional',type='_dj.CatchAll',default=<dataclasses._MISSING_TYPE object at 0x7fa8b3a9b580>,default_facto...TYPE object at 0x7fa8b3a9b580>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD)
        field_names = ['content_type', 'date', 'delivered_to', 'from_', 'message_id', 'additional']
        infer_missing = False
        kvs        = {'content_type': ['multipart/related; type="multipart/alternative"; boundary="----=_NextPart_000_0013_01C6A60C.47EEAB8...red_to': ['[email protected]', '[email protected]'], 'from_': ['"User Name" \\[email protected]\\u003e'], ...}
        missing_fields = {Field(name='additional',type='_dj.CatchAll',default=<dataclasses._MISSING_TYPE object at 0x7fa8b3a9b580>,default_fact...YPE object at 0x7fa8b3a9b580>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD)}
        overrides  = {'additional': FieldOverride(encoder=None, decoder=None, mm_field=None, letter_case=None, exclude=None), 'content_type...ne, decoder=None, mm_field=None, letter_case=<function config.<locals>.override at 0x7fa8b2578790>, exclude=None), ...}
usr/local/lib/python3.9/site-packages/dataclasses_json/utils.py:144: in _handle_undefined_parameters_safe
    return undefined_parameter_action.value.handle_from_dict(cls=cls,
        cls        = <class 'mailpit.client.models.Headers'>
        kvs        = {'content_type': ['multipart/related; type="multipart/alternative"; boundary="----=_NextPart_000_0013_01C6A60C.47EEAB8...red_to': ['[email protected]', '[email protected]'], 'from_': ['"User Name" \\[email protected]\\u003e'], ...}
        undefined_parameter_action = <Undefined.INCLUDE: <class 'dataclasses_json.undefined._CatchAllUndefinedParameters'>>
        usage      = 'from'
usr/local/lib/python3.9/site-packages/dataclasses_json/undefined.py:137: in handle_from_dict
    catch_all_field = _CatchAllUndefinedParameters._get_catch_all_field(
        cls        = <class 'mailpit.client.models.Headers'>
        known      = {'content_type': ['multipart/related; type="multipart/alternative"; boundary="----=_NextPart_000_0013_01C6A60C.47EEAB8...red_to': ['[email protected]', '[email protected]'], 'from_': ['"User Name" \\[email protected]\\u003e'], ...}
        kvs        = {'content_type': ['multipart/related; type="multipart/alternative"; boundary="----=_NextPart_000_0013_01C6A60C.47EEAB8...red_to': ['[email protected]', '[email protected]'], 'from_': ['"User Name" \\[email protected]\\u003e'], ...}
        unknown    = {}
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

cls = <class 'mailpit.client.models.Headers'>

    @staticmethod
    def _get_catch_all_field(cls) -> Field:
        catch_all_fields = list(
            filter(lambda f: f.type == Optional[CatchAllVar], fields(cls)))
        number_of_catch_all_fields = len(catch_all_fields)
        if number_of_catch_all_fields == 0:
>           raise UndefinedParameterError(
E           dataclasses_json.undefined.UndefinedParameterError: No field of type dataclasses_json.CatchAll defined

catch_all_fields = []
cls        = <class 'mailpit.client.models.Headers'>
number_of_catch_all_fields = 0

usr/local/lib/python3.9/site-packages/dataclasses_json/undefined.py:249: UndefinedParameterError
------------------------------ Captured log call -------------------------------
18:15:07 - DEBUG - /usr/local/lib/python3.9/site-packages/httpx/_config.py - line: 79 - load_ssl_context() - load_ssl_context verify=True cert=None trust_env=True http2=False
18:15:07 - DEBUG - /usr/local/lib/python3.9/site-packages/httpx/_config.py - line: 146 - load_ssl_context_verify() - load_verify_locations cafile='/usr/local/lib/python3.9/site-packages/certifi/cacert.pem'
18:15:07 - INFO - /usr/local/lib/python3.9/site-packages/httpx/_client.py - line: 1013 - _send_single_request() - HTTP Request: GET https://example.com/api/v1/message/d7a5543b-96dd-478b-9b60-2b465c9884de/headers "HTTP/1.1 200 OK"
=========================== short test summary info ============================
FAILED root/mailpit-api-client/tests/unit/test_api_message.py::TestHeadersAPI::test_header_get
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
========================= 1 failed, 3 passed in 0.11s ==========================
mailpit-api-client-39-unittest-1 exited with code 1
Aborting on container exit...
[+] Stopping 1/0
 ✔ Container mailpit-api-client-39-unittest-1  Stopped```

Add clear commands for docker containers and images

poetry run -v docker compose -f tests/docker/docker-compose.yml --profile unittest -p mailpit-api-client-310 ps -a
Using virtualenv: /home/lars/.cache/pypoetry/virtualenvs/mailpit-api-client-39aPZNZh-py3.11
NAME                                IMAGE                    COMMAND                  SERVICE             CREATED             STATUS                      PORTS
mailpit-api-client-310-black-1      black:3.10-bullseye      "black /root/mailpit"    black               27 minutes ago      Exited (0) 27 minutes ago   
mailpit-api-client-310-lint-1       lint:3.10-bullseye       "ruff check /root/ma…"   lint                27 minutes ago      Exited (0) 27 minutes ago   
mailpit-api-client-310-mypy-1       mypy:3.10-bullseye       "python3 -m mypy /ro…"   mypy                27 minutes ago      Exited (0) 27 minutes ago   
mailpit-api-client-310-unittest-1   unittest:3.10-bullseye   "pytest -slx --log-l…"   unittest            8 minutes ago       Exited (0) 8 minutes ago

poetry run -v docker compose -f tests/docker/docker-compose.yml --profile unittest -p mailpit-api-client-310 images   
Using virtualenv: /home/lars/.cache/pypoetry/virtualenvs/mailpit-api-client-39aPZNZh-py3.11
CONTAINER                           REPOSITORY          TAG                 IMAGE ID            SIZE
mailpit-api-client-310-black-1      black               3.10-bullseye       5d82696b2403        952MB
mailpit-api-client-310-lint-1       lint                3.10-bullseye       1b5f22ccd2c1        964MB
mailpit-api-client-310-mypy-1       mypy                3.10-bullseye       868cf0869e14        1GB
mailpit-api-client-310-unittest-1   unittest            3.10-bullseye       6ed0cfb2a9a4        951MB

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.