File tree Expand file tree Collapse file tree 7 files changed +53
-4
lines changed Expand file tree Collapse file tree 7 files changed +53
-4
lines changed Original file line number Diff line number Diff line change
1
+ .vimrc
2
+
1
3
# Byte-compiled / optimized / DLL files
2
4
__pycache__ /
3
5
* .py [cod ]
Original file line number Diff line number Diff line change 1
1
DEV_CMD =cd intbot && DJANGO_ENV="dev" uv run ./manage.py
2
+ TEST_CMD =cd intbot && DJANGO_SETTINGS_MODULE="intbot.settings" DJANGO_ENV="test" uv run pytest --nomigrations
2
3
3
4
4
5
help :
@@ -18,4 +19,4 @@ migrations:
18
19
$(DEV_CMD ) makemigrations -n $(N )
19
20
20
21
test :
21
- cd intbot && DJANGO_SETTINGS_MODULE= " intbot.settings " DJANGO_ENV= " test " uv run pytest
22
+ $( TEST_CMD ) -s -vv
Original file line number Diff line number Diff line change 1
- from django .http import JsonResponse
1
+ from django .http .response import JsonResponse
2
+
2
3
3
4
def index (request ):
4
5
return JsonResponse ({"hello" : "world" })
Original file line number Diff line number Diff line change
1
+ import json
2
+ from django .http .response import HttpResponseNotAllowed , JsonResponse
3
+ from django .views .decorators .csrf import csrf_exempt
4
+
5
+ from core .models import Webhook
6
+
7
+ @csrf_exempt
8
+ def internal_webhook_endpoint (request ):
9
+ if request .method == "POST" :
10
+ print (request .body )
11
+ wh = Webhook .objects .create (
12
+ source = "internal" ,
13
+ content = json .loads (request .body ),
14
+ )
15
+
16
+ return JsonResponse ({"status" : "created" , "guid" : wh .uuid })
17
+
18
+ return HttpResponseNotAllowed ("Only POST" )
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ class Webhook(models.Model):
14
14
15
15
# Extra information about the webhook, that might be provided in the
16
16
# headers or similar
17
- meta = models .JSONField ()
17
+ meta = models .JSONField (default = {} )
18
18
19
19
content = models .JSONField ()
20
20
Original file line number Diff line number Diff line change 1
1
from django .contrib import admin
2
2
from django .urls import path
3
3
4
- from core .views import index
4
+ from core .endpoints .basic import index
5
+ from core .endpoints .webhooks import internal_webhook_endpoint
5
6
6
7
urlpatterns = [
7
8
path ('admin/' , admin .site .urls ),
8
9
path ('' , index ),
10
+ # Internal Webhooks
11
+ path ('webhook/internal/' , internal_webhook_endpoint ),
9
12
]
Original file line number Diff line number Diff line change
1
+ import pytest
2
+ from core .models import Webhook
3
+
4
+
5
+ @pytest .mark .django_db
6
+ def test_database_sanity_check (client ):
7
+ webhook_body = {
8
+ "event" : "test1" ,
9
+ "content" : {
10
+ "random" : "content" ,
11
+ },
12
+ }
13
+
14
+ response = client .post (
15
+ "/webhook/internal/" ,
16
+ json = webhook_body ,
17
+ content_type = "application/json" ,
18
+ )
19
+
20
+ wh = Webhook .objects .get ()
21
+ assert response .status_code == 200
22
+ assert response ["Content-Type" ] == "application/json"
23
+ assert response .json ()["status" ] == "created"
24
+ assert response .json ()["guid" ] == str (wh .uuid )
You can’t perform that action at this time.
0 commit comments