Skip to content

Commit

Permalink
Change social information
Browse files Browse the repository at this point in the history
Co-authored-by: Breno Mariz <mrzbeo@gmail.com>
  • Loading branch information
mateusdemorais and breno-mariz committed Jun 17, 2018
1 parent 12a4df0 commit fbab955
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 99 deletions.
2 changes: 1 addition & 1 deletion VoxPopLoader/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def setup(self):
base=self.base_url
)

self.api_base_url = "localhost:8000"
self.api_base_url = "api:8000"
self.propositions_url = \
"http://{base}/api/propositions/?limit=10000".format(
base=self.api_base_url
Expand Down
9 changes: 5 additions & 4 deletions api/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,19 @@ class PropositionAdmin(admin.ModelAdmin):
'year',
'abstract',
'processing',
'situation'
'situation',
'last_update'
]


class SocialInformationAdmin(admin.ModelAdmin):
list_display = [
'owner',
'federal_unit',
'city',
'region',
'income',
'education',
'job',
'race',
'gender',
'birth_date',
]

Expand Down
132 changes: 67 additions & 65 deletions api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,47 @@


# Create your models here.
UF_CHOICES = (
('N', 'Null'),
('AC', 'Acre'),
('AL', 'Alagoas'),
('AP', 'Amapá'),
('BA', 'Bahia'),
('CE', 'Ceará'),
('DF', 'Distrito Federal'),
('ES', 'Espírito Santo'),
('GO', 'Goiás'),
('MA', 'Maranão'),
('MG', 'Minas Gerais'),
('MS', 'Mato Grosso do Sul'),
('MT', 'Mato Grosso'),
('PA', 'Pará'),
('PB', 'Paraíba'),
('PE', 'Pernanbuco'),
('PI', 'Piauí'),
('PR', 'Paraná'),
('RJ', 'Rio de Janeiro'),
('RN', 'Rio Grande do Norte'),
('RO', 'Rondônia'),
('RR', 'Roraima'),
('RS', 'Rio Grande do Sul'),
('SC', 'Santa Catarina'),
('SE', 'Sergipe'),
('SP', 'São Paulo'),
('TO', 'Tocantins')
REGION_CHOICES = (
(None, 'Null'),
('N', 'Norte'),
('NE', 'Nordeste'),
('CO', 'Centro-Oeste'),
('SE', 'Sudeste'),
('S', 'Sul')
)

INCOME_CHOICES = (
(None, 'Null'),
('E', '0.00-1874.00'),
('D', '1874.01-3748.00'),
('C', '3748.01-9370.00'),
('B', '9370.01-18740.00'),
('A', '18740.01+')
)

EDUCATION_CHOICES = (
('N', 'Null'),
('EFC', 'Ensino Fundamental Completo'),
('EFI', 'Ensino Fundamental Incompleto'),
('EMC', 'Ensino Médio Completo'),
('EMI', 'Ensino Médio Incompleto'),
('ESC', 'Ensino Superior Completo'),
('ESI', 'Ensino Superior Incompleto'),
('PG', 'Pós-Graduação'),
('ME', 'Mestrado'),
('DO', 'Doutorado'),
('PD', 'Pós-Doutorado')
(None, 'Null'),
('SE', 'Sem Escolaridade'),
('EF', 'Ensino Fundamental'),
('EM', 'Ensino Médio'),
('ES', 'Ensino Superior'),
('PG', 'Pós-Graduação')
)

RACE_CHOICES = (
(None, 'Null'),
('B', 'Branca'),
('PR', 'Preta'),
('A', 'Amarela'),
('PA', 'Parda'),
('I', 'Indígena')
)

GENDER_CHOICES = (
(None, 'Null'),
('M', 'Masculino'),
('F', 'Feminino'),
('O', 'Outros')
)

VOTE_CHOICES = (
Expand All @@ -57,22 +56,6 @@
('M', 'Missing'),
)

GENDER_CHOICES = (
('M', 'Male'),
('F', 'Female'),
)

INCOME_CHOICES = (
('-1', 'Null'),
('0', '0.00-1000.00'),
('1', '1000.01-3000.00'),
('2', '3000.01-6000.00'),
('3', '6000.01-9000.00'),
('4', '9000.01-15000.00'),
('5', '15000.01-25000.00'),
('6', '25000.00+'),
)

CONTACT_CHOICES = (
('A', 'Dúvida'),
('B', 'Sugestão'),
Expand All @@ -88,22 +71,40 @@ class SocialInformation(models.Model):
related_name='social_information',
on_delete=models.CASCADE
)
federal_unit = models.CharField(
max_length=150,
choices=UF_CHOICES,
default='N'
region = models.CharField(
max_length=2,
choices=REGION_CHOICES,
default=None,
null=True
)
city = models.CharField(max_length=150, blank=True)
income = models.CharField(
max_length=100,
max_length=20,
choices=INCOME_CHOICES,
default='-1'
default=None,
null=True
)
education = models.CharField(
max_length=150, choices=EDUCATION_CHOICES, default='N'
max_length=2,
choices=EDUCATION_CHOICES,
default=None,
null=True
)
race = models.CharField(
max_length=2,
choices=RACE_CHOICES,
default=None,
null=True
)
gender = models.CharField(
max_length=1,
choices=GENDER_CHOICES,
default=None,
null=True
)
birth_date = models.DateField(
default=None,
null=True
)
job = models.CharField(max_length=100, blank=True)
birth_date = models.DateField(default=datetime.date.today)

def __str__(self):
return '{owner}'.format(owner=self.owner)
Expand Down Expand Up @@ -146,6 +147,7 @@ class Proposition(models.Model):
processing = models.CharField(max_length=100, blank=True)
situation = models.CharField(max_length=100, blank=True)
url_full = models.URLField(blank=True)
last_update = models.DateTimeField(blank=True)

def __str__(self):
return 'Proposition {native_id}'.format(
Expand Down
2 changes: 1 addition & 1 deletion api/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def has_permission(self, request, view):
elif (request.user.is_anonymous and request.method == 'POST'):
return True

elif 'users' in request.path and not 'actual_user' in request.path:
elif 'users' in request.path and 'actual_user' not in request.path:
url_id = request.path.split('/users/')[1][:-1]
user_id = str(request.user.id)

Expand Down
9 changes: 5 additions & 4 deletions api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class Meta:
fields = [
'id',
'owner',
'federal_unit',
'city',
'region',
'income',
'education',
'job',
'race',
'gender',
'birth_date',
]

Expand Down Expand Up @@ -100,7 +100,8 @@ class Meta:
'abstract',
'processing',
'situation',
'url_full'
'url_full',
'last_update'
]


Expand Down
54 changes: 30 additions & 24 deletions api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ def setUp(self):
email='teste@teste.com',
password='teste'
)
self.social_information = SocialInformation.objects.create(
owner=self.user
)
self.url = '/api/users/'
# self.client.force_login(self.user)
self.client.force_authenticate(self.superuser)
Expand All @@ -37,6 +40,7 @@ def tearDown(self):
This method will run after any test.
"""
self.user.delete()
self.social_information.delete()

def test_create_user(self):
"""
Expand All @@ -63,6 +67,7 @@ def test_update_user(self):
"""
Ensure we can create a new user object.
"""
self.client.force_authenticate(self.user)
self.assertEqual(self.user.username, 'teste')
data = {
'username':'teste',
Expand Down Expand Up @@ -102,6 +107,7 @@ def test_partial_update_user(self):
"""
Ensure we can partially update a user object.
"""
self.client.force_authenticate(self.user)
self.assertEqual(self.user.email, 'teste@teste.com')
data = {
'email':'silverson@teste.com',
Expand Down Expand Up @@ -171,12 +177,12 @@ def test_invalid_create_social(self):
"""
data = {
"owner": self.user,
"federal_unit": "AC",
"city": "Rio Branco",
"income": "2",
"education": "EFC",
"job": "Dono de Casa",
"birth_date": "2018-01-01"
"region": "",
"income": "",
"education": "",
"race": "",
"gender": "",
"birth_date": ""
}
response = None

Expand All @@ -191,34 +197,34 @@ def test_update_social(self):
"""
Ensure we can update a new social information object.
"""
self.assertEqual(self.social.job, '')
self.assertEqual(self.social.region, None)
data = {
"owner": self.user.pk,
"federal_unit": "AC",
"city": "Rio Branco",
"income": "2",
"education": "EFC",
"job": "Dono de Prédio",
"birth_date": "2018-04-07"
"region": "N",
"income": "",
"education": "",
"race": "",
"gender": "",
"birth_date": ""
}
response = self.client.put(self.url + str(self.social.pk) + '/', data)

new_social = SocialInformation.objects.get(pk=self.social.pk)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(new_social.job, 'Dono de Prédio')
self.assertEqual(new_social.region, 'N')

def test_invalid_update_social(self):
"""
Ensure we can't update a social object with invalid fields.
"""
self.assertEqual(self.social.birth_date, datetime.date.today())
self.assertEqual(self.social.birth_date, None)
data = {
"owner": self.user.pk,
"federal_unit": "AC",
"city": "Rio Branco",
"income": "2",
"education": "EFC",
"job": "Dono de Casa",
"region": "",
"income": "",
"education": "",
"race": "",
"gender": "",
"birth_date": "20180-43-213"
}
response = self.client.put(self.url + str(self.social.pk) + '/', data)
Expand All @@ -236,21 +242,21 @@ def test_partial_update_social(self):
"""
Ensure we can partially update a social object.
"""
self.assertEqual(self.social.job, '')
self.assertEqual(self.social.region, None)
data = {
'job':'Dono de Condomínio',
'region': 'N',
}
response = self.client.patch(self.url + str(self.social.pk) + '/', data)
new_social = SocialInformation.objects.get(pk=self.social.pk)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(new_social.job, 'Dono de Condomínio')
self.assertEqual(new_social.region, 'N')

def test_invalid_partial_update_social(self):
"""
Ensure we can't partially update invalid information on a valid social
object.
"""
self.assertEqual(self.social.job, '')
self.assertEqual(self.social.region, None)
data = {
'birth_date': '20180-56-89',
}
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ django-cors-headers
django-celery-beat
redis
coverage
django-rest-framework-social-oauth2

0 comments on commit fbab955

Please sign in to comment.