Skip to content

Commit

Permalink
project: format
Browse files Browse the repository at this point in the history
  • Loading branch information
Tatsh committed Sep 14, 2023
1 parent c8533ae commit 973674a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
5 changes: 1 addition & 4 deletions minchoc/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ def __str__(self) -> str:
return cast(str, self.base.username)


def post_save_receiver(
sender: AbstractUser,
instance: AbstractUser,
**kwargs: Any) -> None:
def post_save_receiver(sender: AbstractUser, instance: AbstractUser, **kwargs: Any) -> None:
if not NugetUser.objects.filter(base=instance).exists():
nuget_user = NugetUser()
nuget_user.base = instance
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.conf import settings
import pytest

DJANGO_APP_DIR = Path(f'testdjango{uuid4().hex}')
DJANGO_APP_DIR = Path(f'test_django{uuid4().hex}')

pytest_plugins = ['tests.fixtures']

Expand Down
1 change: 1 addition & 0 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@pytest.fixture
def nuget_user() -> Iterator[Any]:
from django.contrib.auth.models import User

from minchoc.models import NugetUser
user = User.objects.create()
assert user is not None
Expand Down
35 changes: 20 additions & 15 deletions tests/test_workflow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.test import Client
import pytest

from minchoc.models import NugetUser


Expand Down Expand Up @@ -33,37 +34,41 @@ def test_post_not_authorized(client: Client) -> None:

@pytest.mark.django_db
def test_put_invalid_content_type_unknown(client: Client, nuget_user: NugetUser) -> None:
response = client.put('/api/v2/package/', headers={'x-nuget-apikey': nuget_user.token.hex})
response = client.put('/api/v2/package/', headers={'x-nuget-apikey':
nuget_user.token.hex}) # type: ignore[arg-type]
assert response.json()['error'] == 'Invalid content type: unknown'
assert response.status_code == 400


@pytest.mark.django_db
def test_put_invalid_content_type_set(client: Client, nuget_user: NugetUser) -> None:
response = client.put('/api/v2/package/',
'nothing',
'application/xml',
headers={'x-nuget-apikey': nuget_user.token.hex})
response = client.put(
'/api/v2/package/',
'nothing',
'application/xml',
headers={'x-nuget-apikey': nuget_user.token.hex}) # type: ignore[arg-type]
assert response.json()['error'] == 'Invalid content type: application/xml'
assert response.status_code == 400


@pytest.mark.django_db
def test_put_no_boundary(client: Client, nuget_user: NugetUser) -> None:
response = client.put('/api/v2/package/',
'nothing',
'multipart/form-data',
headers={'x-nuget-apikey': nuget_user.token.hex})
response = client.put(
'/api/v2/package/',
'nothing',
'multipart/form-data',
headers={'x-nuget-apikey': nuget_user.token.hex}) # type: ignore[arg-type]
assert response.json()['error'] == 'Invalid upload'
assert response.status_code == 400


@pytest.mark.django_db
def test_put_no_files(client: Client, nuget_user: NugetUser) -> None:
response = client.put('/api/v2/package/',
'nothing',
'multipart/form-data; boundary=1234abc',
headers={'x-nuget-apikey': nuget_user.token.hex})
response = client.put(
'/api/v2/package/',
'nothing',
'multipart/form-data; boundary=1234abc',
headers={'x-nuget-apikey': nuget_user.token.hex}) # type: ignore[arg-type]
assert response.json()['error'] == 'No files sent'
assert response.status_code == 400

Expand All @@ -87,7 +92,7 @@ def test_put_too_many_files(client: Client, nuget_user: NugetUser) -> None:
headers={
'content-length': f'{len(content)}',
'x-nuget-apikey': nuget_user.token.hex
})
}) # type: ignore[arg-type]
assert response.json()['error'] == 'More than one file sent'
assert response.status_code == 400

Expand All @@ -106,6 +111,6 @@ def test_put_not_zip_file(client: Client, nuget_user: NugetUser) -> None:
headers={
'content-length': f'{len(content)}',
'x-nuget-apikey': nuget_user.token.hex
})
}) # type: ignore[arg-type]
assert response.json()['error'] == 'Not a zip file'
assert response.status_code == 400

0 comments on commit 973674a

Please sign in to comment.