Skip to content

Commit

Permalink
Merge pull request #34 from akretion/ci
Browse files Browse the repository at this point in the history
add CI and image push
  • Loading branch information
rvalyi authored Jul 5, 2024
2 parents fcd4f81 + 7609347 commit 60657a1
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Build

on:
push:
branches:
- master
pull_request:
schedule:
- cron: "0 4 * * 0"

jobs:
build-boleto-cnab-api:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to ghcr.io
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
cache-from: type=registry,ref=ghcr.io/build-boleto-cnab-api-latest
cache-to: type=local,dest=/tmp/.buildx-cache
load: true
- name: Install test pre-requisites
run: pip install pytest
- name: Test
run: pytest -v
- name: Push image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=inline
push: true
if: ${{ github.repository_owner == 'akretion' && github.ref == 'refs/heads/master' }}
71 changes: 71 additions & 0 deletions test_run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import json
import tempfile
from pathlib import Path
import os
import subprocess
import requests
import time


def test_run():
cmd = ["docker", "build", "-t", "akretion/boleto_cnab_api", "."]
result = subprocess.run(
cmd, check=False, capture_output=True, text=True, cwd=Path(__file__).parent
)
assert result.returncode == 0, result.stderr + "\n" + result.stdout

cmd = [
"docker",
"run",
"-d",
"-p",
"9292:9292",
"--name=boleto_cnab_api",
"akretion/boleto_cnab_api",
]
result = subprocess.run(cmd, check=False, capture_output=True, text=True)
assert result.returncode == 0, result.stderr + "\n" + result.stdout
time.sleep(5)
remessa_values = [
{
"valor": 5.0,
"cedente": "Kivanio Barbosa",
"documento_cedente": "12345678912",
"sacado": "Claudio Pozzebom",
"sacado_documento": "12345678900",
"agencia": "0810",
"conta_corrente": "53678",
"convenio": 12387,
"nosso_numero": "12345678",
"bank": "itau",
},
{
"valor": 10.00,
"cedente": "PREFEITURA MUNICIPAL DE VILHENA",
"documento_cedente": "04092706000181",
"sacado": "João Paulo Barbosa",
"sacado_documento": "77777777777",
"agencia": "1825",
"conta_corrente": "0000528",
"convenio": "245274",
"nosso_numero": "000000000000001",
"bank": "caixa",
},
]
content = json.dumps(remessa_values)
with open(tempfile.mktemp(), "w") as f:
file_name = f.name
f.write(content)
files = {"data": open(file_name, "rb")}
result = requests.post(
"http://localhost:9292/api/boleto/multi",
data={
"type": "pdf",
},
files=files,
)
assert str(result.status_code)[0] == "2"

cmd = ["docker", "rm", "-f", "boleto_cnab_api"]
result = subprocess.run(cmd, check=False, capture_output=True, text=True)
assert result.returncode == 0, result.stderr + "\n" + result.stdout

0 comments on commit 60657a1

Please sign in to comment.