Server IP : 85.214.239.14 / Your IP : 3.144.16.40 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /srv/modoboa/env/lib/python3.5/site-packages/modoboa_contacts/ |
Upload File : |
"""Mocks to test the contacts plugin.""" import httmock @httmock.urlmatch(method="OPTIONS") def options_mock(url, request): """Simulate options request.""" return {"status_code": 200, "headers": {"DAV": "addressbook"}} @httmock.urlmatch(method="MKCOL") def mkcol_mock(url, request): """Simulate collection creation.""" return {"status_code": 201} @httmock.urlmatch(method="DELETE") def delete_mock(url, request): """Simulate a DELETE request.""" return {"status_code": 204} @httmock.urlmatch(method="PUT") def put_mock(url, request): """Simulate a PUT request.""" return {"status_code": 200, "headers": {"etag": '"12345"'}} @httmock.urlmatch(method="PROPFIND") def propfind_mock(url, request): """Simulate a PROPFIND request.""" content = b""" <d:multistatus xmlns:d="DAV:" xmlns:cs="http://calendarserver.org/ns/"> <d:response> <d:href>/radicale/user@test.com/contacts/</d:href> <d:propstat> <d:prop> <d:sync-token>http://modoboa.org/ns/sync-token/3145</d:sync-token> </d:prop> <d:status>HTTP/1.1 200 OK</d:status> </d:propstat> </d:response> </d:multistatus> """ return {"status_code": 200, "content": content} @httmock.urlmatch(method="REPORT") def report_mock(url, request): """Simulate a REPORT request.""" if url.path.endswith(".vcf"): content = b""" <d:multistatus xmlns:d="DAV:"> <d:response> <d:href>/radicale/user@test.com/contacts/newcard.vcf</d:href> <d:propstat> <d:prop> <d:getetag>"33441-34321"</d:getetag> </d:prop> <d:status>HTTP/1.1 200 OK</d:status> </d:propstat> </d:response> </d:multistatus> """ else: content = b""" <d:multistatus xmlns:d="DAV:"> <d:response> <d:href>/radicale/user@test.com/contacts/newcard.vcf</d:href> <d:propstat> <d:prop> <d:getetag>"33441-34321"</d:getetag> </d:prop> <d:status>HTTP/1.1 200 OK</d:status> </d:propstat> </d:response> <d:response> <d:href>/radicale/user@test.com/contacts/updatedcard.vcf</d:href> <d:propstat> <d:prop> <d:getetag>"33541-34696"</d:getetag> </d:prop> <d:status>HTTP/1.1 200 OK</d:status> </d:propstat> </d:response> <d:response> <d:href>/radicale/user@test.com/contacts/deletedcard.vcf</d:href> <d:status>HTTP/1.1 404 Not Found</d:status> </d:response> <d:sync-token>http://modoboa.org/ns/sync/5001</d:sync-token> </d:multistatus> """ return {"status_code": 200, "content": content} @httmock.urlmatch(method="GET") def get_mock(url, request): """Simulate a GET request.""" uid = url.path.split("/")[-1] content = """ BEGIN:VCARD VERSION:3.0 UID:{} N:Gump;Forrest FN:Forrest Gump ORG:Bubba Gump Shrimp Co. TITLE:Shrimp Man TEL;TYPE=WORK;VOICE:(111) 555-1212 TEL;TYPE=HOME;VOICE:(404) 555-1212 ADR;TYPE=HOME:;;42 Plantation St.;Baytown;LA;30314;United States of America EMAIL;TYPE=PREF,INTERNET:forrestgump@example.com END:VCARD """.format(uid) return {"status_code": 200, "content": content}