Skip to content

Commit b5c8895

Browse files
committed
add APP_VERSION support
1 parent b5fa47e commit b5c8895

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

intbot/core/bot/main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ async def on_ready():
1818
async def ping(ctx):
1919
await ctx.send("Pong!")
2020

21+
@bot.command()
22+
async def version(ctx):
23+
app_version = settings.APP_VERSION
24+
await ctx.send(f"Version: {app_version}")
25+
2126

2227
def run_bot():
2328
bot_token = settings.DISCORD_BOT_TOKEN

intbot/core/endpoints/basic.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
from django.http.response import JsonResponse
2+
from django.conf import settings
23

34

45
def index(request):
5-
return JsonResponse({"hello": "world"})
6+
return JsonResponse(
7+
{
8+
"hello": "world",
9+
"v": settings.APP_VERSION,
10+
}
11+
)

intbot/intbot/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
109109

110110
DJANGO_ENV = os.environ["DJANGO_ENV"]
111+
APP_VERSION = os.environ.get("APP_VERSION", "latest")[:8]
111112

112113
if DJANGO_ENV == "dev":
113114
DEBUG = True

intbot/tests/test_basic.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"""
1212

1313
from django.contrib.auth.models import User
14+
from django.conf import settings
1415
import pytest
1516

1617

@@ -28,3 +29,4 @@ def test_http_sanity_check(client):
2829
assert response.status_code == 200
2930
assert response["Content-Type"] == "application/json"
3031
assert response.json()["hello"] == "world"
32+
assert response.json()["v"] == settings.APP_VERSION

intbot/tests/test_bot.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from unittest.mock import AsyncMock
22

33
import pytest
4-
from core.bot.main import ping
4+
from core.bot.main import ping, version
55

66

77
@pytest.mark.asyncio
@@ -14,3 +14,15 @@ async def test_ping_command():
1414

1515
# Assert that the command sent the expected message
1616
ctx.send.assert_called_once_with("Pong!")
17+
18+
19+
@pytest.mark.asyncio
20+
async def test_version_command():
21+
# Mock context
22+
ctx = AsyncMock()
23+
24+
# Call the command
25+
await version(ctx)
26+
27+
# Assert that the command sent the expected message
28+
ctx.send.assert_called_once_with("Version: latest")

0 commit comments

Comments
 (0)