Skip to content

Commit

Permalink
Update tests structure, Add Github Actions for running tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mjnaderi committed Nov 18, 2020
1 parent 1e3b331 commit 0dbed15
Show file tree
Hide file tree
Showing 15 changed files with 109 additions and 97 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/test.yml
@@ -0,0 +1,69 @@
name: Tests

on:
push:
branches: [ $default-branch ]
pull_request:
branches: [ $default-branch ]
workflow_dispatch:
inputs: {}

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
env: [pytracking]
include:
- python-version: 3.6
env: django-dj111
- python-version: 3.7
env: django-dj111
- python-version: 3.6
env: django-dj20
- python-version: 3.7
env: django-dj20
- python-version: 3.6
env: django-dj21
- python-version: 3.7
env: django-dj21
- python-version: 3.6
env: django-dj22
- python-version: 3.7
env: django-dj22
- python-version: 3.8
env: django-dj22
- python-version: 3.9
env: django-dj22
- python-version: 3.6
env: django-dj30
- python-version: 3.7
env: django-dj30
- python-version: 3.8
env: django-dj30
- python-version: 3.9
env: django-dj30
- python-version: 3.6
env: django-dj31
- python-version: 3.7
env: django-dj31
- python-version: 3.8
env: django-dj31
- python-version: 3.9
env: django-dj31
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox
- name: Test with tox and pyenv
env:
TOXENV: ${{ matrix.env }}
run: |
tox
7 changes: 7 additions & 0 deletions CHANGELOG.rst
@@ -1,6 +1,13 @@
Changelog - pytracking
======================

0.2.2 - November 17th 2020
--------------------------

- Updated django-ipware to >=2.0.
- Updated tests structure and added Github Actions for running tests
- Updated supported Python versions to 3.6, 3.7, 3.8, 3.9

0.2.1 - October 28th 2020
-------------------------

Expand Down
5 changes: 0 additions & 5 deletions requirements-all.txt

This file was deleted.

1 change: 0 additions & 1 deletion requirements-crypto.txt

This file was deleted.

2 changes: 0 additions & 2 deletions requirements-django.txt

This file was deleted.

1 change: 0 additions & 1 deletion requirements-html.txt

This file was deleted.

1 change: 0 additions & 1 deletion requirements-test.txt

This file was deleted.

1 change: 0 additions & 1 deletion requirements-webhook.txt

This file was deleted.

Empty file added tests/__init__.py
Empty file.
12 changes: 1 addition & 11 deletions test_crypto.py → tests/test_crypto.py
@@ -1,22 +1,12 @@
import copy

import pytest

from pytracking import (
Configuration, get_click_tracking_url, get_click_tracking_url_path,
get_open_tracking_url_path,
get_click_tracking_result, get_open_tracking_url,
get_open_tracking_result)


try:
from cryptography.fernet import Fernet
support_crypto = True
except ImportError:
support_crypto = False

pytestmark = pytest.mark.skipif(
not support_crypto, reason="Cryptography lib not installed")
from cryptography.fernet import Fernet

DEFAULT_URL_TO_TRACK = "https://www.bob.com/hello-world/?token=valueééé"

Expand Down
26 changes: 8 additions & 18 deletions test_django.py → tests/test_django.py
Expand Up @@ -3,31 +3,21 @@
from pytracking import (
get_open_tracking_url, get_click_tracking_url, get_open_tracking_url_path,
get_click_tracking_url_path, TRACKING_PIXEL, PNG_MIME_TYPE)
from test_pytracking import (
from .test_pytracking import (
DEFAULT_BASE_OPEN_TRACKING_URL, DEFAULT_BASE_CLICK_TRACKING_URL,
DEFAULT_METADATA, DEFAULT_WEBHOOK_URL, DEFAULT_DEFAULT_METADATA,
DEFAULT_URL_TO_TRACK, EXPECTED_METADATA)

DEFAULT_ENCODED_URL_TO_TRACK =\
"https://www.bob.com/hello-world/?token=value%C3%A9%C3%A9%C3%A9"

try:
import ipware # noqa

# Must call configure before importing tracking_django
from django.conf import settings
from django.http import Http404
settings.configure()
# Must call configure before importing tracking_django
from django.conf import settings
from django.http import Http404
settings.configure()

import pytracking.django as tracking_django
import pytracking.django as tracking_django

support_django = True
except ImportError:
support_django = False


pytestmark = pytest.mark.skipif(
not support_django, reason="Django-support lib not installed")
DEFAULT_ENCODED_URL_TO_TRACK =\
"https://www.bob.com/hello-world/?token=value%C3%A9%C3%A9%C3%A9"

DEFAULT_SETTINGS = {
"webhook_url": DEFAULT_WEBHOOK_URL,
Expand Down
20 changes: 4 additions & 16 deletions test_html.py → tests/test_html.py
@@ -1,14 +1,15 @@
import pytest

from pytracking import (
get_click_tracking_url_path, get_open_tracking_url_path,
get_open_tracking_result, get_click_tracking_result)

from test_pytracking import (
from .test_pytracking import (
DEFAULT_BASE_OPEN_TRACKING_URL, DEFAULT_BASE_CLICK_TRACKING_URL,
DEFAULT_METADATA, DEFAULT_WEBHOOK_URL, DEFAULT_DEFAULT_METADATA,
EXPECTED_METADATA)

from lxml import html
import pytracking.html as tracking_html

TEST_HTML_EMAIL = """
<!DOCTYPE html>
<html>
Expand Down Expand Up @@ -41,19 +42,6 @@
"default_metadata": DEFAULT_DEFAULT_METADATA
}

try:
from lxml import html # noqa

import pytracking.html as tracking_html

support_html = True
except ImportError:
support_html = False


pytestmark = pytest.mark.skipif(
not support_html, reason="HTML-support lib not installed")


def test_adapt_html_full():
new_html = tracking_html.adapt_html(
Expand Down
File renamed without changes.
15 changes: 2 additions & 13 deletions test_webhook.py → tests/test_webhook.py
@@ -1,26 +1,15 @@
from unittest.mock import patch

import pytest

from pytracking import (
get_click_tracking_url, get_click_tracking_url_path,
get_click_tracking_result, get_open_tracking_url,
get_open_tracking_result, get_open_tracking_url_path,
DEFAULT_TIMEOUT_SECONDS)
from test_pytracking import (
from .test_pytracking import (
DEFAULT_URL_TO_TRACK, DEFAULT_BASE_CLICK_TRACKING_URL, DEFAULT_WEBHOOK_URL,
DEFAULT_METADATA, DEFAULT_BASE_OPEN_TRACKING_URL)

try:
import requests # noqa
import pytracking.webhook
support_requests = True
except ImportError:
support_requests = False


pytestmark = pytest.mark.skipif(
not support_requests, reason="Requests lib not installed")
import pytracking.webhook


def test_send_webhook_click():
Expand Down
46 changes: 18 additions & 28 deletions tox.ini
@@ -1,31 +1,21 @@
[tox]
envlist = py36-vanilla,py36-crypto,py36-django,py36-webhook,py36-html
envlist =
py{36,37,38,39}-{pytracking},
py{36,37}-django-dj{111,20,21},
py{36,37,38,39}-django-dj{22,30,31}

[testenv]
deps =
-rrequirements-test.txt
commands = py.test

[testenv:py36-crypto]
deps =
-rrequirements-test.txt
-rrequirements-crypto.txt
commands = py.test

[testenv:py36-django]
deps =
-rrequirements-test.txt
-rrequirements-django.txt
commands = py.test

[testenv:py36-webhook]
deps =
-rrequirements-test.txt
-rrequirements-webhook.txt
commands = py.test

[testenv:py36-html]
deps =
-rrequirements-test.txt
-rrequirements-html.txt
commands = py.test
extras =
test
pytracking: crypto,html,webhook
django: django
commands =
pytracking: py.test --ignore tests/test_django.py
django: py.test tests/test_django.py
deps=
dj111: Django>=1.11,<2.0
dj20: Django>=2.0,<2.1
dj21: Django>=2.1,<2.2
dj22: Django>=2.2,<2.3
dj30: Django>=3.0,<3.1
dj31: Django>=3.1,<3.2

0 comments on commit 0dbed15

Please sign in to comment.