Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Rivixer committed Jan 6, 2024
2 parents 58193c8 + 12c9af1 commit 468637e
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 19 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: SGGWBot tests

on:
push:
branches: [ "main", "develop" ]
pull_request:
branches: [ "main", "develop" ]

permissions:
contents: read

jobs:
linux_build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: "3.10"
cache: 'pip'
- run: pip install -r requirements.txt
- run: pytest
2 changes: 1 addition & 1 deletion sggwbot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
__author__ = "Wiktor Jaworski"
__license__ = "MIT"
__copyright__ = "Copyright 2023 Wiktor Jaworski"
__version__ = "0.7.8"
__version__ = "0.7.10"

from . import console, errors, utils
from .sggw_bot import SGGWBot
2 changes: 1 addition & 1 deletion sggwbot/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ExceptionData:
@nextcord.slash_command(name="divide", description="Divide two numbers.")
@InteractionUtils.with_info(catch_errors=[
ErrorData(ZeroDivisionError, with_traceback_in_reply=False)
ExceptionData(ZeroDivisionError, with_traceback_in_reply=False)
])
async def _divide(self, interaction, a, b) -> None:
await interaction.response.send_message(f"{a} / {b} = {a / b}")
Expand Down
5 changes: 3 additions & 2 deletions sggwbot/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,11 +676,12 @@ def check_if_blocked(self, index: str) -> str | None:

def add_mail_sent_time(self, index: str) -> None:
"""Adds the time to logs when the email was sent."""
dt_now = dt.datetime.now().replace(microsecond=0)
for log in self.mail_logs:
if log.provided_index == index:
log.mails_sent_time.append(dt.datetime.now())
log.mails_sent_time.append(dt_now)
return
self.mail_logs.append(MailLog(index, [dt.datetime.now()]))
self.mail_logs.append(MailLog(index, [dt_now]))

def to_dict(self) -> dict[str, Any]:
"""Returns a dictionary representation of the object."""
Expand Down
2 changes: 1 addition & 1 deletion sggwbot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,6 @@ async def foo():

time_until_midnight = midnight - today
await asyncio.sleep(
time_until_midnight.seconds + time_until_midnight.microseconds / 1000
time_until_midnight.seconds + time_until_midnight.microseconds / 1_000_000
)
return True
24 changes: 10 additions & 14 deletions tests/test_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,8 @@
from nextcord.embeds import Embed
from pytest import MonkeyPatch

from sggwbot.registration import (
CodeController,
CodeModel,
MailLog,
MemberData,
MemberInfo,
RegistrationModel,
)
from sggwbot.registration import (CodeController, CodeModel, MailLog,
MemberData, MemberInfo, RegistrationModel)

from .mocks import *

Expand Down Expand Up @@ -217,22 +211,24 @@ def test_code_model_check_if_blocked() -> None:


def test_code_model_add_mail_sent_time() -> None:
model = CodeModel("xxxxxx", dt.datetime.now(), [])
dt_now = dt.datetime.now().replace(microsecond=0)
model = CodeModel("xxxxxx", dt_now, [])
model.add_mail_sent_time("123456")
assert model.mail_logs == [MailLog("123456", [dt.datetime.now()])]
assert model.mail_logs == [MailLog("123456", [dt_now])]

model.add_mail_sent_time("123456")
assert model.mail_logs == [
MailLog("123456", [dt.datetime.now(), dt.datetime.now()])
MailLog("123456", [dt_now, dt_now])
]


def test_code_model_to_dict() -> None:
log1 = MailLog("123456", [dt.datetime.now()])
model = CodeModel("xxxxxx", dt.datetime.now(), [log1])
dt_now = dt.datetime.now().replace(microsecond=0)
log1 = MailLog("123456", [dt_now])
model = CodeModel("xxxxxx", dt_now, [log1])
assert model.to_dict() == {
"code": "xxxxxx",
"generation_time": dt.datetime.now().timestamp(),
"generation_time": dt_now.timestamp(),
"mail_logs": [log1.to_dict()],
}

Expand Down

0 comments on commit 468637e

Please sign in to comment.