Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mariofix committed Dec 13, 2024
1 parent e508e6b commit 26b9e62
Show file tree
Hide file tree
Showing 25 changed files with 388 additions and 73 deletions.
42 changes: 30 additions & 12 deletions .github/workflows/tests_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,49 @@ on:
branches: ["main"]

jobs:
tests:
build:
name: build (Python ${{ matrix.python-version }}, Django ${{ matrix.django-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 5
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
poetry-version: ["2.0.0.dev0"]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
django-version: ["4.2", "5.0", "5.1", "main"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Set Up Poetry
uses: abatilo/actions-poetry@v3

- name: Get pip cache dir
id: pip-cache
run: |
echo "::set-output name=dir::$(pip cache dir)"
- name: Cache
uses: actions/cache@v4
with:
poetry-version: ${{ matrix.poetry-version }}
- name: Install django-payments-chile
run: poetry install --with dev
- name: Test
run: poetry run tox
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ matrix.python-version }}-v1-${{ hashFiles('**/setup.py') }}-${{ hashFiles('**/tox.ini') }}
restore-keys: |
${{ matrix.python-version }}-v1-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade tox tox-gh-actions
- name: Tox tests
run: |
tox -v
env:
DJANGO: ${{ matrix.django-version }}

- name: Coverage report (xml)
run: poetry run coverage xml
run: coverage xml
- name: Run codacy-coverage-reporter
uses: codacy/codacy-coverage-reporter-action@v1
with:
Expand Down
35 changes: 0 additions & 35 deletions ejemplo/README.md

This file was deleted.

16 changes: 0 additions & 16 deletions ejemplo/pyproject.toml

This file was deleted.

28 changes: 21 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ classifiers = [
"Operating System :: OS Independent",
]

dependencies = ["django-payments>=2.0, <4.0", "requests"]
dependencies = ["django-payments>=2.0, <4.0", "requests", "pyflowcl"]

[project.urls]
Homepage = "https://mariofix.github.io/django-payments-chile/"
Expand Down Expand Up @@ -78,11 +78,7 @@ dev = [


[tool.setuptools.packages.find]
include = ["django_payments_chile", "tests", "ejemplo"]

[tool.pytest.ini_options]
DJANGO_SETTINGS_MODULE = "tests.django_settings"
addopts = "--cov=django_payments_chile/ --cov-branch --cov-report=term-missing --cov-report=xml"
include = ["django_payments_chile", "tests"]

[tool.black]
line-length = 119
Expand All @@ -93,4 +89,22 @@ profile = "black"
line_length = 119
multi_line_output = 5
py_version = 39
src_paths = ["django_payments_chile", "tests", "ejemplo"]
src_paths = ["django_payments_chile", "tests"]


[tool.coverage.report]
exclude_lines = ["if TYPE_CHECKING:"]

[tool.django-stubs]
django_settings_module = "tests.django_settings"

[tool.pytest.ini_options]
addopts = [
"--cov=django_payments_chile",
"--cov-report=term-missing:skip-covered",
"--no-cov-on-fail",
"--color=yes",
]
testpaths = "tests"
DJANGO_SETTINGS_MODULE = "tests.django_settings"
pythonpath = "."
14 changes: 14 additions & 0 deletions tests/django_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os

PROJECT_ROOT = os.path.normpath(os.path.join(os.path.dirname(__file__), "tienda_pruebas"))
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(PROJECT_ROOT, "templates")],
}
]
USE_TZ = True
SECRET_KEY = "NOTREALLY"
PAYMENT_HOST = "example.com"

INSTALLED_APPS = ["payments", "django.contrib.sites"]
60 changes: 57 additions & 3 deletions tests/test_flowprovider.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,59 @@
from django_payments_chile.FlowProvider import FlowProvider
from unittest import TestCase
from unittest.mock import Mock
from unittest.mock import patch

from payments import PaymentStatus
from payments import RedirectNeeded

def test_provider_components():
assert FlowProvider == "2024.9.30"
from django_payments_chile import FlowProvider

API_KEY = "flow_test_key"
API_SECRET = "flow_test_secret"


class payment_attrs:
session = dict


class Payment(Mock):
id = 1
description = "payment"
currency = "CLP"
delivery = 0
status = PaymentStatus.WAITING
message = None
tax = 0
total = 5000
captured_amount = 0
transaction_id = None
billing_email = "correo@usuario.com"
attrs = payment_attrs()

def change_status(self, status, message=""):
self.status = status
self.message = message

def get_failure_url(self):
return "http://mi-app.cl/error"

def get_process_url(self):
return "http://mi-app.cl/process"

def get_purchased_items(self):
return []

def get_success_url(self):
return "http://mi-app.cl/exito"


class TestStripeProviderV3(TestCase):
def test_provider_create_session_success(self):
payment = Payment()
provider = FlowProvider(api_key=API_KEY, api_secret=API_SECRET)
return_value = {"url": "https://flow.cl", "token": "TOKEN_ID", "flowOrder": "ORDER_ID"}
with patch("stripe.checkout.Session.create", return_value=return_value):
with self.assertRaises(RedirectNeeded):
provider.get_form(payment)
self.assertTrue("url" in payment.attrs.session)
self.assertTrue("token" in payment.attrs.session)
self.assertEqual(payment.status, PaymentStatus.WAITING)
1 change: 1 addition & 0 deletions tienda_pruebas/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10
File renamed without changes.
1 change: 1 addition & 0 deletions tienda_pruebas/django_payments_chile
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.
7 changes: 7 additions & 0 deletions tienda_pruebas/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[project]
name = "tienda-pruebas"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.10"
dependencies = ["django-payments>=2.0,<4.0"]
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 26b9e62

Please sign in to comment.