diff --git a/emails/testsuite/conftest.py b/emails/testsuite/conftest.py index 5269a51..a36492f 100644 --- a/emails/testsuite/conftest.py +++ b/emails/testsuite/conftest.py @@ -6,6 +6,10 @@ import random import sys import platform +import os +import functools +import threading +from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer logging.basicConfig(level=logging.DEBUG) @@ -14,6 +18,37 @@ import cssutils cssutils.log.setLevel(logging.FATAL) +import emails.utils + +TESTSUITE_ROOT = os.path.dirname(__file__) + + +class _QuietHandler(SimpleHTTPRequestHandler): + def log_message(self, *args): + pass + + +@pytest.fixture(scope='session') +def _http_fixtures_server(): + handler = functools.partial(_QuietHandler, directory=TESTSUITE_ROOT) + server = ThreadingHTTPServer(('127.0.0.1', 0), handler) + thread = threading.Thread(target=server.serve_forever, daemon=True) + thread.start() + yield 'http://127.0.0.1:%s/' % server.server_address[1] + server.shutdown() + server.server_close() + + +@pytest.fixture +def http_fixtures(_http_fixtures_server, monkeypatch): + """ + Base url of a local HTTP server that serves files from emails/testsuite, + e.g. http_fixtures + 'data/http/python-logo.gif'. + Fetching from loopback is allowed while the fixture is active. + """ + monkeypatch.setattr(emails.utils, 'url_validator', None) + return _http_fixtures_server + @pytest.fixture(scope='module') def django_email_backend(request): diff --git a/emails/testsuite/data/http/python-logo.gif b/emails/testsuite/data/http/python-logo.gif new file mode 100644 index 0000000..01c7bf3 Binary files /dev/null and b/emails/testsuite/data/http/python-logo.gif differ diff --git a/emails/testsuite/data/http/sample-template/images/facebook.gif b/emails/testsuite/data/http/sample-template/images/facebook.gif new file mode 100644 index 0000000..f85793d Binary files /dev/null and b/emails/testsuite/data/http/sample-template/images/facebook.gif differ diff --git a/emails/testsuite/data/http/sample-template/images/flickr.gif b/emails/testsuite/data/http/sample-template/images/flickr.gif new file mode 100644 index 0000000..2f39e10 Binary files /dev/null and b/emails/testsuite/data/http/sample-template/images/flickr.gif differ diff --git a/emails/testsuite/data/http/sample-template/images/gallery.png b/emails/testsuite/data/http/sample-template/images/gallery.png new file mode 100644 index 0000000..000c71e Binary files /dev/null and b/emails/testsuite/data/http/sample-template/images/gallery.png differ diff --git a/emails/testsuite/data/http/sample-template/images/spacer.gif b/emails/testsuite/data/http/sample-template/images/spacer.gif new file mode 100644 index 0000000..35d42e8 Binary files /dev/null and b/emails/testsuite/data/http/sample-template/images/spacer.gif differ diff --git a/emails/testsuite/data/http/sample-template/images/twitter.gif b/emails/testsuite/data/http/sample-template/images/twitter.gif new file mode 100644 index 0000000..1148a0b Binary files /dev/null and b/emails/testsuite/data/http/sample-template/images/twitter.gif differ diff --git a/emails/testsuite/data/http/sample-template/images/widget-hero3.png b/emails/testsuite/data/http/sample-template/images/widget-hero3.png new file mode 100644 index 0000000..ba184ec Binary files /dev/null and b/emails/testsuite/data/http/sample-template/images/widget-hero3.png differ diff --git a/emails/testsuite/data/http/sample-template/images/widget-logo4.png b/emails/testsuite/data/http/sample-template/images/widget-logo4.png new file mode 100644 index 0000000..4a4e735 Binary files /dev/null and b/emails/testsuite/data/http/sample-template/images/widget-logo4.png differ diff --git a/emails/testsuite/data/http/sample-template/template-widgets.html b/emails/testsuite/data/http/sample-template/template-widgets.html new file mode 100644 index 0000000..e805f34 --- /dev/null +++ b/emails/testsuite/data/http/sample-template/template-widgets.html @@ -0,0 +1,301 @@ + + + +
+ +
+
+
+ +
|
+