Skip to content

Commit

Permalink
chore: Move to src layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Stranger6667 committed Aug 29, 2020
1 parent d7b92a1 commit 5bf9865
Show file tree
Hide file tree
Showing 30 changed files with 43 additions and 63 deletions.
7 changes: 7 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
[run]
branch = true
parallel = true
source = postmarker

[paths]
source =
src/postmarker
.tox/*/lib/python*/site-packages/postmarker

[report]
show_missing = true
Expand Down
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[build-system]
requires = ["setuptools >= 40.6.0", "wheel"]
build-backend = "setuptools.build_meta"

[tool.black]
line-length = 120
target_version = ["py37"]
Expand All @@ -9,4 +13,4 @@ multi_line_output = 3
default_section = "THIRDPARTY"
include_trailing_comma = true
known_first_party = "postmarker"
known_third_party = ["betamax", "betamax_serializers", "django", "pytest", "requests", "setuptools", "sphinx_rtd_theme", "tornado"]
known_third_party = ["betamax", "betamax_serializers", "django", "postmarker", "pytest", "requests", "setuptools", "sphinx_rtd_theme", "tornado"]
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# coding: utf-8
from setuptools import setup

import postmarker
from setuptools import find_packages, setup

install_requires = ["requests>=2.20.0"]

Expand All @@ -13,8 +11,7 @@
setup(
name="postmarker",
url="https://github.com/Stranger6667/postmarker",
version=postmarker.__version__,
packages=["postmarker", "postmarker.models", "postmarker.django"],
version="0.14.1",
license="MIT",
author="Dmitry Dygalo",
author_email="[email protected]",
Expand All @@ -23,6 +20,9 @@
keywords=["postmark", "api", "client", "email"],
description="Python client library for Postmark API",
long_description=long_description,
long_description_content_type="text/x-rst",
packages=find_packages(where="src"),
package_dir={"": "src"},
classifiers=[
"Development Status :: 4 - Beta",
"Environment :: Console",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 2 additions & 9 deletions postmarker/models/emails.py → src/postmarker/models/emails.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Basic ways to send emails."""
import mimetypes
import os
import sys
from base64 import b64encode
from email.header import decode_header
from email.mime.base import MIMEBase
Expand All @@ -11,10 +10,7 @@
from ..utils import chunks
from .base import MessageModel, Model, ModelManager

if sys.version_info[:2] <= (3, 2):
SEPARATOR = " "
else:
SEPARATOR = ""
SEPARATOR = ""


def list_to_csv(value):
Expand Down Expand Up @@ -92,10 +88,7 @@ def deconstruct_multipart_recursive(seen, text, html, attachments, message):
else:
# Ignore underlying messages inside `message/rfc822` payload, because the message itself will be passed
# as an attachment
if content_type == "message/rfc822" and sys.version_info[:2] not in (
(2, 6),
(3, 2),
):
if content_type == "message/rfc822":
for part in message.get_payload():
seen.add(part)
attachments.append(message)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

DEFAULT_SERVER_TOKEN = "SERVER_TOKEN"
DEFAULT_ACCOUNT_TOKEN = "ACCOUNT_TOKEN"
CASSETTE_DIR = "tests/cassettes/"
CASSETTE_DIR = "test/cassettes/"
SERVER_TOKEN = os.environ.get("SERVER_TOKEN", DEFAULT_SERVER_TOKEN)
ACCOUNT_TOKEN = os.environ.get("ACCOUNT_TOKEN", DEFAULT_ACCOUNT_TOKEN)

Expand Down
19 changes: 4 additions & 15 deletions test/django/test_backend.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sys
from contextlib import contextmanager
from unittest.mock import patch

Expand Down Expand Up @@ -177,16 +176,10 @@ def test_send_mail_with_attachment(postmark_request, message):
def test_text_html_alternative_and_pdf_attachment_failure(postmark_request, message):
"""Send a text body, HTML alternative, and PDF attachment."""
message.attach_alternative("<html></html>", "text/html")
if sys.version_info[:2] == (3, 2):
content = b"PDF-File-Contents"
else:
content = "PDF-File-Contents"
content = "PDF-File-Contents"
message.attach("hello.pdf", content, "application/pdf")
message.send(fail_silently=False)
if sys.version_info[0] < 3:
encoded_content = "UERGLUZpbGUtQ29udGVudHM="
else:
encoded_content = "UERGLUZpbGUtQ29udGVudHM=\n"
encoded_content = "UERGLUZpbGUtQ29udGVudHM=\n"
assert postmark_request.call_args[1]["json"][0] == {
"Attachments": [
{
Expand All @@ -211,12 +204,8 @@ def test_text_html_alternative_and_pdf_attachment_failure(postmark_request, mess


def test_message_rfc822(postmark_request, message):
if sys.version_info[:2] == (3, 2):
message_content = b"Fake message"
expected_content = "RmFrZSBtZXNzYWdl\n"
else:
message_content = "Fake message"
expected_content = "RmFrZSBtZXNzYWdl"
message_content = "Fake message"
expected_content = "RmFrZSBtZXNzYWdl"
message.attach_alternative(message_content, "message/rfc822")
message.send(fail_silently=False)
assert postmark_request.call_args[1]["json"][0] == {
Expand Down
16 changes: 5 additions & 11 deletions test/models/test_emails.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import sys
from email import encoders
from email.mime.base import MIMEBase
from email.mime.image import MIMEImage
Expand All @@ -19,12 +18,12 @@ def get_attachment_path(filename):

ATTACHMENT = {
"Name": "readme.txt",
"Content": "dGVzdCBjb250ZW50",
"Content": "dGVzdCBjb250ZW50Cg==",
"ContentType": "text/plain",
}
TUPLE_ATTACHMENT = ATTACHMENT["Name"], ATTACHMENT["Content"], ATTACHMENT["ContentType"]
MIME_ATTACHMENT = MIMEBase("text", "plain")
MIME_ATTACHMENT.set_payload("dGVzdCBjb250ZW50")
MIME_ATTACHMENT.set_payload("dGVzdCBjb250ZW50Cg==")
MIME_ATTACHMENT.add_header("Content-Disposition", "attachment", filename="readme.txt")
PATH_ATTACHMENT = get_attachment_path("readme.txt")

Expand Down Expand Up @@ -63,12 +62,7 @@ def get_mime_message(text, html_text=None, **kwargs):

MIME_MESSAGE = get_mime_message("Text", **DEFAULT_HEADERS)
MIME_ALTERNATIVE = get_mime_message("Text", "HTML content", **DEFAULT_HEADERS)

if sys.version_info[0] < 3:
ENCODED_CONTENT = "dGVzdCBjb250ZW50"
else:
ENCODED_CONTENT = "dGVzdCBjb250ZW50\n"

ENCODED_CONTENT = "dGVzdCBjb250ZW50\n"

IMAGE = MIMEImage(b"test content", "png", name="image1.png")
IMAGE.add_header("Content-ID", "<[email protected]>")
Expand Down Expand Up @@ -280,13 +274,13 @@ def test_attach_unknown_content_type(self, email, postmark_request):
assert postmark_request.call_args[1]["json"]["Attachments"] == [
{
"Name": "report.blabla",
"Content": "dGVzdCBjb250ZW50",
"Content": "dGVzdCBjb250ZW50Cg==",
"ContentType": "application/octet-stream",
}
]

def test_attach_binary(self, email, postmark_request):
email.attach_binary(b"test content", "readme.txt")
email.attach_binary(b"test content\n", "readme.txt")
email.send()
assert postmark_request.call_args[1]["json"]["Attachments"] == [ATTACHMENT]

Expand Down
16 changes: 0 additions & 16 deletions test/test_pytest.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
import sys

import pytest

from postmarker.core import PostmarkClient


def test_postmark_client(postmark_client, postmark_request):
assert isinstance(postmark_client, PostmarkClient)
assert postmark_client.mock is postmark_request


@pytest.mark.skipif(sys.version_info[0] == 3, reason="Mock is required only for Python 2")
def test_mock_not_installed():
sys.modules["mock"] = None
del sys.modules["postmarker._compat"]
del sys.modules["postmarker.pytest"]

from postmarker.pytest import postmark_request

with pytest.raises(AssertionError, matches="To use pytest fixtures on Python 2.*"):
list(postmark_request())
19 changes: 14 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
envlist = py{35,36,37,py3}
skipsdist = True
isolated_build = true
envlist = py{35,36,37,py3},coverage-report

[testenv]
passenv =
Expand All @@ -18,10 +18,8 @@ deps =
py35: Django>=1.10.0,<1.11.0
py36: Django>=1.11.0,<2.0.0
py37: Django>=2.1.0,<2.2.0
usedevelop = True
commands =
coverage run --source postmarker -m pytest --ds tests.django.settings {posargs:test}
coverage xml
coverage run --source postmarker -m pytest --ds test.django.settings {posargs:test}

[testenv:record]
deps =
Expand All @@ -31,3 +29,14 @@ deps =
betamax_serializers
Django
commands = pytest --record {posargs:test}

[testenv:coverage-report]
description = Report coverage over all measured test runs.
basepython = python3.7
deps = coverage
skip_install = true
depends = py{35,36,37}
commands =
coverage combine
coverage report
coverage xml -i {posargs:}

0 comments on commit 5bf9865

Please sign in to comment.