Skip to content

Commit

Permalink
Merge pull request #25 from unicef/develop
Browse files Browse the repository at this point in the history
Release 0.9.0
  • Loading branch information
robertavram committed Oct 21, 2020
2 parents ef22194 + d1fd501 commit 0db38dc
Show file tree
Hide file tree
Showing 21 changed files with 75 additions and 36 deletions.
6 changes: 6 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[flake8]
max-line-length = 120
ignore =

exclude =
*/migrations,
12 changes: 12 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[isort]
combine_as_imports = true
default_section = THIRDPARTY
include_trailing_comma = true
known_tests = pytest,unittest,factory
known_demo = demo
sections = FUTURE,STDLIB,DJANGO,THIRDPARTY,TESTS,FIRSTPARTY,DEMO,LOCALFOLDER
known_first_party = unicef_attachments
multi_line_output = 3
line_length = 120
balanced_wrapping = true
order_by_type = false
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ python:
env:
- DJANGO=2.2
- DJANGO=3.0
- DJANGO=3.1

addons:
postgresql: "9.5"
postgresql: "9.6"

install:
- pip install tox codecov
Expand Down
6 changes: 5 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
Release 0.9
-----------
* Update attachment upload post to be atomic

Release 0.8
-----------
* Add support to python 3.8
* Remove support to python 3.6
* Add support to django 3.0
* Add support to django 3.0 and 3.1
* Remove support to django 2.1

Release 0.7
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
'Framework :: Django',
'Framework :: Django :: 2.2',
'Framework :: Django :: 3.0',
'Framework :: Django :: 3.1',
'Intended Audience :: Developers'],
scripts=[],
)
Expand Down
2 changes: 1 addition & 1 deletion src/unicef_attachments/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
NAME = 'unicef_attachments'
VERSION = __version__ = "0.8.0"
VERSION = __version__ = "0.9.0"
__author__ = 'UNICEF'
13 changes: 6 additions & 7 deletions src/unicef_attachments/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from urllib.parse import urljoin

from django.contrib.contenttypes.models import ContentType
from django.db import transaction
from django.db.models import Q
from django.http import HttpResponseNotFound, HttpResponseRedirect
from django.utils.translation import gettext as _
Expand Down Expand Up @@ -105,15 +106,13 @@ class AttachmentCreateView(CreateAPIView):
def perform_create(self, serializer):
self.instance = serializer.save()

@transaction.atomic
def post(self, *args, **kwargs):
super().post(*args, **kwargs)
return Response(
AttachmentFlatSerializer(
get_attachment_flat_model().objects.filter(
attachment=self.instance
).first()
).data
)
attachment_flat = get_attachment_flat_model().objects.filter(
attachment=self.instance
).first()
return Response(AttachmentFlatSerializer(attachment_flat).data)


class AttachmentUpdateView(UpdateAPIView):
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import base64
import tempfile

import pytest
from django.contrib.contenttypes.models import ContentType
from django.core.files.uploadedfile import SimpleUploadedFile
from rest_framework.test import APIClient

import pytest

from tests import factories


Expand Down
3 changes: 2 additions & 1 deletion tests/demoproject/demo/sample/admin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from demo.sample.models import Author
from django.contrib import admin

from unicef_attachments.admin import AttachmentInlineAdminMixin, AttachmentSingleInline

from demo.sample.models import Author


class ProfileImageInline(AttachmentSingleInline):
code = 'author_profile_image'
Expand Down
3 changes: 2 additions & 1 deletion tests/demoproject/demo/sample/serializers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from demo.sample.models import Author, Book
from rest_framework import serializers

from unicef_attachments.fields import AttachmentSingleFileField, FileTypeModelChoiceField
from unicef_attachments.models import FileType
from unicef_attachments.serializers import AttachmentSerializerMixin

from demo.sample.models import Author, Book


class BookSerializer(serializers.ModelSerializer):
class Meta:
Expand Down
3 changes: 2 additions & 1 deletion tests/demoproject/demo/sample/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from demo.sample import views
from rest_framework import routers

from demo.sample import views

app_name = 'sample'

router = routers.DefaultRouter()
Expand Down
3 changes: 2 additions & 1 deletion tests/demoproject/demo/sample/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from rest_framework import viewsets

from demo.sample import serializers
from demo.sample.models import Author, Book
from rest_framework import viewsets


class AuthorViewSet(viewsets.ModelViewSet):
Expand Down
6 changes: 4 additions & 2 deletions tests/factories.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import factory
from demo.sample.models import Author, Book
from django.contrib.auth import get_user_model

import factory
from factory import fuzzy

from unicef_attachments import models

from demo.sample.models import Author, Book


class UserFactory(factory.django.DjangoModelFactory):
username = factory.Faker("user_name")
Expand Down
3 changes: 2 additions & 1 deletion tests/test_admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
from django.urls import reverse

import pytest

pytestmark = pytest.mark.django_db


Expand Down
6 changes: 4 additions & 2 deletions tests/test_fields.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import base64

import pytest
from demo.sample.serializers import AuthorFileTypeSerializer
from rest_framework import serializers

import pytest

from tests.factories import AttachmentFactory, AttachmentFileTypeFactory
from unicef_attachments.fields import AttachmentSingleFileField, Base64FileField
from unicef_attachments.models import Attachment

from demo.sample.serializers import AuthorFileTypeSerializer

pytestmark = pytest.mark.django_db


Expand Down
3 changes: 2 additions & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import pytest
from django.core.exceptions import ValidationError
from django.core.files.uploadedfile import SimpleUploadedFile

import pytest

from tests.factories import AttachmentFactory, AttachmentFileTypeFactory
from unicef_attachments import models

Expand Down
6 changes: 4 additions & 2 deletions tests/test_serializers.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import os

import pytest
from demo.sample.serializers import AuthorOverrideSerializer, AuthorSerializer
from rest_framework.exceptions import ValidationError

import pytest

from tests.factories import AttachmentFactory, AttachmentFileTypeFactory, UserFactory
from unicef_attachments.models import Attachment
from unicef_attachments.serializers import Base64AttachmentSerializer

from demo.sample.serializers import AuthorOverrideSerializer, AuthorSerializer

pytestmark = pytest.mark.django_db


Expand Down
10 changes: 6 additions & 4 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import pytest
from demo.sample.models import AttachmentFlatOverride
from demo.sample.permissions import AttachmentPermOverride
from demo.sample.utils import denormalize, filepath_prefix
from django.core.exceptions import ImproperlyConfigured

import pytest

from tests.factories import AttachmentFactory, AttachmentFileTypeFactory
from unicef_attachments import utils
from unicef_attachments.models import AttachmentFlat, FileType
from unicef_attachments.permissions import AttachmentPermissions

from demo.sample.models import AttachmentFlatOverride
from demo.sample.permissions import AttachmentPermOverride
from demo.sample.utils import denormalize, filepath_prefix

pytestmark = pytest.mark.django_db


Expand Down
3 changes: 2 additions & 1 deletion tests/test_validators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
from django.forms import ValidationError

import pytest

from unicef_attachments.validators import SafeFileValidator


Expand Down
6 changes: 3 additions & 3 deletions tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from unittest.mock import Mock, patch

import pytest
from django.contrib.contenttypes.models import ContentType
from django.urls import reverse
from rest_framework import status

import pytest
from unittest.mock import Mock, patch

from tests.factories import AttachmentFactory, AttachmentFileTypeFactory
from unicef_attachments.models import Attachment, AttachmentLink

Expand Down
10 changes: 5 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py{37,38}-d{22,30}
envlist = py{37,38}-d{22,30,31}
envtmpdir={toxinidir}/build/{envname}/tmp
envlogdir={toxinidir}/build/{envname}/log

Expand Down Expand Up @@ -29,16 +29,16 @@ setenv =
PYTHONPATH={toxinidir}/src
deps =
d22: django==2.2.*
d30: django>==3.0.*
dev: git+git://github.com/django/django.git#egg=django
d30: django==3.0.*
d31: django==3.1.*
extras =
test
whitelist_externals = createdb
bash

commands =
flake8 src/
isort -rc src/ --check-only
flake8 src/ tests/
isort src/ tests/ --check-only
pytest tests \
-q \
--create-db \
Expand Down

0 comments on commit 0db38dc

Please sign in to comment.