-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from silentninja/develop
Django middleware Release v0.1.2
- Loading branch information
Showing
19 changed files
with
251 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Python package | ||
|
||
on: | ||
push: | ||
branches: [ 'main' ] | ||
paths-ignore: | ||
- .github/** | ||
- "**.md" | ||
- "Taskfile.yml" | ||
pull_request: | ||
branches: [ 'main' ] | ||
paths-ignore: | ||
- .github/** | ||
- "**.md" | ||
- "Taskfile.yml" | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [ 3.7, 3.8, 3.9 ] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Set up nodejs | ||
uses: actions/setup-node@v2 | ||
- name: Install Task | ||
run: curl -sL https://taskfile.dev/install.sh | sudo bash -s -- -b /usr/local/bin/ | ||
- name: Install dependencies | ||
run: | | ||
pip install tox tox-gh-actions | ||
- name: Install Optic | ||
run: yarn global add @useoptic/cli | ||
- run: task test-all |
2 changes: 1 addition & 1 deletion
2
frameworks/django/optic_django_middleware/optic_django_middleware/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.1.1" | ||
__version__ = "0.1.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
frameworks/django/optic_django_middleware/tests/fixtures/2.log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
[ | ||
{ | ||
"@timestamp": "2021-01-01T00:00:00", | ||
"url": { | ||
"full": "http://testserver/form-url", | ||
"query": "", | ||
"domain": "testserver", | ||
"path": "/form-url", | ||
"kind": "url" | ||
}, | ||
"useragent": { | ||
"original": "DjangoTestServer", | ||
"kind": "useragent" | ||
}, | ||
"http": { | ||
"response": { | ||
"body": { | ||
"content": "Created", | ||
"bytes": 7 | ||
}, | ||
"status_code": 200, | ||
"headers": { | ||
"Content-Type": "text/html; charset=utf-8" | ||
} | ||
}, | ||
"request": { | ||
"body": { | ||
"content": "{\"name\": [\"Boo\"], \"names\": [\"foo\", \"bar\"]}", | ||
"bytes": 42 | ||
}, | ||
"method": "POST", | ||
"headers": { | ||
"Cookie": "", | ||
"User-Agent": "DjangoTestServer", | ||
"Content-Length": "28", | ||
"Content-Type": "application/x-www-form-urlencoded" | ||
} | ||
} | ||
} | ||
} | ||
] |
41 changes: 41 additions & 0 deletions
41
frameworks/django/optic_django_middleware/tests/fixtures/3.log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
[ | ||
{ | ||
"@timestamp": "2021-01-01T00:00:00", | ||
"url": { | ||
"full": "http://testserver/json-url-3", | ||
"path": "/json-url-3", | ||
"domain": "testserver", | ||
"query": "", | ||
"kind": "url" | ||
}, | ||
"useragent": { | ||
"original": "DjangoTestServer", | ||
"kind": "useragent" | ||
}, | ||
"http": { | ||
"response": { | ||
"body": { | ||
"content": "{\"foo\": \"bar\"}", | ||
"bytes": 14 | ||
}, | ||
"status_code": 200, | ||
"headers": { | ||
"Content-Type": "application/json" | ||
} | ||
}, | ||
"request": { | ||
"body": { | ||
"content": "{\"name\": \"Boo\"}", | ||
"bytes": 15 | ||
}, | ||
"method": "PUT", | ||
"headers": { | ||
"Cookie": "", | ||
"User-Agent": "DjangoTestServer", | ||
"Content-Length": "15", | ||
"Content-Type": "application/json" | ||
} | ||
} | ||
} | ||
} | ||
] |
Empty file.
31 changes: 31 additions & 0 deletions
31
frameworks/django/optic_django_middleware/tests/middleware_test_app/views.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from django import forms | ||
from django.http import HttpResponse, JsonResponse | ||
|
||
|
||
def view1(request): | ||
return HttpResponse("view1") | ||
|
||
|
||
def view2(request): | ||
return HttpResponse("view2") | ||
|
||
|
||
def json_view(request): | ||
return JsonResponse({"foo": "bar"}) | ||
|
||
|
||
class NameForm(forms.Form): | ||
name = forms.CharField(label="Your name", max_length=100) | ||
names = forms.MultipleChoiceField(choices=(("foo", "Foo"), ("bar", "Bar"))) | ||
|
||
|
||
def form_view(request): | ||
if request.method == "POST": | ||
# create a form instance and populate it with data from the request: | ||
form = NameForm(request.POST) | ||
# check whether it's valid: | ||
if form.is_valid(): | ||
# process the data in form.cleaned_data as required | ||
# ... | ||
# redirect to a new URL: | ||
return HttpResponse("Created") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 39 additions & 5 deletions
44
frameworks/django/optic_django_middleware/tests/test_serializer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,52 @@ | ||
from django.test import RequestFactory, TestCase | ||
from django.utils.datastructures import MultiValueDict | ||
from django.utils.http import urlencode | ||
from fixtures import get_fixture | ||
from freezegun import freeze_time | ||
from middleware_test_app.views import form_view, json_view, view1 | ||
|
||
from optic_django_middleware.serializers import OpticEcsLogger | ||
from tests.views import view1 | ||
from .fixtures import get_fixture | ||
|
||
|
||
class HttpInteractionCountContainerTestCase(TestCase): | ||
|
||
@freeze_time("2021-01-01") | ||
def test_serialize_to_ecs(self): | ||
rf = RequestFactory(HTTP_USER_AGENT="DjangoTestServer") | ||
request = rf.get('/url-1/') | ||
request = rf.get("/url-1/") | ||
response = view1(request) | ||
serialized_interaction = OpticEcsLogger().serialize_to_ecs(request, response, request.body) | ||
serialized_interaction = OpticEcsLogger().serialize_to_ecs( | ||
request, response, request.body | ||
) | ||
interaction = get_fixture("1.log") | ||
self.assertDictEqual(interaction[0], serialized_interaction) | ||
|
||
@freeze_time("2021-01-01") | ||
def test_serialize_form_test(self): | ||
rf = RequestFactory(HTTP_USER_AGENT="DjangoTestServer") | ||
form_data = urlencode( | ||
MultiValueDict({"name": "Boo", "names": ["foo", "bar"]}), doseq=True | ||
) | ||
request = rf.post( | ||
"/form-url", | ||
data=form_data, | ||
content_type="application/x-www-form-urlencoded", | ||
) | ||
response = form_view(request) | ||
serialized_interaction = OpticEcsLogger().serialize_to_ecs( | ||
request, response, request.body | ||
) | ||
interaction = get_fixture("2.log") | ||
self.assertDictEqual(interaction[0], serialized_interaction) | ||
|
||
@freeze_time("2021-01-01") | ||
def test_serialize_json_test(self): | ||
rf = RequestFactory(HTTP_USER_AGENT="DjangoTestServer") | ||
request = rf.put( | ||
"/json-url-3", data={"name": "Boo"}, content_type="application/json" | ||
) | ||
response = json_view(request) | ||
serialized_interaction = OpticEcsLogger().serialize_to_ecs( | ||
request, response, request.body | ||
) | ||
interaction = get_fixture("3.log") | ||
self.assertDictEqual(interaction[0], serialized_interaction) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.