diff --git a/VoxPopLoader/loader.py b/VoxPopLoader/loader.py index d81a85d..2422e90 100644 --- a/VoxPopLoader/loader.py +++ b/VoxPopLoader/loader.py @@ -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 diff --git a/api/admin.py b/api/admin.py index 6dad804..bff47e1 100644 --- a/api/admin.py +++ b/api/admin.py @@ -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', ] diff --git a/api/models.py b/api/models.py index 1d4b01e..89e5fd1 100644 --- a/api/models.py +++ b/api/models.py @@ -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 = ( @@ -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'), @@ -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) @@ -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( diff --git a/api/permissions.py b/api/permissions.py index 93f693a..30775ee 100644 --- a/api/permissions.py +++ b/api/permissions.py @@ -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) diff --git a/api/serializers.py b/api/serializers.py index 289989f..d523297 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -13,11 +13,11 @@ class Meta: fields = [ 'id', 'owner', - 'federal_unit', - 'city', + 'region', 'income', 'education', - 'job', + 'race', + 'gender', 'birth_date', ] @@ -100,7 +100,8 @@ class Meta: 'abstract', 'processing', 'situation', - 'url_full' + 'url_full', + 'last_update' ] diff --git a/api/tests.py b/api/tests.py index ac79143..7684c21 100644 --- a/api/tests.py +++ b/api/tests.py @@ -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) @@ -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): """ @@ -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', @@ -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', @@ -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 @@ -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) @@ -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', } diff --git a/requirements.txt b/requirements.txt index d8d7ffa..916605e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,3 +8,4 @@ django-cors-headers django-celery-beat redis coverage +django-rest-framework-social-oauth2