Skip to content

Commit

Permalink
Merge branch 'develop' into feature/179-continuous-deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorcx authored Nov 23, 2019
2 parents 8eb5fd7 + d6bbc21 commit 64c3fc2
Show file tree
Hide file tree
Showing 25 changed files with 1,026 additions and 290 deletions.
7 changes: 2 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
image: postgres
env_file: ./.enviroments/.dev
volumes:
- postgres_data:/var/lib/postgresql/data
- "./data/postgres:/var/lib/postgresql/data"

acacia-back:
container_name: acacia_backend
Expand All @@ -25,7 +25,4 @@ services:
volumes:
- .:/code
depends_on:
- db

volumes:
postgres_data:
- db
3 changes: 2 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<p align="center"> <img src="img/wordmark_1.svg" width="400"></p>

[![codecov](https://codecov.io/gh/fga-eps-mds/2019.2-Acacia/branch/develop/graph/badge.svg)](https://codecov.io/gh/fga-eps-mds/2019.2-Acacia)
[![Maintainability](https://api.codeclimate.com/v1/badges/9ceab9b0533182362c16/maintainability)](https://codeclimate.com/github/fga-eps-mds/2019.2-Acacia/maintainability)

## Visão geral

Expand Down Expand Up @@ -68,4 +69,4 @@ Após esses passos a aplicação deverá estar acessível em:

#### Front-end:

Para instalar a camada front-end da aplicação basta seguir os passos de instalação descritos [aqui](https://github.com/fga-eps-mds/2019.2-Acacia-Frontend)
Para instalar a camada front-end da aplicação basta seguir os passos de instalação descritos [aqui](https://github.com/fga-eps-mds/2019.2-Acacia-Frontend)
16 changes: 8 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Pillow
whitenoise
flake8==3.7.8
Django==2.2.4
djangorestframework==3.10
django-phonenumber-field==3.0
phonenumbers==8.10
psycopg2==2.8.3
django-cors-headers==3.1.0
flake8==3.7.8
djangorestframework-simplejwt==4.3.0
coverage==4.5.4
phonenumbers==8.10
django-localflavor==2.2
pillow
whitenoise
djangorestframework==3.10
django-cors-headers==3.1.0
django-phonenumber-field==3.0
djangorestframework-simplejwt==4.3.0
5 changes: 3 additions & 2 deletions src/acacia/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@
('fr-CA', _('French Canadian')),
)

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
Expand Down Expand Up @@ -178,8 +180,7 @@
"http://localhost:8080",
"http://45.55.46.19:8080",
"http://45.55.46.19:8081",

]
]

SIMPLE_JWT = {
'ACCESS_TOKEN_LIFETIME': timedelta(days=5),
Expand Down
8 changes: 7 additions & 1 deletion src/acacia/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.contrib import admin
from django.urls import path, include
from .helpers import list_all_endpoints
from harvest.viewsets import WeekHarvests
from harvest.viewsets import WeekHarvests, MonthlyHarvests


urlpatterns = [
Expand All @@ -25,6 +25,12 @@
WeekHarvests.as_view({'get': 'list'}),
name='weekly_harvests'
),

path(
'monthly_harvest/<int:year>/<int:month>/',
MonthlyHarvests.as_view({'get': 'list'}),
name='monthly_harvest'
),
]

urlpatterns = list_all_endpoints(urlpatterns)
2 changes: 1 addition & 1 deletion src/harvest/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 2.2.4 on 2019-11-16 15:35
# Generated by Django 2.2.4 on 2019-11-19 23:47

from django.db import migrations, models
import django.db.models.deletion
Expand Down
11 changes: 0 additions & 11 deletions src/harvest/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,6 @@ class Harvest(models.Model):
max_volunteers = models.PositiveSmallIntegerField()
min_volunteers = models.PositiveSmallIntegerField()

# TODO: check if this field will continue in this model
# ACCESS_TYPES = (
# ('Restrict Access', 'Restrict Access'),
# ('Free Access', 'Free Access'),
# )

# access = models.CharField(
# choices=ACCESS_TYPES,
# max_length=15
# )

def __str__(self):
return str(self.date)

Expand Down
149 changes: 149 additions & 0 deletions src/harvest/tests/test_tree_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,152 @@ def test_delete_harvest(self):
0,
msg='Failed to delete the harvest'
)


class MonthlyHarvestsTestCase(APITestCase):

def create_authentication_tokens(self, user_credentials):
url_token = reverse('users:token_obtain_pair')

response = self.client.post(
url_token,
user_credentials,
format='json'
)

self.assertEqual(
response.status_code,
200,
msg='Failed to create user tokens credentials'
)

self.credentials = {
'HTTP_AUTHORIZATION': 'Bearer ' + response.data['access']
}

def create_user(self):
user_data = {
"username": 'vitas',
'email': '[email protected]',
'password': 'vitasIsNice',
'confirm_password': 'vitasIsNice'
}

url_user_signup = reverse('users:register')

response = self.client.post(
url_user_signup,
user_data,
format='json'
)

self.assertEqual(
response.status_code,
201,
msg='Failed during user creation'
)

user_data.pop('username')
user_data.pop('confirm_password')

self.create_authentication_tokens(user_data)

def create_property(self):
property_data = {
'type_of_address': 'House',
'BRZipCode': '73021498',
'state': 'DF',
'city': 'Gama',
'district': 'Leste',
'address': "Quadra 4",
}

url_property_creation = reverse(
'property:property-list',
)

response = self.client.post(
path=url_property_creation,
data=property_data,
format='json',
**self.credentials,
)

self.assertEqual(
response.status_code,
201,
msg='Failed to create property'
)

self.property = Property.objects.get(pk=1)

def setUp(self):
self.create_user()
self.create_property()

self.harvest_data = {
'date': '2019-11-21',
'description': 'Apple Harvest',
'status': 'Open',
'max_volunteers': 10,
'min_volunteers': 5,
}

self.url_list = reverse(
'property:harvest:harvest-list',
kwargs={'property_pk': self.property.pk}
)

self.url_detail = reverse(
'property:harvest:harvest-detail',
kwargs={
'property_pk': self.property.pk,
'pk': '1'
}
)

def tearDown(self):
Property.objects.all().delete()
User.objects.all().delete()
Harvest.objects.all().delete()

def test_get_harvests_of_the_week(self):

today = datetime.date(datetime(2020, 1, 1))

for i in range(0, 12):
date = today + timedelta(days=i*31)

self.harvest_data['date'] = date

response = self.client.post(
path=self.url_list,
data=self.harvest_data,
format='json',
**self.credentials,
)

self.assertEqual(
response.status_code,
201,
msg='Failed to create a harvest'
)

for month in range(1, 13):
weekly_harvests_url = reverse(
'monthly_harvest',
kwargs={
'year': date.year,
'month': month
}
)

response = self.client.get(
path=weekly_harvests_url,
)

self.assertEqual(
len(response.data),
1,
msg='Failed return only 1 harvest'
)
24 changes: 24 additions & 0 deletions src/harvest/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from . import serializers

import datetime
import calendar


class HarvestViewSet(viewsets.ModelViewSet):
Expand Down Expand Up @@ -74,3 +75,26 @@ def get_queryset(self):
)

return queryset


class MonthlyHarvests(ListModelMixin, viewsets.GenericViewSet):

queryset = Harvest.objects.all()
serializer_class = serializers.HarvestSerializer
permission_classes = (permissions.AllowAny,)

def get_queryset(self):

month = self.kwargs['month']
year = self.kwargs['year']

_, last_day = calendar.monthrange(year, month)

start_date = datetime.datetime(year, month, 1)
end_date = datetime.datetime(year, month, last_day)

queryset = Harvest.objects.filter(
date__range=(start_date, end_date)
)

return queryset
2 changes: 1 addition & 1 deletion src/property/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 2.2.4 on 2019-11-16 15:35
# Generated by Django 2.2.4 on 2019-11-19 23:47

from django.conf import settings
from django.db import migrations, models
Expand Down
2 changes: 1 addition & 1 deletion src/property/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class UserIsPropertyOwner(permissions.BasePermission):
Assumes the model instance has an `user` attribute.
"""

def has_object_permition(self, request, view, property):
def has_object_permission(self, request, view, property):
return bool(
request.method in permissions.SAFE_METHODS or
request.user and
Expand Down
7 changes: 7 additions & 0 deletions src/property/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ def test_verbose_name_plural(self):
_('Properties')
)

def test_unique_together(self):
self.assertEqual(
Property._meta.unique_together,
(('BRZipCode', 'type_of_address', 'address'),),
msg='Property unique key is not being set properly'
)

def test_property_creation(self):
self.assertEqual(
Property.objects.last(),
Expand Down
Loading

0 comments on commit 64c3fc2

Please sign in to comment.