Skip to content

Commit

Permalink
Merge pull request #47 from juntossomosmais/feat/update-packages-sept…
Browse files Browse the repository at this point in the history
…ember

feat(packages): update packages
  • Loading branch information
MatheusGeiger authored Sep 9, 2024
2 parents 15113a0 + 118612e commit e0bcbfc
Show file tree
Hide file tree
Showing 23 changed files with 150 additions and 50 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# https://docs.docker.com/engine/reference/builder/#dockerignore-file
*
!django_outbox_pattern
!scripts
!pyproject.toml
!poetry.lock
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.github @juntossomosmais/core
* @juntossomosmais/loyalty-backends
* @juntossomosmais/loja-virtual-backends
22 changes: 22 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: 2
updates:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
time: "08:00"
day: "sunday"
target-branch: "main"
reviewers:
- "juntossomosmais/loyalty"
- "juntossomosmais/loja-virtual"
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "monthly"
time: "08:00"
day: "sunday"
target-branch: "main"
reviewers:
- "juntossomosmais/loyalty"
- "juntossomosmais/loja-virtual"
24 changes: 24 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Infos

## [Task name on sprint board](https://juntossomosmais.monday.com/boards/)

### What is being delivered?

- Describe here all the changes that will be made and what the expected result is.

### What impacts?

- Describe what impacts this delivery has and whether it can cause side effects in other parts of the application.

### Reversal plan

- Describe which plan we should follow if this delivery has to be reversed.
Ex.: Revert applied migrations, revert commits, redeploy the application via Azure DevOps

### Where to monitor

- Describe how this delivery can be monitored and how to analyze the data to ensure it works.

- Ex.: [Specific Kibana query name]()

<br>
30 changes: 24 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,26 @@ repos:
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/pycqa/pylint
rev: v3.2.6
hooks:
- id: pylint
additional_dependencies: [ django, 'stomp.py' ]
exclude: migrations
- repo: https://github.com/pycqa/flake8
rev: 7.1.1
hooks:
- id: flake8
additional_dependencies: [
'flake8-bugbear',
'flake8-comprehensions',
'flake8-debugger',
]
- repo: https://github.com/pycqa/autoflake
rev: v2.3.1
hooks:
- id: autoflake
args:
[
"--in-place",
"--remove-all-unused-imports",
"--recursive",
"--ignore-init-module-imports",
]
- repo: https://github.com/psf/black
rev: 24.8.0
hooks:
Expand All @@ -27,3 +37,11 @@ repos:
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
hooks:
- id: mypy
additional_dependencies:
["types-all", "types-pkg-resources==0.1.3"]
pass_filenames: false
args: ['.']
2 changes: 1 addition & 1 deletion django_outbox_pattern/bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class Base:
def __init__(self, connection, username, passcode):
self._credentials = dict(username=username, passcode=passcode) # pylint: disable=R1735
self._credentials = {"username": username, "passcode": passcode}
self.attempts = 0
self.connection = connection

Expand Down
5 changes: 2 additions & 3 deletions django_outbox_pattern/consumers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# pylint: disable=R0902
import json
import logging

from datetime import timedelta

from django import db
Expand Down Expand Up @@ -68,7 +68,7 @@ def message_handler(self, body, headers):
message_id,
)

except BaseException: # pylint: disable=broad-exception-caught
except Exception:
logger.exception("An exception has been caught during callback processing flow")
payload.nack()

Expand Down Expand Up @@ -107,7 +107,6 @@ def _create_queue(self, destination, headers, queue_name=None):
self._subscribe(destination, self.subscribe_id, headers, queue_name)

def _subscribe(self, destination, subscribe_id, headers, queue_name=None, dlq=False):
# pylint: disable=too-many-arguments
routing_key = destination.split("/")[-1]
queue_name = queue_name if queue_name else routing_key
if dlq:
Expand Down
1 change: 1 addition & 0 deletions django_outbox_pattern/decorators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json

from typing import List
from typing import NamedTuple
from typing import Optional
Expand Down
2 changes: 1 addition & 1 deletion django_outbox_pattern/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ExceededSendAttemptsException(Exception):
"""Raised when the limit of attempts to send messages to the broker is exceeded"""

def __init__(self, attempts): # pylint: disable=super-init-not-called
def __init__(self, attempts):
self.attempts = attempts
1 change: 1 addition & 0 deletions django_outbox_pattern/management/commands/publish.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import sys

from datetime import timedelta
from time import sleep

Expand Down
1 change: 1 addition & 0 deletions django_outbox_pattern/management/commands/subscribe.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys

from time import sleep

from django.core.management.base import BaseCommand
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by Django 4.2.14 on 2024-07-15 16:14

import django.contrib.postgres.indexes

from django.contrib.postgres.operations import AddIndexConcurrently
from django.db import migrations

Expand Down
1 change: 1 addition & 0 deletions django_outbox_pattern/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import uuid

from datetime import timedelta

from django.contrib.postgres.indexes import BTreeIndex
Expand Down
1 change: 1 addition & 0 deletions django_outbox_pattern/producers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import logging

from datetime import timedelta
from time import sleep

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ services:
build: .
volumes:
- .:/app
command: [ "./scripts/start-formatter-lint.sh" ]
command: ["./scripts/start-formatter-lint.sh"]
networks:
- djangooutboxpattern

Expand Down
11 changes: 7 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 43 additions & 23 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "django-outbox-pattern"
version = "2.0.0"
version = "2.1.0"
description = "A django application to make it easier to use the transactional outbox pattern"
license = "MIT"
authors = ["Hugo Brilhante <[email protected]>"]
Expand Down Expand Up @@ -36,7 +36,7 @@ django = ">=5.0.8"
[tool.poetry.group.dev.dependencies]
psycopg2-binary = "^2.9.6"
coverage = "*"
pre-commit = "*"
pre-commit = "^3.8.0"

[tool.black]
line-length = 120
Expand All @@ -59,33 +59,53 @@ exclude = '''
)
'''
[tool.isort]
multi_line_output = 3
include_trailing_comma = 'True'
force_grid_wrap = 0
force_single_line = true
use_parentheses = 'True'
ensure_newline_before_comments = 'True'
line_length = 120
py_version = 312
use_parentheses = true
multi_line_output = 3
include_trailing_comma = true
lines_between_types = 1
sections = ["FUTURE", "STDLIB", "DJANGO", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"]

[tool.pylint.master]
ignore = []
[tool.mypy]
python_version = "3.10"

[tool.pylint.messages_control]
disable = [
"no-member",
"missing-class-docstring",
"missing-function-docstring",
"missing-module-docstring",
"too-few-public-methods",
"logging-not-lazy",
"consider-using-f-string",
"logging-fstring-interpolation",
"too-many-ancestors"
]
# flake8-mypy expects the two following for sensible formatting
show_column_numbers = true
show_error_context = false

# do not follow imports (except for ones found in typeshed)
follow_imports = "skip"

# suppress errors about unsatisfied imports
ignore_missing_imports = true

# allow untyped calls as a consequence of the options above
disallow_untyped_calls = false

# allow returning Any as a consequence of the options above
warn_return_any = false

# treat Optional per PEP 484
strict_optional = true

# ensure all execution paths are returning
warn_no_return = true

# lint-style cleanliness for typing needs to be disabled; returns more errors
# than the full run.
warn_redundant_casts = false
warn_unused_ignores = false

[tool.pylint.format]
max-line-length = "120"
# The following are off by default since they're too noisy.
# Flip them on if you feel adventurous.
disallow_untyped_defs = false
check_untyped_defs = false

[[tool.mypy.overrides]]
module = "*.migrations.*"
ignore_errors = true

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
2 changes: 1 addition & 1 deletion scripts/start-formatter-lint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash

set -e
git config --global --add safe.directory /app
pre-commit run --all-files
8 changes: 4 additions & 4 deletions tests/integration/test_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


def get_callback(raise_except=False):
def callback(payload): # pylint: disable=unused-argument
def callback(payload):
if raise_except:
raise KeyError("Test exception")
payload.save()
Expand Down Expand Up @@ -113,10 +113,10 @@ def test_consumer_message_should_remove_old_messages(self):

def test_consumer_should_not_remove_old_message_when_cache_exists(self):
self._create_message_in_the_past(35, 1)
self.consumer._remove_old_messages() # pylint: disable=W0212
self.consumer._remove_old_messages()
self.assertFalse(self.consumer.received_class.objects.filter(msg_id=1).exists())
self._create_message_in_the_past(35, 2)
self.consumer._remove_old_messages() # pylint: disable=W0212
self.consumer._remove_old_messages()
self.assertTrue(self.consumer.received_class.objects.filter(msg_id=2).exists())

def _create_message_in_the_past(self, day_ago, msg_id):
Expand All @@ -133,7 +133,7 @@ def test_consumer_should_consume_message_event_if_a_exception_happen_in_cache(se
destination = "/topic/consumer.v5"
callback = get_callback()
self.consumer.start(callback, destination)
with self.assertRaises(Exception):
with self.assertRaises(Exception): # noqa
self.consumer.connection.send(destination=destination, body='{"message": "Message test no raise"}')
sleep(1)
self.listener.get_latest_message()
Expand Down
7 changes: 4 additions & 3 deletions tests/integration/test_producer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json

from datetime import datetime
from datetime import timedelta
from unittest import mock
Expand Down Expand Up @@ -112,10 +113,10 @@ def test_producer_should_remove_old_messages(self):
def test_consumer_should_not_remove_old_message_when_cache_exists(self):
message = self._create_message_in_the_past(31)
producer = factory_producer()
producer._remove_old_messages() # pylint: disable=W0212
producer._remove_old_messages()
self.assertFalse(Published.objects.filter(id=message.id).exists())
message1 = self._create_message_in_the_past(31)
producer._remove_old_messages() # pylint: disable=W0212
producer._remove_old_messages()
self.assertTrue(Published.objects.filter(id=message1.id).exists())

@mock.patch("django_outbox_pattern.producers.cache")
Expand All @@ -125,7 +126,7 @@ def test_producer_should_send_message_event_if_a_exception_happen_in_cache(self,
producer.set_listener("test_listener", TestListener(print_to_log=True))
producer.connection.subscribe(destination=self.fake_destination, id=1)
listener = producer.get_listener("test_listener")
with self.assertRaises(Exception):
with self.assertRaisesRegex(Exception, "Cache get failed"):
producer.send_event(destination=self.fake_destination, body={"message": "fake message body"})

listener.wait_for_message()
Expand Down
1 change: 0 additions & 1 deletion tests/integration/test_publish_command.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# pylint: disable=R0801
from io import StringIO
from unittest.mock import MagicMock
from unittest.mock import PropertyMock
Expand Down
Loading

0 comments on commit e0bcbfc

Please sign in to comment.