From 49c0f1d558cda071d0f2394816ecd24d942adf34 Mon Sep 17 00:00:00 2001 From: Giovani Date: Sat, 14 Oct 2017 02:55:55 -0300 Subject: [PATCH 01/34] startapp chamber_of_deputies --- jarbas/chamber_of_deputies/__init__.py | 0 jarbas/chamber_of_deputies/admin.py | 3 +++ jarbas/chamber_of_deputies/apps.py | 5 +++++ jarbas/chamber_of_deputies/migrations/__init__.py | 0 jarbas/chamber_of_deputies/models.py | 3 +++ jarbas/chamber_of_deputies/tests.py | 3 +++ jarbas/chamber_of_deputies/views.py | 3 +++ 7 files changed, 17 insertions(+) create mode 100644 jarbas/chamber_of_deputies/__init__.py create mode 100644 jarbas/chamber_of_deputies/admin.py create mode 100644 jarbas/chamber_of_deputies/apps.py create mode 100644 jarbas/chamber_of_deputies/migrations/__init__.py create mode 100644 jarbas/chamber_of_deputies/models.py create mode 100644 jarbas/chamber_of_deputies/tests.py create mode 100644 jarbas/chamber_of_deputies/views.py diff --git a/jarbas/chamber_of_deputies/__init__.py b/jarbas/chamber_of_deputies/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/jarbas/chamber_of_deputies/admin.py b/jarbas/chamber_of_deputies/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/jarbas/chamber_of_deputies/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/jarbas/chamber_of_deputies/apps.py b/jarbas/chamber_of_deputies/apps.py new file mode 100644 index 0000000..be19e72 --- /dev/null +++ b/jarbas/chamber_of_deputies/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class ChamberOfDeputiesConfig(AppConfig): + name = 'chamber_of_deputies' diff --git a/jarbas/chamber_of_deputies/migrations/__init__.py b/jarbas/chamber_of_deputies/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/jarbas/chamber_of_deputies/models.py b/jarbas/chamber_of_deputies/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/jarbas/chamber_of_deputies/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/jarbas/chamber_of_deputies/tests.py b/jarbas/chamber_of_deputies/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/jarbas/chamber_of_deputies/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/jarbas/chamber_of_deputies/views.py b/jarbas/chamber_of_deputies/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/jarbas/chamber_of_deputies/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. From aa45708b4296174b3e85b8c6e1cf6d4e34684269 Mon Sep 17 00:00:00 2001 From: Giovani Date: Sat, 14 Oct 2017 02:55:55 -0300 Subject: [PATCH 02/34] startapp chamber_of_deputies --- jarbas/chamber_of_deputies/__init__.py | 0 jarbas/chamber_of_deputies/admin.py | 3 +++ jarbas/chamber_of_deputies/app.py | 6 ++++++ jarbas/chamber_of_deputies/migrations/__init__.py | 0 jarbas/chamber_of_deputies/models.py | 3 +++ jarbas/chamber_of_deputies/tests.py | 3 +++ jarbas/chamber_of_deputies/views.py | 3 +++ 7 files changed, 18 insertions(+) create mode 100644 jarbas/chamber_of_deputies/__init__.py create mode 100644 jarbas/chamber_of_deputies/admin.py create mode 100644 jarbas/chamber_of_deputies/app.py create mode 100644 jarbas/chamber_of_deputies/migrations/__init__.py create mode 100644 jarbas/chamber_of_deputies/models.py create mode 100644 jarbas/chamber_of_deputies/tests.py create mode 100644 jarbas/chamber_of_deputies/views.py diff --git a/jarbas/chamber_of_deputies/__init__.py b/jarbas/chamber_of_deputies/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/jarbas/chamber_of_deputies/admin.py b/jarbas/chamber_of_deputies/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/jarbas/chamber_of_deputies/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/jarbas/chamber_of_deputies/app.py b/jarbas/chamber_of_deputies/app.py new file mode 100644 index 0000000..d5a36de --- /dev/null +++ b/jarbas/chamber_of_deputies/app.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ChamberOfDeputiesConfig(AppConfig): + name = 'jarbas.chamber_of_deputies' + verbose_name = 'Câmara dos Deputados' diff --git a/jarbas/chamber_of_deputies/migrations/__init__.py b/jarbas/chamber_of_deputies/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/jarbas/chamber_of_deputies/models.py b/jarbas/chamber_of_deputies/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/jarbas/chamber_of_deputies/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/jarbas/chamber_of_deputies/tests.py b/jarbas/chamber_of_deputies/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/jarbas/chamber_of_deputies/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/jarbas/chamber_of_deputies/views.py b/jarbas/chamber_of_deputies/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/jarbas/chamber_of_deputies/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. From e8d99a3bb6a264e0a71a9263cc3d06ae6cd46802 Mon Sep 17 00:00:00 2001 From: Giovani Date: Sat, 14 Oct 2017 05:00:59 -0300 Subject: [PATCH 03/34] split core models between core and chamber_of_deputies models --- jarbas/chamber_of_deputies/models.py | 157 ++++++++++++++++++++++++++- jarbas/core/models.py | 157 --------------------------- 2 files changed, 156 insertions(+), 158 deletions(-) diff --git a/jarbas/chamber_of_deputies/models.py b/jarbas/chamber_of_deputies/models.py index 71a8362..01445b6 100644 --- a/jarbas/chamber_of_deputies/models.py +++ b/jarbas/chamber_of_deputies/models.py @@ -1,3 +1,158 @@ +from django.contrib.postgres.fields import JSONField +from django.contrib.postgres.indexes import GinIndex +from django.contrib.postgres.search import SearchVectorField from django.db import models +from requests import head -# Create your models here. +from simple_history.models import HistoricalRecords +from jarbas.core.querysets import ReimbursementQuerySet + + +class Receipt: + + def __init__(self, year, applicant_id, document_id): + self.year = year + self.applicant_id = applicant_id + self.document_id = document_id + + @property + def url(self): + args = (self.applicant_id, self.year, self.document_id) + return ( + 'http://www.camara.gov.br/' + 'cota-parlamentar/documentos/publ/{}/{}/{}.pdf' + ).format(*args) + + @property + def exists(self): + status = head(self.url).status_code + return 200 <= status < 400 + + +class Reimbursement(models.Model): + document_id = models.IntegerField('Número do Reembolso', db_index=True, unique=True) + last_update = models.DateTimeField('Atualizado no Jarbas em', db_index=True, auto_now=True) + available_in_latest_dataset = models.BooleanField('Disponível na Câmara dos Deputados', default=True) + + year = models.IntegerField('Ano', db_index=True) + applicant_id = models.IntegerField('Identificador do Solicitante', db_index=True) + + total_reimbursement_value = models.DecimalField('Valor da Restituição', max_digits=10, decimal_places=3, blank=True, null=True) + total_net_value = models.DecimalField('Valor Líquido', max_digits=10, decimal_places=3) + reimbursement_numbers = models.CharField('Números dos Ressarcimentos', max_length=140) + net_values = models.CharField('Valores Líquidos dos Ressarcimentos', max_length=140) + + congressperson_id = models.IntegerField('Identificador Único do Parlamentar', blank=True, null=True) + congressperson_name = models.CharField('Nome do Parlamentar', max_length=140, db_index=True, blank=True, null=True) + congressperson_document = models.IntegerField('Número da Carteira Parlamentar', blank=True, null=True) + + party = models.CharField('Partido', max_length=7, blank=True, null=True) + state = models.CharField('UF', max_length=2, db_index=True, blank=True, null=True) + + term_id = models.IntegerField('Código da Legislatura', blank=True, null=True) + term = models.IntegerField('Número da Legislatura', blank=True, null=True) + + subquota_id = models.IntegerField('Número da Subcota', db_index=True) + subquota_description = models.CharField('Descrição da Subcota', max_length=140, db_index=True) + subquota_group_id = models.IntegerField('Número da Especificação da Subcota', blank=True, null=True) + subquota_group_description = models.CharField('Descrição da Especificação da Subcota', max_length=140, blank=True, null=True) + + supplier = models.CharField('Fornecedor', max_length=140) + cnpj_cpf = models.CharField('CNPJ ou CPF', max_length=14, db_index=True, blank=True, null=True) + + document_type = models.IntegerField('Indicativo de Tipo de Documento Fiscal') + document_number = models.CharField('Número do Documento', max_length=140, blank=True, null=True) + document_value = models.DecimalField('Valor do Documento', max_digits=10, decimal_places=3) + + issue_date = models.DateField('Data de Emissão', db_index=True) + month = models.IntegerField('Mês', db_index=True) + remark_value = models.DecimalField('Valor da Glosa', max_digits=10, decimal_places=3, blank=True, null=True) + installment = models.IntegerField('Número da Parcela', blank=True, null=True) + batch_number = models.IntegerField('Número do Lote') + reimbursement_values = models.CharField('Valores dos Ressarcimentos', max_length=140, blank=True, null=True) + + passenger = models.CharField('Passageiro', max_length=140, blank=True, null=True) + leg_of_the_trip = models.CharField('Trecho', max_length=140, blank=True, null=True) + + probability = models.DecimalField('Probabilidade', max_digits=6, decimal_places=5, blank=True, null=True) + suspicions = JSONField('Suspeitas', blank=True, null=True) + + receipt_fetched = models.BooleanField('Tentamos acessar a URL do documento fiscal?', default=False, db_index=True) + receipt_url = models.CharField('URL do Documento Fiscal', max_length=140, blank=True, null=True) + receipt_text = models.TextField('Texto do Recibo', blank=True, null=True) + + search_vector = SearchVectorField(null=True) + + history = HistoricalRecords() + + objects = models.Manager.from_queryset(ReimbursementQuerySet)() + + class Meta: + ordering = ('-year', '-issue_date') + verbose_name = 'reembolso' + verbose_name_plural = 'reembolsos' + index_together = [['year', 'issue_date', 'id']] + indexes = [GinIndex(fields=['search_vector'])] + + def get_receipt_url(self, force=False, bulk=False): + if self.receipt_url: + return self.receipt_url + + if self.receipt_fetched and not force: + return None + + receipt = Receipt(self.year, self.applicant_id, self.document_id) + if receipt.exists: + self.receipt_url = receipt.url + self.receipt_fetched = True + + if bulk: + return self + + self.save() + return self.receipt_url + + @property + def all_net_values(self): + return self.as_list(self.net_values, float) + + @property + def all_reimbursement_values(self): + return self.as_list(self.reimbursement_values, float) + + @property + def all_reimbursement_numbers(self): + return self.as_list(self.reimbursement_numbers, int) + + @staticmethod + def as_list(content, cast=None): + if not content: + return None + + parts = content.split(',') + return [cast(p) for p in parts] if cast else parts + + def __repr__(self): + return 'Reimbursement(document_id={})'.format(self.document_id) + + def __str__(self): + return 'Documento nº {}'.format(self.document_id) + + +class Tweet(models.Model): + + reimbursement = models.OneToOneField(Reimbursement) + status = models.DecimalField('Tweet ID', db_index=True, max_digits=25, decimal_places=0) + + def get_url(self): + base_url = 'https://twitter.com/RosieDaSerenata/status/' + return base_url + str(self.status) + + def __str__(self): + return self.get_url() + + def __repr__(self): + return ''.format(self.status) + + class Meta: + ordering = ('-status',) diff --git a/jarbas/core/models.py b/jarbas/core/models.py index aa97a3e..e21db5b 100644 --- a/jarbas/core/models.py +++ b/jarbas/core/models.py @@ -1,142 +1,4 @@ -from django.contrib.postgres.fields import JSONField -from django.contrib.postgres.indexes import GinIndex -from django.contrib.postgres.search import SearchVectorField from django.db import models -from requests import head -from simple_history.models import HistoricalRecords - -from jarbas.core.querysets import ReimbursementQuerySet - - -class Receipt: - - def __init__(self, year, applicant_id, document_id): - self.year = year - self.applicant_id = applicant_id - self.document_id = document_id - - @property - def url(self): - args = (self.applicant_id, self.year, self.document_id) - return ( - 'http://www.camara.gov.br/' - 'cota-parlamentar/documentos/publ/{}/{}/{}.pdf' - ).format(*args) - - @property - def exists(self): - status = head(self.url).status_code - return 200 <= status < 400 - - -class Reimbursement(models.Model): - document_id = models.IntegerField('Número do Reembolso', db_index=True, unique=True) - last_update = models.DateTimeField('Atualizado no Jarbas em', db_index=True, auto_now=True) - available_in_latest_dataset = models.BooleanField('Disponível na Câmara dos Deputados', default=True) - - year = models.IntegerField('Ano', db_index=True) - applicant_id = models.IntegerField('Identificador do Solicitante', db_index=True) - - total_reimbursement_value = models.DecimalField('Valor da Restituição', max_digits=10, decimal_places=3, blank=True, null=True) - total_net_value = models.DecimalField('Valor Líquido', max_digits=10, decimal_places=3) - reimbursement_numbers = models.CharField('Números dos Ressarcimentos', max_length=140) - net_values = models.CharField('Valores Líquidos dos Ressarcimentos', max_length=140) - - congressperson_id = models.IntegerField('Identificador Único do Parlamentar', blank=True, null=True) - congressperson_name = models.CharField('Nome do Parlamentar', max_length=140, db_index=True, blank=True, null=True) - congressperson_document = models.IntegerField('Número da Carteira Parlamentar', blank=True, null=True) - - party = models.CharField('Partido', max_length=7, blank=True, null=True) - state = models.CharField('UF', max_length=2, db_index=True, blank=True, null=True) - - term_id = models.IntegerField('Código da Legislatura', blank=True, null=True) - term = models.IntegerField('Número da Legislatura', blank=True, null=True) - - subquota_id = models.IntegerField('Número da Subcota', db_index=True) - subquota_description = models.CharField('Descrição da Subcota', max_length=140, db_index=True) - subquota_group_id = models.IntegerField('Número da Especificação da Subcota', blank=True, null=True) - subquota_group_description = models.CharField('Descrição da Especificação da Subcota', max_length=140, blank=True, null=True) - - supplier = models.CharField('Fornecedor', max_length=140) - cnpj_cpf = models.CharField('CNPJ ou CPF', max_length=14, db_index=True, blank=True, null=True) - - document_type = models.IntegerField('Indicativo de Tipo de Documento Fiscal') - document_number = models.CharField('Número do Documento', max_length=140, blank=True, null=True) - document_value = models.DecimalField('Valor do Documento', max_digits=10, decimal_places=3) - - issue_date = models.DateField('Data de Emissão', db_index=True) - month = models.IntegerField('Mês', db_index=True) - remark_value = models.DecimalField('Valor da Glosa', max_digits=10, decimal_places=3, blank=True, null=True) - installment = models.IntegerField('Número da Parcela', blank=True, null=True) - batch_number = models.IntegerField('Número do Lote') - reimbursement_values = models.CharField('Valores dos Ressarcimentos', max_length=140, blank=True, null=True) - - passenger = models.CharField('Passageiro', max_length=140, blank=True, null=True) - leg_of_the_trip = models.CharField('Trecho', max_length=140, blank=True, null=True) - - probability = models.DecimalField('Probabilidade', max_digits=6, decimal_places=5, blank=True, null=True) - suspicions = JSONField('Suspeitas', blank=True, null=True) - - receipt_fetched = models.BooleanField('Tentamos acessar a URL do documento fiscal?', default=False, db_index=True) - receipt_url = models.CharField('URL do Documento Fiscal', max_length=140, blank=True, null=True) - receipt_text = models.TextField('Texto do Recibo', blank=True, null=True) - - search_vector = SearchVectorField(null=True) - - history = HistoricalRecords() - - objects = models.Manager.from_queryset(ReimbursementQuerySet)() - - class Meta: - ordering = ('-year', '-issue_date') - verbose_name = 'reembolso' - verbose_name_plural = 'reembolsos' - index_together = [['year', 'issue_date', 'id']] - indexes = [GinIndex(fields=['search_vector'])] - - def get_receipt_url(self, force=False, bulk=False): - if self.receipt_url: - return self.receipt_url - - if self.receipt_fetched and not force: - return None - - receipt = Receipt(self.year, self.applicant_id, self.document_id) - if receipt.exists: - self.receipt_url = receipt.url - self.receipt_fetched = True - - if bulk: - return self - - self.save() - return self.receipt_url - - @property - def all_net_values(self): - return self.as_list(self.net_values, float) - - @property - def all_reimbursement_values(self): - return self.as_list(self.reimbursement_values, float) - - @property - def all_reimbursement_numbers(self): - return self.as_list(self.reimbursement_numbers, int) - - @staticmethod - def as_list(content, cast=None): - if not content: - return None - - parts = content.split(',') - return [cast(p) for p in parts] if cast else parts - - def __repr__(self): - return 'Reimbursement(document_id={})'.format(self.document_id) - - def __str__(self): - return 'Documento nº {}'.format(self.document_id) class Activity(models.Model): @@ -180,22 +42,3 @@ class Company(models.Model): longitude = models.DecimalField('Longitude', decimal_places=7, max_digits=10, blank=True, null=True) last_updated = models.DateTimeField('Last updated', blank=True, null=True) - - -class Tweet(models.Model): - - reimbursement = models.OneToOneField(Reimbursement) - status = models.DecimalField('Tweet ID', db_index=True, max_digits=25, decimal_places=0) - - def get_url(self): - base_url = 'https://twitter.com/RosieDaSerenata/status/' - return base_url + str(self.status) - - def __str__(self): - return self.get_url() - - def __repr__(self): - return ''.format(self.status) - - class Meta: - ordering = ('-status',) From 57d33d09285b0a544f56596ef76692234e060ff4 Mon Sep 17 00:00:00 2001 From: Giovani Date: Sat, 14 Oct 2017 05:01:44 -0300 Subject: [PATCH 04/34] Register the new app chamber_of_deputies --- jarbas/settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/jarbas/settings.py b/jarbas/settings.py index 6163c45..b899485 100644 --- a/jarbas/settings.py +++ b/jarbas/settings.py @@ -45,6 +45,7 @@ 'simple_history', 'rest_framework', 'jarbas.core.app.CoreConfig', + 'jarbas.chamber_of_deputies.app.ChamberOfDeputiesConfig', 'jarbas.api', 'jarbas.frontend', 'jarbas.dashboard', From 10b401e50704b18a118d826e3d0c1d5b188ddb73 Mon Sep 17 00:00:00 2001 From: Giovani Date: Sat, 14 Oct 2017 05:02:15 -0300 Subject: [PATCH 05/34] migrations of the new models --- .../migrations/0001_initial.py | 149 ++++++++++++++++++ .../migrations/0041_auto_20171014_0445.py | 32 ++++ 2 files changed, 181 insertions(+) create mode 100644 jarbas/chamber_of_deputies/migrations/0001_initial.py create mode 100644 jarbas/core/migrations/0041_auto_20171014_0445.py diff --git a/jarbas/chamber_of_deputies/migrations/0001_initial.py b/jarbas/chamber_of_deputies/migrations/0001_initial.py new file mode 100644 index 0000000..0f5056d --- /dev/null +++ b/jarbas/chamber_of_deputies/migrations/0001_initial.py @@ -0,0 +1,149 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.5 on 2017-10-14 07:45 +from __future__ import unicode_literals + +from django.conf import settings +import django.contrib.postgres.fields.jsonb +import django.contrib.postgres.indexes +import django.contrib.postgres.search +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='HistoricalReimbursement', + fields=[ + ('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')), + ('document_id', models.IntegerField(db_index=True, verbose_name='Número do Reembolso')), + ('last_update', models.DateTimeField(blank=True, db_index=True, editable=False, verbose_name='Atualizado no Jarbas em')), + ('available_in_latest_dataset', models.BooleanField(default=True, verbose_name='Disponível na Câmara dos Deputados')), + ('year', models.IntegerField(db_index=True, verbose_name='Ano')), + ('applicant_id', models.IntegerField(db_index=True, verbose_name='Identificador do Solicitante')), + ('total_reimbursement_value', models.DecimalField(blank=True, decimal_places=3, max_digits=10, null=True, verbose_name='Valor da Restituição')), + ('total_net_value', models.DecimalField(decimal_places=3, max_digits=10, verbose_name='Valor Líquido')), + ('reimbursement_numbers', models.CharField(max_length=140, verbose_name='Números dos Ressarcimentos')), + ('net_values', models.CharField(max_length=140, verbose_name='Valores Líquidos dos Ressarcimentos')), + ('congressperson_id', models.IntegerField(blank=True, null=True, verbose_name='Identificador Único do Parlamentar')), + ('congressperson_name', models.CharField(blank=True, db_index=True, max_length=140, null=True, verbose_name='Nome do Parlamentar')), + ('congressperson_document', models.IntegerField(blank=True, null=True, verbose_name='Número da Carteira Parlamentar')), + ('party', models.CharField(blank=True, max_length=7, null=True, verbose_name='Partido')), + ('state', models.CharField(blank=True, db_index=True, max_length=2, null=True, verbose_name='UF')), + ('term_id', models.IntegerField(blank=True, null=True, verbose_name='Código da Legislatura')), + ('term', models.IntegerField(blank=True, null=True, verbose_name='Número da Legislatura')), + ('subquota_id', models.IntegerField(db_index=True, verbose_name='Número da Subcota')), + ('subquota_description', models.CharField(db_index=True, max_length=140, verbose_name='Descrição da Subcota')), + ('subquota_group_id', models.IntegerField(blank=True, null=True, verbose_name='Número da Especificação da Subcota')), + ('subquota_group_description', models.CharField(blank=True, max_length=140, null=True, verbose_name='Descrição da Especificação da Subcota')), + ('supplier', models.CharField(max_length=140, verbose_name='Fornecedor')), + ('cnpj_cpf', models.CharField(blank=True, db_index=True, max_length=14, null=True, verbose_name='CNPJ ou CPF')), + ('document_type', models.IntegerField(verbose_name='Indicativo de Tipo de Documento Fiscal')), + ('document_number', models.CharField(blank=True, max_length=140, null=True, verbose_name='Número do Documento')), + ('document_value', models.DecimalField(decimal_places=3, max_digits=10, verbose_name='Valor do Documento')), + ('issue_date', models.DateField(db_index=True, verbose_name='Data de Emissão')), + ('month', models.IntegerField(db_index=True, verbose_name='Mês')), + ('remark_value', models.DecimalField(blank=True, decimal_places=3, max_digits=10, null=True, verbose_name='Valor da Glosa')), + ('installment', models.IntegerField(blank=True, null=True, verbose_name='Número da Parcela')), + ('batch_number', models.IntegerField(verbose_name='Número do Lote')), + ('reimbursement_values', models.CharField(blank=True, max_length=140, null=True, verbose_name='Valores dos Ressarcimentos')), + ('passenger', models.CharField(blank=True, max_length=140, null=True, verbose_name='Passageiro')), + ('leg_of_the_trip', models.CharField(blank=True, max_length=140, null=True, verbose_name='Trecho')), + ('probability', models.DecimalField(blank=True, decimal_places=5, max_digits=6, null=True, verbose_name='Probabilidade')), + ('suspicions', django.contrib.postgres.fields.jsonb.JSONField(blank=True, null=True, verbose_name='Suspeitas')), + ('receipt_fetched', models.BooleanField(db_index=True, default=False, verbose_name='Tentamos acessar a URL do documento fiscal?')), + ('receipt_url', models.CharField(blank=True, max_length=140, null=True, verbose_name='URL do Documento Fiscal')), + ('receipt_text', models.TextField(blank=True, null=True, verbose_name='Texto do Recibo')), + ('search_vector', django.contrib.postgres.search.SearchVectorField(null=True)), + ('history_id', models.AutoField(primary_key=True, serialize=False)), + ('history_date', models.DateTimeField()), + ('history_type', models.CharField(choices=[('+', 'Criado'), ('~', 'Modificado'), ('-', 'Excluído')], max_length=1)), + ], + options={ + 'get_latest_by': 'history_date', + 'ordering': ('-history_date', '-history_id'), + 'verbose_name': 'historical reembolso', + }, + ), + migrations.CreateModel( + name='Reimbursement', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('document_id', models.IntegerField(db_index=True, unique=True, verbose_name='Número do Reembolso')), + ('last_update', models.DateTimeField(auto_now=True, db_index=True, verbose_name='Atualizado no Jarbas em')), + ('available_in_latest_dataset', models.BooleanField(default=True, verbose_name='Disponível na Câmara dos Deputados')), + ('year', models.IntegerField(db_index=True, verbose_name='Ano')), + ('applicant_id', models.IntegerField(db_index=True, verbose_name='Identificador do Solicitante')), + ('total_reimbursement_value', models.DecimalField(blank=True, decimal_places=3, max_digits=10, null=True, verbose_name='Valor da Restituição')), + ('total_net_value', models.DecimalField(decimal_places=3, max_digits=10, verbose_name='Valor Líquido')), + ('reimbursement_numbers', models.CharField(max_length=140, verbose_name='Números dos Ressarcimentos')), + ('net_values', models.CharField(max_length=140, verbose_name='Valores Líquidos dos Ressarcimentos')), + ('congressperson_id', models.IntegerField(blank=True, null=True, verbose_name='Identificador Único do Parlamentar')), + ('congressperson_name', models.CharField(blank=True, db_index=True, max_length=140, null=True, verbose_name='Nome do Parlamentar')), + ('congressperson_document', models.IntegerField(blank=True, null=True, verbose_name='Número da Carteira Parlamentar')), + ('party', models.CharField(blank=True, max_length=7, null=True, verbose_name='Partido')), + ('state', models.CharField(blank=True, db_index=True, max_length=2, null=True, verbose_name='UF')), + ('term_id', models.IntegerField(blank=True, null=True, verbose_name='Código da Legislatura')), + ('term', models.IntegerField(blank=True, null=True, verbose_name='Número da Legislatura')), + ('subquota_id', models.IntegerField(db_index=True, verbose_name='Número da Subcota')), + ('subquota_description', models.CharField(db_index=True, max_length=140, verbose_name='Descrição da Subcota')), + ('subquota_group_id', models.IntegerField(blank=True, null=True, verbose_name='Número da Especificação da Subcota')), + ('subquota_group_description', models.CharField(blank=True, max_length=140, null=True, verbose_name='Descrição da Especificação da Subcota')), + ('supplier', models.CharField(max_length=140, verbose_name='Fornecedor')), + ('cnpj_cpf', models.CharField(blank=True, db_index=True, max_length=14, null=True, verbose_name='CNPJ ou CPF')), + ('document_type', models.IntegerField(verbose_name='Indicativo de Tipo de Documento Fiscal')), + ('document_number', models.CharField(blank=True, max_length=140, null=True, verbose_name='Número do Documento')), + ('document_value', models.DecimalField(decimal_places=3, max_digits=10, verbose_name='Valor do Documento')), + ('issue_date', models.DateField(db_index=True, verbose_name='Data de Emissão')), + ('month', models.IntegerField(db_index=True, verbose_name='Mês')), + ('remark_value', models.DecimalField(blank=True, decimal_places=3, max_digits=10, null=True, verbose_name='Valor da Glosa')), + ('installment', models.IntegerField(blank=True, null=True, verbose_name='Número da Parcela')), + ('batch_number', models.IntegerField(verbose_name='Número do Lote')), + ('reimbursement_values', models.CharField(blank=True, max_length=140, null=True, verbose_name='Valores dos Ressarcimentos')), + ('passenger', models.CharField(blank=True, max_length=140, null=True, verbose_name='Passageiro')), + ('leg_of_the_trip', models.CharField(blank=True, max_length=140, null=True, verbose_name='Trecho')), + ('probability', models.DecimalField(blank=True, decimal_places=5, max_digits=6, null=True, verbose_name='Probabilidade')), + ('suspicions', django.contrib.postgres.fields.jsonb.JSONField(blank=True, null=True, verbose_name='Suspeitas')), + ('receipt_fetched', models.BooleanField(db_index=True, default=False, verbose_name='Tentamos acessar a URL do documento fiscal?')), + ('receipt_url', models.CharField(blank=True, max_length=140, null=True, verbose_name='URL do Documento Fiscal')), + ('receipt_text', models.TextField(blank=True, null=True, verbose_name='Texto do Recibo')), + ('search_vector', django.contrib.postgres.search.SearchVectorField(null=True)), + ], + options={ + 'verbose_name_plural': 'reembolsos', + 'ordering': ('-year', '-issue_date'), + 'verbose_name': 'reembolso', + }, + ), + migrations.CreateModel( + name='Tweet', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('status', models.DecimalField(db_index=True, decimal_places=0, max_digits=25, verbose_name='Tweet ID')), + ('reimbursement', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='chamber_of_deputies.Reimbursement')), + ], + options={ + 'ordering': ('-status',), + }, + ), + migrations.AddIndex( + model_name='reimbursement', + index=django.contrib.postgres.indexes.GinIndex(fields=['search_vector'], name='chamber_of__search__10d8b3_gin'), + ), + migrations.AlterIndexTogether( + name='reimbursement', + index_together=set([('year', 'issue_date', 'id')]), + ), + migrations.AddField( + model_name='historicalreimbursement', + name='history_user', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/jarbas/core/migrations/0041_auto_20171014_0445.py b/jarbas/core/migrations/0041_auto_20171014_0445.py new file mode 100644 index 0000000..2ffb0da --- /dev/null +++ b/jarbas/core/migrations/0041_auto_20171014_0445.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.5 on 2017-10-14 07:45 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0040_create_gin_index_with_search_vector'), + ] + + operations = [ + migrations.RemoveField( + model_name='historicalreimbursement', + name='history_user', + ), + migrations.DeleteModel( + name='Reimbursement', + ), + migrations.RemoveField( + model_name='tweet', + name='reimbursement', + ), + migrations.DeleteModel( + name='HistoricalReimbursement', + ), + migrations.DeleteModel( + name='Tweet', + ), + ] From e2417db03144443d8d40916a5a72e4ec881746af Mon Sep 17 00:00:00 2001 From: Giovani Date: Sat, 14 Oct 2017 05:08:36 -0300 Subject: [PATCH 06/34] Fix models import paths --- jarbas/api/serializers.py | 3 ++- jarbas/api/tests/test_applicant_view.py | 2 +- jarbas/api/tests/test_reimbursement_view.py | 8 ++++---- jarbas/api/tests/test_same_day_view.py | 3 ++- jarbas/api/tests/test_subquota_view.py | 2 +- jarbas/api/views.py | 3 ++- jarbas/core/management/commands/receipts.py | 2 +- jarbas/core/management/commands/receipts_text.py | 2 +- .../core/management/commands/reimbursements.py | 2 +- jarbas/core/management/commands/searchvector.py | 2 +- jarbas/core/management/commands/suspicions.py | 2 +- jarbas/core/management/commands/tweets.py | 2 +- jarbas/core/tests/__init__.py | 2 +- jarbas/core/tests/test_receipt_class.py | 8 ++++---- jarbas/core/tests/test_receipts_text_command.py | 2 +- jarbas/core/tests/test_reimbursement_model.py | 16 ++++++++-------- jarbas/core/tests/test_reimbursements_command.py | 2 +- jarbas/core/tests/test_searchvector_command.py | 2 +- jarbas/core/tests/test_suspicions_command.py | 2 +- jarbas/core/tests/test_tweet_model.py | 2 +- jarbas/core/tests/test_tweets_command.py | 2 +- jarbas/dashboard/admin.py | 2 +- jarbas/dashboard/tests/test_dashboard_admin.py | 2 +- jarbas/dashboard/tests/test_dashboard_view.py | 8 ++++---- 24 files changed, 43 insertions(+), 40 deletions(-) diff --git a/jarbas/api/serializers.py b/jarbas/api/serializers.py index 3844f62..3acf352 100644 --- a/jarbas/api/serializers.py +++ b/jarbas/api/serializers.py @@ -1,6 +1,7 @@ from rest_framework import serializers -from jarbas.core.models import Activity, Reimbursement, Company +from jarbas.chamber_of_deputies.models import Reimbursement +from jarbas.core.models import Activity, Company class ReimbursementSerializer(serializers.ModelSerializer): diff --git a/jarbas/api/tests/test_applicant_view.py b/jarbas/api/tests/test_applicant_view.py index 95883e0..0b81c17 100644 --- a/jarbas/api/tests/test_applicant_view.py +++ b/jarbas/api/tests/test_applicant_view.py @@ -4,7 +4,7 @@ from django.shortcuts import resolve_url from django.test import TestCase -from jarbas.core.models import Reimbursement +from jarbas.chamber_of_deputies.models import Reimbursement from jarbas.core.tests import sample_reimbursement_data diff --git a/jarbas/api/tests/test_reimbursement_view.py b/jarbas/api/tests/test_reimbursement_view.py index eefc042..d302056 100644 --- a/jarbas/api/tests/test_reimbursement_view.py +++ b/jarbas/api/tests/test_reimbursement_view.py @@ -8,7 +8,7 @@ from mixer.backend.django import mixer from jarbas.api.tests import get_sample_reimbursement_api_response -from jarbas.core.models import Reimbursement, Tweet +from jarbas.chamber_of_deputies.models import Reimbursement, Tweet from jarbas.core.tests import random_tweet_status @@ -154,7 +154,7 @@ def setUp(self): self.url_no_receipt = resolve_url( 'api:reimbursement-receipt', document_id=self.reimbursement_no_receipt.document_id) - @patch('jarbas.core.models.head') + @patch('jarbas.chamber_of_deputies.models.head') def test_fetch_existing_receipt(self, mocked_head): mocked_head.return_value.status_code = 200 resp = self.client.get(self.url) @@ -162,7 +162,7 @@ def test_fetch_existing_receipt(self, mocked_head): content = loads(resp.content.decode('utf-8')) self.assertEqual(expected, content) - @patch('jarbas.core.models.head') + @patch('jarbas.chamber_of_deputies.models.head') def test_fetch_non_existing_receipt(self, mocked_head): mocked_head.return_value.status_code = 404 resp = self.client.get(self.url_no_receipt) @@ -170,7 +170,7 @@ def test_fetch_non_existing_receipt(self, mocked_head): content = loads(resp.content.decode('utf-8')) self.assertEqual(expected, content) - @patch('jarbas.core.models.head') + @patch('jarbas.chamber_of_deputies.models.head') def test_refetch_existing_receipt(self, mocked_head): expected = dict(url=self.reimbursement.receipt_url) self.reimbursement.receipt_fetched = True diff --git a/jarbas/api/tests/test_same_day_view.py b/jarbas/api/tests/test_same_day_view.py index bf57c7e..f3fcad5 100644 --- a/jarbas/api/tests/test_same_day_view.py +++ b/jarbas/api/tests/test_same_day_view.py @@ -3,7 +3,8 @@ from django.shortcuts import resolve_url from django.test import TestCase -from jarbas.core.models import Company, Reimbursement +from jarbas.chamber_of_deputies.models import Reimbursement +from jarbas.core.models import Company from jarbas.core.tests import sample_company_data, sample_reimbursement_data from jarbas.api.serializers import format_cnpj diff --git a/jarbas/api/tests/test_subquota_view.py b/jarbas/api/tests/test_subquota_view.py index 0426c25..a76adbf 100644 --- a/jarbas/api/tests/test_subquota_view.py +++ b/jarbas/api/tests/test_subquota_view.py @@ -4,7 +4,7 @@ from django.shortcuts import resolve_url from django.test import TestCase -from jarbas.core.models import Reimbursement +from jarbas.chamber_of_deputies.models import Reimbursement from jarbas.core.tests import sample_reimbursement_data diff --git a/jarbas/api/views.py b/jarbas/api/views.py index 932ba3e..e95ce2f 100644 --- a/jarbas/api/views.py +++ b/jarbas/api/views.py @@ -2,7 +2,8 @@ from rest_framework.generics import ListAPIView, RetrieveAPIView from jarbas.api import serializers -from jarbas.core.models import Reimbursement, Company +from jarbas.chamber_of_deputies.models import Reimbursement +from jarbas.core.models import Company class ReimbursementListView(ListAPIView): diff --git a/jarbas/core/management/commands/receipts.py b/jarbas/core/management/commands/receipts.py index dcb034e..329f353 100644 --- a/jarbas/core/management/commands/receipts.py +++ b/jarbas/core/management/commands/receipts.py @@ -5,7 +5,7 @@ from django.core.management.base import BaseCommand from requests.exceptions import ConnectionError -from jarbas.core.models import Reimbursement +from jarbas.chamber_of_deputies.models import Reimbursement class Command(BaseCommand): diff --git a/jarbas/core/management/commands/receipts_text.py b/jarbas/core/management/commands/receipts_text.py index f115f74..078d287 100644 --- a/jarbas/core/management/commands/receipts_text.py +++ b/jarbas/core/management/commands/receipts_text.py @@ -6,7 +6,7 @@ from bulk_update.helper import bulk_update from jarbas.core.management.commands import LoadCommand -from jarbas.core.models import Reimbursement +from jarbas.chamber_of_deputies.models import Reimbursement class Command(LoadCommand): diff --git a/jarbas/core/management/commands/reimbursements.py b/jarbas/core/management/commands/reimbursements.py index f788a7c..9407982 100644 --- a/jarbas/core/management/commands/reimbursements.py +++ b/jarbas/core/management/commands/reimbursements.py @@ -5,7 +5,7 @@ from reprint import output from jarbas.core.management.commands import LoadCommand -from jarbas.core.models import Reimbursement +from jarbas.chamber_of_deputies.models import Reimbursement class Command(LoadCommand): diff --git a/jarbas/core/management/commands/searchvector.py b/jarbas/core/management/commands/searchvector.py index 514f34a..5727ba7 100644 --- a/jarbas/core/management/commands/searchvector.py +++ b/jarbas/core/management/commands/searchvector.py @@ -1,7 +1,7 @@ from django.core.management.base import BaseCommand from django.contrib.postgres.search import SearchVector -from jarbas.core.models import Reimbursement +from jarbas.chamber_of_deputies.models import Reimbursement class Command(BaseCommand): diff --git a/jarbas/core/management/commands/suspicions.py b/jarbas/core/management/commands/suspicions.py index 32d3e7c..8a7f2bb 100644 --- a/jarbas/core/management/commands/suspicions.py +++ b/jarbas/core/management/commands/suspicions.py @@ -6,7 +6,7 @@ from bulk_update.helper import bulk_update from jarbas.core.management.commands import LoadCommand -from jarbas.core.models import Reimbursement +from jarbas.chamber_of_deputies.models import Reimbursement class Command(LoadCommand): diff --git a/jarbas/core/management/commands/tweets.py b/jarbas/core/management/commands/tweets.py index 9055cb1..0bf0d5b 100644 --- a/jarbas/core/management/commands/tweets.py +++ b/jarbas/core/management/commands/tweets.py @@ -5,7 +5,7 @@ from django.conf import settings from django.core.management.base import BaseCommand -from jarbas.core.models import Reimbursement, Tweet +from jarbas.chamber_of_deputies.models import Reimbursement, Tweet class Command(BaseCommand): diff --git a/jarbas/core/tests/__init__.py b/jarbas/core/tests/__init__.py index bb2d13a..2feab47 100644 --- a/jarbas/core/tests/__init__.py +++ b/jarbas/core/tests/__init__.py @@ -3,7 +3,7 @@ from django.utils import timezone -from jarbas.core.models import Tweet +from jarbas.chamber_of_deputies.models import Tweet suspicions = { diff --git a/jarbas/core/tests/test_receipt_class.py b/jarbas/core/tests/test_receipt_class.py index 60ab91f..3318cf7 100644 --- a/jarbas/core/tests/test_receipt_class.py +++ b/jarbas/core/tests/test_receipt_class.py @@ -3,7 +3,7 @@ from django.test import TestCase from requests.exceptions import ConnectionError -from jarbas.core.models import Receipt +from jarbas.chamber_of_deputies.models import Receipt class TestReceipt(TestCase): @@ -15,17 +15,17 @@ def test_url(self): expected = 'http://www.camara.gov.br/cota-parlamentar/documentos/publ/13/1970/42.pdf' self.assertEqual(expected, self.receipt.url) - @patch('jarbas.core.models.head') + @patch('jarbas.chamber_of_deputies.models.head') def test_existing_url(self, mocked_head): mocked_head.return_value.status_code = 200 self.assertTrue(self.receipt.exists) - @patch('jarbas.core.models.head') + @patch('jarbas.chamber_of_deputies.models.head') def test_no_existing_url(self, mocked_head): mocked_head.return_value.status_code = 404 self.assertFalse(self.receipt.exists) - @patch('jarbas.core.models.head') + @patch('jarbas.chamber_of_deputies.models.head') def test_connection_error(self, mocked_head): mocked_head.side_effect = ConnectionError with self.assertRaises(ConnectionError): diff --git a/jarbas/core/tests/test_receipts_text_command.py b/jarbas/core/tests/test_receipts_text_command.py index 56fc4a2..d4749f1 100644 --- a/jarbas/core/tests/test_receipts_text_command.py +++ b/jarbas/core/tests/test_receipts_text_command.py @@ -4,7 +4,7 @@ from django.test import TestCase from jarbas.core.management.commands.receipts_text import Command -from jarbas.core.models import Reimbursement +from jarbas.chamber_of_deputies.models import Reimbursement class TestCommand(TestCase): diff --git a/jarbas/core/tests/test_reimbursement_model.py b/jarbas/core/tests/test_reimbursement_model.py index 07a3516..4838ca3 100644 --- a/jarbas/core/tests/test_reimbursement_model.py +++ b/jarbas/core/tests/test_reimbursement_model.py @@ -4,7 +4,7 @@ from django.test import TestCase from requests.exceptions import ConnectionError -from jarbas.core.models import Reimbursement +from jarbas.chamber_of_deputies.models import Reimbursement from jarbas.core.tests import sample_reimbursement_data @@ -204,7 +204,7 @@ def test_url_is_none(self): self.assertIsNone(self.obj.receipt_url) self.assertFalse(self.obj.receipt_fetched) - @patch('jarbas.core.models.head') + @patch('jarbas.chamber_of_deputies.models.head') def test_get_existing_url(self, mocked_head): mocked_head.return_value.status_code = 200 self.assertEqual(self.expected_receipt_url, self.obj.get_receipt_url()) @@ -212,7 +212,7 @@ def test_get_existing_url(self, mocked_head): self.assertTrue(self.obj.receipt_fetched) mocked_head.assert_called_once_with(self.expected_receipt_url) - @patch('jarbas.core.models.head') + @patch('jarbas.chamber_of_deputies.models.head') def test_get_non_existing_url(self, mocked_head): mocked_head.return_value.status_code = 404 self.assertIsNone(self.obj.get_receipt_url()) @@ -220,13 +220,13 @@ def test_get_non_existing_url(self, mocked_head): self.assertTrue(self.obj.receipt_fetched) mocked_head.assert_called_once_with(self.expected_receipt_url) - @patch('jarbas.core.models.head') + @patch('jarbas.chamber_of_deputies.models.head') def test_get_non_existing_url_with_error(self, mocked_head): mocked_head.side_effect = ConnectionError with self.assertRaises(ConnectionError): self.obj.get_receipt_url() - @patch('jarbas.core.models.head') + @patch('jarbas.chamber_of_deputies.models.head') def test_get_fetched_existing_url(self, mocked_head): self.obj.receipt_fetched = True self.obj.receipt_url = '42' @@ -236,7 +236,7 @@ def test_get_fetched_existing_url(self, mocked_head): self.assertTrue(self.obj.receipt_fetched) mocked_head.assert_not_called() - @patch('jarbas.core.models.head') + @patch('jarbas.chamber_of_deputies.models.head') def test_get_fetched_non_existing_url(self, mocked_head): self.obj.receipt_fetched = True self.obj.receipt_url = None @@ -246,7 +246,7 @@ def test_get_fetched_non_existing_url(self, mocked_head): self.assertTrue(self.obj.receipt_fetched) mocked_head.assert_not_called() - @patch('jarbas.core.models.head') + @patch('jarbas.chamber_of_deputies.models.head') def test_force_get_receipt_url(self, mocked_head): mocked_head.return_value.status_code = 200 self.obj.receipt_fetched = True @@ -260,7 +260,7 @@ def test_force_get_receipt_url(self, mocked_head): self.assertTrue(self.obj.receipt_fetched) mocked_head.assert_called_once_with(self.expected_receipt_url) - @patch('jarbas.core.models.head') + @patch('jarbas.chamber_of_deputies.models.head') def test_bulk_get_receipt_url(self, mocked_head): mocked_head.return_value.status_code = 200 updated = self.obj.get_receipt_url(bulk=True) diff --git a/jarbas/core/tests/test_reimbursements_command.py b/jarbas/core/tests/test_reimbursements_command.py index 998bf90..8f4dfcc 100644 --- a/jarbas/core/tests/test_reimbursements_command.py +++ b/jarbas/core/tests/test_reimbursements_command.py @@ -5,7 +5,7 @@ from django.test import TestCase from jarbas.core.management.commands.reimbursements import Command -from jarbas.core.models import Reimbursement +from jarbas.chamber_of_deputies.models import Reimbursement class TestCommand(TestCase): diff --git a/jarbas/core/tests/test_searchvector_command.py b/jarbas/core/tests/test_searchvector_command.py index 2c7719d..6555fc9 100644 --- a/jarbas/core/tests/test_searchvector_command.py +++ b/jarbas/core/tests/test_searchvector_command.py @@ -3,7 +3,7 @@ from django.test import TestCase from jarbas.core.management.commands.searchvector import Command -from jarbas.core.models import Reimbursement +from jarbas.chamber_of_deputies.models import Reimbursement class TestCommandHandler(TestCase): diff --git a/jarbas/core/tests/test_suspicions_command.py b/jarbas/core/tests/test_suspicions_command.py index f14ea94..542978e 100644 --- a/jarbas/core/tests/test_suspicions_command.py +++ b/jarbas/core/tests/test_suspicions_command.py @@ -4,7 +4,7 @@ from django.test import TestCase from jarbas.core.management.commands.suspicions import Command -from jarbas.core.models import Reimbursement +from jarbas.chamber_of_deputies.models import Reimbursement class TestCommand(TestCase): diff --git a/jarbas/core/tests/test_tweet_model.py b/jarbas/core/tests/test_tweet_model.py index fb45dab..88a0149 100644 --- a/jarbas/core/tests/test_tweet_model.py +++ b/jarbas/core/tests/test_tweet_model.py @@ -1,7 +1,7 @@ from django.test import TestCase from mixer.backend.django import mixer -from jarbas.core.models import Tweet +from jarbas.chamber_of_deputies.models import Tweet class TestTweet(TestCase): diff --git a/jarbas/core/tests/test_tweets_command.py b/jarbas/core/tests/test_tweets_command.py index 4d5467b..c0e5d84 100644 --- a/jarbas/core/tests/test_tweets_command.py +++ b/jarbas/core/tests/test_tweets_command.py @@ -5,7 +5,7 @@ from django.test import TestCase from mixer.backend.django import mixer -from jarbas.core.models import Reimbursement, Tweet +from jarbas.chamber_of_deputies.models import Reimbursement, Tweet from jarbas.core.management.commands.tweets import Command from jarbas.core.tests import random_tweet_status diff --git a/jarbas/dashboard/admin.py b/jarbas/dashboard/admin.py index 298221b..10340c5 100644 --- a/jarbas/dashboard/admin.py +++ b/jarbas/dashboard/admin.py @@ -9,7 +9,7 @@ from django.forms.widgets import Widget from simple_history.admin import SimpleHistoryAdmin -from jarbas.core.models import Reimbursement +from jarbas.chamber_of_deputies.models import Reimbursement from jarbas.dashboard.sites import dashboard diff --git a/jarbas/dashboard/tests/test_dashboard_admin.py b/jarbas/dashboard/tests/test_dashboard_admin.py index 025816f..645bc67 100644 --- a/jarbas/dashboard/tests/test_dashboard_admin.py +++ b/jarbas/dashboard/tests/test_dashboard_admin.py @@ -3,7 +3,7 @@ from django.test import TestCase -from jarbas.core.models import Reimbursement +from jarbas.chamber_of_deputies.models import Reimbursement from jarbas.dashboard.admin import ( ReceiptUrlWidget, ReimbursementModelAdmin, diff --git a/jarbas/dashboard/tests/test_dashboard_view.py b/jarbas/dashboard/tests/test_dashboard_view.py index 5928d0e..0093501 100644 --- a/jarbas/dashboard/tests/test_dashboard_view.py +++ b/jarbas/dashboard/tests/test_dashboard_view.py @@ -4,7 +4,7 @@ from django.test import TestCase from mixer.backend.django import mixer -from jarbas.core.models import Reimbursement +from jarbas.chamber_of_deputies.models import Reimbursement class TestDashboard(TestCase): @@ -13,9 +13,9 @@ def setUp(self): obj = mixer.blend(Reimbursement, search_vector=None) self.urls = ( resolve_url('dashboard:index'), - resolve_url('dashboard:core_reimbursement_changelist'), - resolve_url('dashboard:core_reimbursement_change', obj.pk), - resolve_url('dashboard:core_reimbursement_history', obj.pk), + resolve_url('dashboard:chamber_of_deputies_reimbursement_changelist'), + resolve_url('dashboard:chamber_of_deputies_reimbursement_change', obj.pk), + resolve_url('dashboard:chamber_of_deputies_reimbursement_history', obj.pk), ) self.forbidden = ( '/login/', From 59bfd11f8db58eeeb8de6ba0072851c2eb496a47 Mon Sep 17 00:00:00 2001 From: Giovani Date: Sat, 14 Oct 2017 14:36:49 -0300 Subject: [PATCH 07/34] Add permission to dashboard access chamber of deputies Reimbursements --- jarbas/dashboard/sites.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jarbas/dashboard/sites.py b/jarbas/dashboard/sites.py index f78fd37..03d345d 100644 --- a/jarbas/dashboard/sites.py +++ b/jarbas/dashboard/sites.py @@ -10,10 +10,10 @@ class DummyUser(AnonymousUser): def has_module_perms(self, app_label): - return app_label == 'core' + return app_label == 'chamber_of_deputies' def has_perm(self, permission, obj=None): - return permission == 'core.change_reimbursement' + return permission == 'chamber_of_deputies.change_reimbursement' class DashboardSite(AdminSite): From 8bd4c92dd87df22cca46fe4df8df25662a9b226d Mon Sep 17 00:00:00 2001 From: Giovani Date: Sat, 14 Oct 2017 16:13:04 -0300 Subject: [PATCH 08/34] Remove unused files from chamber_of_deputies app --- jarbas/chamber_of_deputies/admin.py | 3 --- jarbas/chamber_of_deputies/tests.py | 3 --- jarbas/chamber_of_deputies/views.py | 3 --- 3 files changed, 9 deletions(-) delete mode 100644 jarbas/chamber_of_deputies/admin.py delete mode 100644 jarbas/chamber_of_deputies/tests.py delete mode 100644 jarbas/chamber_of_deputies/views.py diff --git a/jarbas/chamber_of_deputies/admin.py b/jarbas/chamber_of_deputies/admin.py deleted file mode 100644 index 8c38f3f..0000000 --- a/jarbas/chamber_of_deputies/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/jarbas/chamber_of_deputies/tests.py b/jarbas/chamber_of_deputies/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/jarbas/chamber_of_deputies/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/jarbas/chamber_of_deputies/views.py b/jarbas/chamber_of_deputies/views.py deleted file mode 100644 index 91ea44a..0000000 --- a/jarbas/chamber_of_deputies/views.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.shortcuts import render - -# Create your views here. From 21fbe89a8a970789d7535987983f63e03dd67997 Mon Sep 17 00:00:00 2001 From: Giovani Date: Sat, 14 Oct 2017 16:14:54 -0300 Subject: [PATCH 09/34] Move Reimbursement querysets to chamber_of_deputies --- jarbas/chamber_of_deputies/models.py | 2 +- jarbas/{core => chamber_of_deputies}/querysets.py | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename jarbas/{core => chamber_of_deputies}/querysets.py (100%) diff --git a/jarbas/chamber_of_deputies/models.py b/jarbas/chamber_of_deputies/models.py index 90c49f6..23ffdf1 100644 --- a/jarbas/chamber_of_deputies/models.py +++ b/jarbas/chamber_of_deputies/models.py @@ -5,7 +5,7 @@ from requests import head from simple_history.models import HistoricalRecords -from jarbas.core.querysets import ReimbursementQuerySet +from jarbas.chamber_of_deputies.querysets import ReimbursementQuerySet class Receipt: diff --git a/jarbas/core/querysets.py b/jarbas/chamber_of_deputies/querysets.py similarity index 100% rename from jarbas/core/querysets.py rename to jarbas/chamber_of_deputies/querysets.py From 5f8b47cdfb5a6a1a5804d3199a94d23457e0bdbc Mon Sep 17 00:00:00 2001 From: Giovani Date: Sat, 14 Oct 2017 16:22:12 -0300 Subject: [PATCH 10/34] Reflect the permission change at dashboard sites to tests --- jarbas/dashboard/tests/test_dummy_user.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/jarbas/dashboard/tests/test_dummy_user.py b/jarbas/dashboard/tests/test_dummy_user.py index b7fa120..36cdb0d 100644 --- a/jarbas/dashboard/tests/test_dummy_user.py +++ b/jarbas/dashboard/tests/test_dummy_user.py @@ -9,12 +9,13 @@ def setUp(self): self.user = DummyUser() def test_has_module_perms(self): - self.assertTrue(self.user.has_module_perms('core')) + self.assertTrue(self.user.has_module_perms('chamber_of_deputies')) + self.assertFalse(self.user.has_module_perms('core')) self.assertFalse(self.user.has_module_perms('api')) self.assertFalse(self.user.has_module_perms('dashboard')) self.assertFalse(self.user.has_module_perms('frontend')) def test_has_perm(self): - self.assertTrue(self.user.has_perm('core.change_reimbursement')) - self.assertFalse(self.user.has_perm('core.add_reimbursement')) - self.assertFalse(self.user.has_perm('core.delete_reimbursement')) + self.assertTrue(self.user.has_perm('chamber_of_deputies.change_reimbursement')) + self.assertFalse(self.user.has_perm('chamber_of_deputies.add_reimbursement')) + self.assertFalse(self.user.has_perm('chamber_of_deputies.delete_reimbursement')) From c57de74c8455f5c577ad76a396658351a0e4090d Mon Sep 17 00:00:00 2001 From: Giovani Date: Sat, 14 Oct 2017 16:31:42 -0300 Subject: [PATCH 11/34] Move chamber_of_deputies models related samples from core tests to chamber tests --- jarbas/api/tests/test_applicant_view.py | 2 +- jarbas/api/tests/test_reimbursement_view.py | 2 +- jarbas/api/tests/test_same_day_view.py | 3 +- jarbas/api/tests/test_subquota_view.py | 2 +- jarbas/chamber_of_deputies/tests/__init__.py | 58 +++++++++++++++++++ jarbas/core/tests/__init__.py | 56 ------------------ jarbas/core/tests/test_reimbursement_model.py | 2 +- jarbas/core/tests/test_tweets_command.py | 2 +- 8 files changed, 65 insertions(+), 62 deletions(-) create mode 100644 jarbas/chamber_of_deputies/tests/__init__.py diff --git a/jarbas/api/tests/test_applicant_view.py b/jarbas/api/tests/test_applicant_view.py index 0b81c17..e34ffd6 100644 --- a/jarbas/api/tests/test_applicant_view.py +++ b/jarbas/api/tests/test_applicant_view.py @@ -5,7 +5,7 @@ from django.test import TestCase from jarbas.chamber_of_deputies.models import Reimbursement -from jarbas.core.tests import sample_reimbursement_data +from jarbas.chamber_of_deputies.tests import sample_reimbursement_data class TestApplicant(TestCase): diff --git a/jarbas/api/tests/test_reimbursement_view.py b/jarbas/api/tests/test_reimbursement_view.py index d302056..db21b84 100644 --- a/jarbas/api/tests/test_reimbursement_view.py +++ b/jarbas/api/tests/test_reimbursement_view.py @@ -9,7 +9,7 @@ from jarbas.api.tests import get_sample_reimbursement_api_response from jarbas.chamber_of_deputies.models import Reimbursement, Tweet -from jarbas.core.tests import random_tweet_status +from jarbas.chamber_of_deputies.tests import random_tweet_status def get_reimbursement(**kwargs): diff --git a/jarbas/api/tests/test_same_day_view.py b/jarbas/api/tests/test_same_day_view.py index f3fcad5..2fbf45f 100644 --- a/jarbas/api/tests/test_same_day_view.py +++ b/jarbas/api/tests/test_same_day_view.py @@ -5,7 +5,8 @@ from jarbas.chamber_of_deputies.models import Reimbursement from jarbas.core.models import Company -from jarbas.core.tests import sample_company_data, sample_reimbursement_data +from jarbas.chamber_of_deputies.tests import sample_reimbursement_data +from jarbas.core.tests import sample_company_data from jarbas.api.serializers import format_cnpj diff --git a/jarbas/api/tests/test_subquota_view.py b/jarbas/api/tests/test_subquota_view.py index a76adbf..8b62628 100644 --- a/jarbas/api/tests/test_subquota_view.py +++ b/jarbas/api/tests/test_subquota_view.py @@ -5,7 +5,7 @@ from django.test import TestCase from jarbas.chamber_of_deputies.models import Reimbursement -from jarbas.core.tests import sample_reimbursement_data +from jarbas.chamber_of_deputies.tests import sample_reimbursement_data class TestSubquota(TestCase): diff --git a/jarbas/chamber_of_deputies/tests/__init__.py b/jarbas/chamber_of_deputies/tests/__init__.py new file mode 100644 index 0000000..b66658b --- /dev/null +++ b/jarbas/chamber_of_deputies/tests/__init__.py @@ -0,0 +1,58 @@ +from datetime import date +from random import randrange + +from jarbas.chamber_of_deputies.models import Tweet + + +suspicions = { + 'over_monthly_subquota': {'is_suspect': True, 'probability': 1.0} +} + +sample_reimbursement_data = dict( + applicant_id=13, + batch_number=9, + cnpj_cpf='11111111111111', + congressperson_document=2, + congressperson_id=1, + congressperson_name='Roger That', + document_id=42, + document_number='6', + document_type=7, + document_value=8.90, + installment=7, + issue_date=date(1970, 1, 1), + leg_of_the_trip='8', + month=1, + net_values='1.99,2.99', + party='Partido', + passenger='John Doe', + reimbursement_numbers='10,11', + reimbursement_values='12.13,14.15', + remark_value=1.23, + state='UF', + subquota_description='Subquota description', + subquota_group_description='Subquota group desc', + subquota_group_id=5, + subquota_id=4, + supplier='Acme', + term=1970, + term_id=3, + total_net_value=4.56, + total_reimbursement_value=None, + year=1970, + probability=0.5, + suspicions=suspicions +) + + +def random_tweet_status(): + """ + Fixture generators (mixer, and faker behind the scenes) won't generate a + value for a `DecimalField` with zero decimal places - which is the case of + Tweet.status (too big to fit `BigIntegerField`). Therefore we use this + function to workaround random test fixtures for Tweet.status. + """ + status = Tweet._meta.get_field('status') + min_range = 9223372036854775807 # max big integer should be the minimum + max_range = 10 ** status.max_digits # field limit + return randrange(min_range, max_range) diff --git a/jarbas/core/tests/__init__.py b/jarbas/core/tests/__init__.py index 2feab47..adb8562 100644 --- a/jarbas/core/tests/__init__.py +++ b/jarbas/core/tests/__init__.py @@ -1,50 +1,7 @@ from datetime import date -from random import randrange from django.utils import timezone -from jarbas.chamber_of_deputies.models import Tweet - - -suspicions = { - 'over_monthly_subquota': {'is_suspect': True, 'probability': 1.0} -} - -sample_reimbursement_data = dict( - applicant_id=13, - batch_number=9, - cnpj_cpf='11111111111111', - congressperson_document=2, - congressperson_id=1, - congressperson_name='Roger That', - document_id=42, - document_number='6', - document_type=7, - document_value=8.90, - installment=7, - issue_date=date(1970, 1, 1), - leg_of_the_trip='8', - month=1, - net_values='1.99,2.99', - party='Partido', - passenger='John Doe', - reimbursement_numbers='10,11', - reimbursement_values='12.13,14.15', - remark_value=1.23, - state='UF', - subquota_description='Subquota description', - subquota_group_description='Subquota group desc', - subquota_group_id=5, - subquota_id=4, - supplier='Acme', - term=1970, - term_id=3, - total_net_value=4.56, - total_reimbursement_value=None, - year=1970, - probability=0.5, - suspicions=suspicions -) sample_activity_data = dict( code='42', @@ -78,16 +35,3 @@ latitude=None, longitude=None ) - - -def random_tweet_status(): - """ - Fixture generators (mixer, and faker behind the scenes) won't generate a - value for a `DecimalField` with zero decimal places — which is the case of - Tweet.status (too big to fit `BigIntegerField`). Therefore we use this - function to workaround random test fixtures for Tweet.status. - """ - status = Tweet._meta.get_field('status') - min_range = 9223372036854775807 # max big integer should be the minimum - max_range = 10 ** status.max_digits # field limit - return randrange(min_range, max_range) diff --git a/jarbas/core/tests/test_reimbursement_model.py b/jarbas/core/tests/test_reimbursement_model.py index 4838ca3..c2fc84f 100644 --- a/jarbas/core/tests/test_reimbursement_model.py +++ b/jarbas/core/tests/test_reimbursement_model.py @@ -5,7 +5,7 @@ from requests.exceptions import ConnectionError from jarbas.chamber_of_deputies.models import Reimbursement -from jarbas.core.tests import sample_reimbursement_data +from jarbas.chamber_of_deputies.tests import sample_reimbursement_data class TestReimbursement(TestCase): diff --git a/jarbas/core/tests/test_tweets_command.py b/jarbas/core/tests/test_tweets_command.py index c0e5d84..34738d7 100644 --- a/jarbas/core/tests/test_tweets_command.py +++ b/jarbas/core/tests/test_tweets_command.py @@ -7,7 +7,7 @@ from jarbas.chamber_of_deputies.models import Reimbursement, Tweet from jarbas.core.management.commands.tweets import Command -from jarbas.core.tests import random_tweet_status +from jarbas.chamber_of_deputies.tests import random_tweet_status KEYS = ( From 2dd28bc7391888a61a86afb02f8a8f350caaa957 Mon Sep 17 00:00:00 2001 From: Giovani Date: Sat, 14 Oct 2017 16:37:14 -0300 Subject: [PATCH 12/34] Move chamber models related tests from core to chamber_of_deputies tests --- jarbas/{core => chamber_of_deputies}/tests/test_receipt_class.py | 0 .../tests/test_reimbursement_model.py | 0 jarbas/{core => chamber_of_deputies}/tests/test_tweet_model.py | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename jarbas/{core => chamber_of_deputies}/tests/test_receipt_class.py (100%) rename jarbas/{core => chamber_of_deputies}/tests/test_reimbursement_model.py (100%) rename jarbas/{core => chamber_of_deputies}/tests/test_tweet_model.py (100%) diff --git a/jarbas/core/tests/test_receipt_class.py b/jarbas/chamber_of_deputies/tests/test_receipt_class.py similarity index 100% rename from jarbas/core/tests/test_receipt_class.py rename to jarbas/chamber_of_deputies/tests/test_receipt_class.py diff --git a/jarbas/core/tests/test_reimbursement_model.py b/jarbas/chamber_of_deputies/tests/test_reimbursement_model.py similarity index 100% rename from jarbas/core/tests/test_reimbursement_model.py rename to jarbas/chamber_of_deputies/tests/test_reimbursement_model.py diff --git a/jarbas/core/tests/test_tweet_model.py b/jarbas/chamber_of_deputies/tests/test_tweet_model.py similarity index 100% rename from jarbas/core/tests/test_tweet_model.py rename to jarbas/chamber_of_deputies/tests/test_tweet_model.py From 5e9532ca7d08455e32467eec6c662be18d7cc742 Mon Sep 17 00:00:00 2001 From: Giovani Date: Sat, 14 Oct 2017 17:21:42 -0300 Subject: [PATCH 13/34] Move chamber_of_deputies related commands from core to chamber_of_deputies commands --- jarbas/chamber_of_deputies/management/__init__.py | 0 .../management/commands/ceapdatasets.py | 0 .../{core => chamber_of_deputies}/management/commands/receipts.py | 0 .../management/commands/receipts_text.py | 0 .../management/commands/reimbursements.py | 0 .../management/commands/searchvector.py | 0 .../management/commands/suspicions.py | 0 .../{core => chamber_of_deputies}/management/commands/tweets.py | 0 8 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 jarbas/chamber_of_deputies/management/__init__.py rename jarbas/{core => chamber_of_deputies}/management/commands/ceapdatasets.py (100%) rename jarbas/{core => chamber_of_deputies}/management/commands/receipts.py (100%) rename jarbas/{core => chamber_of_deputies}/management/commands/receipts_text.py (100%) rename jarbas/{core => chamber_of_deputies}/management/commands/reimbursements.py (100%) rename jarbas/{core => chamber_of_deputies}/management/commands/searchvector.py (100%) rename jarbas/{core => chamber_of_deputies}/management/commands/suspicions.py (100%) rename jarbas/{core => chamber_of_deputies}/management/commands/tweets.py (100%) diff --git a/jarbas/chamber_of_deputies/management/__init__.py b/jarbas/chamber_of_deputies/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/jarbas/core/management/commands/ceapdatasets.py b/jarbas/chamber_of_deputies/management/commands/ceapdatasets.py similarity index 100% rename from jarbas/core/management/commands/ceapdatasets.py rename to jarbas/chamber_of_deputies/management/commands/ceapdatasets.py diff --git a/jarbas/core/management/commands/receipts.py b/jarbas/chamber_of_deputies/management/commands/receipts.py similarity index 100% rename from jarbas/core/management/commands/receipts.py rename to jarbas/chamber_of_deputies/management/commands/receipts.py diff --git a/jarbas/core/management/commands/receipts_text.py b/jarbas/chamber_of_deputies/management/commands/receipts_text.py similarity index 100% rename from jarbas/core/management/commands/receipts_text.py rename to jarbas/chamber_of_deputies/management/commands/receipts_text.py diff --git a/jarbas/core/management/commands/reimbursements.py b/jarbas/chamber_of_deputies/management/commands/reimbursements.py similarity index 100% rename from jarbas/core/management/commands/reimbursements.py rename to jarbas/chamber_of_deputies/management/commands/reimbursements.py diff --git a/jarbas/core/management/commands/searchvector.py b/jarbas/chamber_of_deputies/management/commands/searchvector.py similarity index 100% rename from jarbas/core/management/commands/searchvector.py rename to jarbas/chamber_of_deputies/management/commands/searchvector.py diff --git a/jarbas/core/management/commands/suspicions.py b/jarbas/chamber_of_deputies/management/commands/suspicions.py similarity index 100% rename from jarbas/core/management/commands/suspicions.py rename to jarbas/chamber_of_deputies/management/commands/suspicions.py diff --git a/jarbas/core/management/commands/tweets.py b/jarbas/chamber_of_deputies/management/commands/tweets.py similarity index 100% rename from jarbas/core/management/commands/tweets.py rename to jarbas/chamber_of_deputies/management/commands/tweets.py From 012a2fa81a6c9254c311a9c6c14da04ac7d69b0c Mon Sep 17 00:00:00 2001 From: Giovani Date: Sat, 14 Oct 2017 17:22:34 -0300 Subject: [PATCH 14/34] Fix commands path to chamber_of_deputies commands --- jarbas/core/tests/test_receipts_command.py | 46 +++++++++---------- .../core/tests/test_receipts_text_command.py | 42 ++++++++--------- .../core/tests/test_reimbursements_command.py | 32 ++++++------- .../core/tests/test_searchvector_command.py | 4 +- jarbas/core/tests/test_suspicions_command.py | 42 ++++++++--------- jarbas/core/tests/test_tweets_command.py | 12 ++--- jarbas/frontend/tests/test_static_files.py | 2 +- 7 files changed, 90 insertions(+), 90 deletions(-) diff --git a/jarbas/core/tests/test_receipts_command.py b/jarbas/core/tests/test_receipts_command.py index f1ed490..689f541 100644 --- a/jarbas/core/tests/test_receipts_command.py +++ b/jarbas/core/tests/test_receipts_command.py @@ -4,17 +4,17 @@ from django.db.models import QuerySet from requests.exceptions import ConnectionError -from jarbas.core.management.commands.receipts import Command +from jarbas.chamber_of_deputies.management.commands.receipts import Command class TestCommandHandler(TestCase): - @patch('jarbas.core.management.commands.receipts.Command.get_queryset') - @patch('jarbas.core.management.commands.receipts.Command.fetch') - @patch('jarbas.core.management.commands.receipts.Command.print_count') - @patch('jarbas.core.management.commands.receipts.Command.print_pause') - @patch('jarbas.core.management.commands.receipts.sleep') - @patch('jarbas.core.management.commands.receipts.print') + @patch('jarbas.chamber_of_deputies.management.commands.receipts.Command.get_queryset') + @patch('jarbas.chamber_of_deputies.management.commands.receipts.Command.fetch') + @patch('jarbas.chamber_of_deputies.management.commands.receipts.Command.print_count') + @patch('jarbas.chamber_of_deputies.management.commands.receipts.Command.print_pause') + @patch('jarbas.chamber_of_deputies.management.commands.receipts.sleep') + @patch('jarbas.chamber_of_deputies.management.commands.receipts.print') def test_handler_with_queryset(self, print_, sleep, print_pause, print_count, fetch, get_queryset): get_queryset.side_effect = (True, True, True, False) command = Command() @@ -28,9 +28,9 @@ def test_handler_with_queryset(self, print_, sleep, print_pause, print_count, fe self.assertEqual(42, command.pause) self.assertEqual(0, command.count) - @patch('jarbas.core.management.commands.receipts.Command.get_queryset') - @patch('jarbas.core.management.commands.receipts.Command.fetch') - @patch('jarbas.core.management.commands.receipts.print') + @patch('jarbas.chamber_of_deputies.management.commands.receipts.Command.get_queryset') + @patch('jarbas.chamber_of_deputies.management.commands.receipts.Command.fetch') + @patch('jarbas.chamber_of_deputies.management.commands.receipts.print') def test_handler_without_queryset(self, print_, fetch, get_queryset): get_queryset.return_value = False command = Command() @@ -54,9 +54,9 @@ def test_add_arguments(self): class TestCommandMethods(TestCase): - @patch('jarbas.core.management.commands.receipts.Command.update') - @patch('jarbas.core.management.commands.receipts.Command.bulk_update') - @patch('jarbas.core.management.commands.receipts.Command.print_count') + @patch('jarbas.chamber_of_deputies.management.commands.receipts.Command.update') + @patch('jarbas.chamber_of_deputies.management.commands.receipts.Command.bulk_update') + @patch('jarbas.chamber_of_deputies.management.commands.receipts.Command.print_count') def test_fetch(self, print_count, bulk_update, update): command = Command() command.count = 0 @@ -94,8 +94,8 @@ def test_update_with_error(self): reimbursement.get_receipt_url.assert_called_once_with(bulk=True) self.assertEqual(0, len(command.queue)) - @patch('jarbas.core.management.commands.receipts.bulk_update') - @patch('jarbas.core.management.commands.receipts.Command.print_saving') + @patch('jarbas.chamber_of_deputies.management.commands.receipts.bulk_update') + @patch('jarbas.chamber_of_deputies.management.commands.receipts.Command.print_saving') def test_bulk_update(self, print_saving, bulk_update): command = Command() command.queue = [1, 2, 3] @@ -113,7 +113,7 @@ def test_count_msg(self): command.count = 42 self.assertEqual('42 receipt URLs fetched', command.count_msg()) - @patch('jarbas.core.management.commands.receipts.print') + @patch('jarbas.chamber_of_deputies.management.commands.receipts.print') def test_print_msg(self, print_): Command.print_msg('42') print_.assert_has_calls(( @@ -121,13 +121,13 @@ def test_print_msg(self, print_): call('42') )) - @patch('jarbas.core.management.commands.receipts.print') + @patch('jarbas.chamber_of_deputies.management.commands.receipts.print') def test_print_permanent_msg(self, print_): Command.print_msg('42', permanent=True) print_.assert_called_once_with('42') - @patch('jarbas.core.management.commands.receipts.Command.count_msg') - @patch('jarbas.core.management.commands.receipts.Command.print_msg') + @patch('jarbas.chamber_of_deputies.management.commands.receipts.Command.count_msg') + @patch('jarbas.chamber_of_deputies.management.commands.receipts.Command.print_msg') def test_print_count(self, print_msg, count_msg): count_msg.return_value = '42' command = Command() @@ -135,16 +135,16 @@ def test_print_count(self, print_msg, count_msg): command.print_count(permanent=True) print_msg.assert_has_calls((call('42'), call('42', permanent=True))) - @patch('jarbas.core.management.commands.receipts.Command.count_msg') - @patch('jarbas.core.management.commands.receipts.Command.print_msg') + @patch('jarbas.chamber_of_deputies.management.commands.receipts.Command.count_msg') + @patch('jarbas.chamber_of_deputies.management.commands.receipts.Command.print_msg') def test_print_pause(self, print_msg, count_msg): count_msg.return_value = '42' command = Command() command.print_pause() print_msg.assert_called_once_with('42 (Taking a break to avoid being blocked…)') - @patch('jarbas.core.management.commands.receipts.Command.count_msg') - @patch('jarbas.core.management.commands.receipts.Command.print_msg') + @patch('jarbas.chamber_of_deputies.management.commands.receipts.Command.count_msg') + @patch('jarbas.chamber_of_deputies.management.commands.receipts.Command.print_msg') def test_print_saving(self, print_msg, count_msg): count_msg.return_value = '42' command = Command() diff --git a/jarbas/core/tests/test_receipts_text_command.py b/jarbas/core/tests/test_receipts_text_command.py index d4749f1..c588360 100644 --- a/jarbas/core/tests/test_receipts_text_command.py +++ b/jarbas/core/tests/test_receipts_text_command.py @@ -3,7 +3,7 @@ from django.test import TestCase -from jarbas.core.management.commands.receipts_text import Command +from jarbas.chamber_of_deputies.management.commands.receipts_text import Command from jarbas.chamber_of_deputies.models import Reimbursement @@ -41,9 +41,9 @@ def test_serializer_without_text(self): class TestCustomMethods(TestCommand): - @patch('jarbas.core.management.commands.receipts_text.Command.receipts') - @patch('jarbas.core.management.commands.receipts_text.Command.schedule_update') - @patch('jarbas.core.management.commands.receipts_text.Command.update') + @patch('jarbas.chamber_of_deputies.management.commands.receipts_text.Command.receipts') + @patch('jarbas.chamber_of_deputies.management.commands.receipts_text.Command.schedule_update') + @patch('jarbas.chamber_of_deputies.management.commands.receipts_text.Command.update') def test_main(self, update, schedule_update, receipts): receipts.return_value = (range(21), range(21, 43)) self.command.main() @@ -72,8 +72,8 @@ def test_schedule_update_non_existing_record(self, get): get.assert_called_once_with(document_id=42) self.assertEqual([], self.command.queue) - @patch('jarbas.core.management.commands.receipts_text.bulk_update') - @patch('jarbas.core.management.commands.receipts_text.print') + @patch('jarbas.chamber_of_deputies.management.commands.receipts_text.bulk_update') + @patch('jarbas.chamber_of_deputies.management.commands.receipts_text.print') def test_update(self, print_, bulk_update): self.command.count = 40 self.command.queue = list(range(2)) @@ -86,10 +86,10 @@ def test_update(self, print_, bulk_update): class TestConventionMethods(TestCommand): - @patch('jarbas.core.management.commands.receipts_text.Command.receipts') - @patch('jarbas.core.management.commands.receipts_text.Command.main') - @patch('jarbas.core.management.commands.receipts_text.os.path.exists') - @patch('jarbas.core.management.commands.receipts_text.print') + @patch('jarbas.chamber_of_deputies.management.commands.receipts_text.Command.receipts') + @patch('jarbas.chamber_of_deputies.management.commands.receipts_text.Command.main') + @patch('jarbas.chamber_of_deputies.management.commands.receipts_text.os.path.exists') + @patch('jarbas.chamber_of_deputies.management.commands.receipts_text.print') def test_handler_with_options(self, print_, exists, main, receipts): self.command.handle(dataset='receipts-texts.xz', batch_size=42) main.assert_called_once_with() @@ -97,10 +97,10 @@ def test_handler_with_options(self, print_, exists, main, receipts): self.assertEqual(self.command.path, 'receipts-texts.xz') self.assertEqual(self.command.batch_size, 42) - @patch('jarbas.core.management.commands.receipts_text.Command.receipts') - @patch('jarbas.core.management.commands.receipts_text.Command.main') - @patch('jarbas.core.management.commands.receipts_text.os.path.exists') - @patch('jarbas.core.management.commands.receipts_text.print') + @patch('jarbas.chamber_of_deputies.management.commands.receipts_text.Command.receipts') + @patch('jarbas.chamber_of_deputies.management.commands.receipts_text.Command.main') + @patch('jarbas.chamber_of_deputies.management.commands.receipts_text.os.path.exists') + @patch('jarbas.chamber_of_deputies.management.commands.receipts_text.print') def test_handler_without_options(self, print_, exists, main, receipts): self.command.handle(dataset='receipts-texts.xz', batch_size=4096) main.assert_called_once_with() @@ -108,9 +108,9 @@ def test_handler_without_options(self, print_, exists, main, receipts): self.assertEqual(self.command.path, 'receipts-texts.xz') self.assertEqual(self.command.batch_size, 4096) - @patch('jarbas.core.management.commands.receipts_text.Command.receipts') - @patch('jarbas.core.management.commands.receipts_text.Command.main') - @patch('jarbas.core.management.commands.receipts_text.os.path.exists') + @patch('jarbas.chamber_of_deputies.management.commands.receipts_text.Command.receipts') + @patch('jarbas.chamber_of_deputies.management.commands.receipts_text.Command.main') + @patch('jarbas.chamber_of_deputies.management.commands.receipts_text.os.path.exists') def test_handler_with_non_existing_file(self, exists, update, receipts): exists.return_value = False with self.assertRaises(FileNotFoundError): @@ -120,10 +120,10 @@ def test_handler_with_non_existing_file(self, exists, update, receipts): class TestFileLoader(TestCommand): - @patch('jarbas.core.management.commands.receipts_text.print') - @patch('jarbas.core.management.commands.receipts_text.lzma') - @patch('jarbas.core.management.commands.receipts_text.csv.DictReader') - @patch('jarbas.core.management.commands.receipts_text.Command.serialize') + @patch('jarbas.chamber_of_deputies.management.commands.receipts_text.print') + @patch('jarbas.chamber_of_deputies.management.commands.receipts_text.lzma') + @patch('jarbas.chamber_of_deputies.management.commands.receipts_text.csv.DictReader') + @patch('jarbas.chamber_of_deputies.management.commands.receipts_text.Command.serialize') def test_receipts(self, serialize, rows, lzma, print_): serialize.return_value = '.' lzma.return_value = StringIO() diff --git a/jarbas/core/tests/test_reimbursements_command.py b/jarbas/core/tests/test_reimbursements_command.py index 8f4dfcc..b069da8 100644 --- a/jarbas/core/tests/test_reimbursements_command.py +++ b/jarbas/core/tests/test_reimbursements_command.py @@ -4,7 +4,7 @@ from django.test import TestCase -from jarbas.core.management.commands.reimbursements import Command +from jarbas.chamber_of_deputies.management.commands.reimbursements import Command from jarbas.chamber_of_deputies.models import Reimbursement @@ -92,7 +92,7 @@ def test_serializer(self): class TestCreate(TestCommand): @patch.object(Reimbursement.objects, 'update_or_create') - @patch('jarbas.core.management.commands.reimbursements.output') + @patch('jarbas.chamber_of_deputies.management.commands.reimbursements.output') def test_create_or_update(self, output, create): status = MagicMock() reimbursements = ( @@ -144,11 +144,11 @@ def test_mark_available_in_latest_dataset(self, filter_): class TestConventionMethods(TestCommand): - @patch('jarbas.core.management.commands.reimbursements.print') - @patch('jarbas.core.management.commands.reimbursements.Command.reimbursements') - @patch('jarbas.core.management.commands.reimbursements.Command.create_or_update') - @patch('jarbas.core.management.commands.reimbursements.output') - @patch('jarbas.core.management.commands.reimbursements.Command.mark_not_updated_reimbursements') + @patch('jarbas.chamber_of_deputies.management.commands.reimbursements.print') + @patch('jarbas.chamber_of_deputies.management.commands.reimbursements.Command.reimbursements') + @patch('jarbas.chamber_of_deputies.management.commands.reimbursements.Command.create_or_update') + @patch('jarbas.chamber_of_deputies.management.commands.reimbursements.output') + @patch('jarbas.chamber_of_deputies.management.commands.reimbursements.Command.mark_not_updated_reimbursements') def test_handler_without_options(self, mark, output, create, reimbursements, print_): status = MagicMock() output.return_value.__enter__.return_value = status @@ -161,12 +161,12 @@ def test_handler_without_options(self, mark, output, create, reimbursements, pri self.assertEqual('reimbursements.xz', self.command.path) mark.assert_called_once_with() - @patch('jarbas.core.management.commands.reimbursements.print') - @patch('jarbas.core.management.commands.reimbursements.Command.reimbursements') - @patch('jarbas.core.management.commands.reimbursements.Command.create_or_update') - @patch('jarbas.core.management.commands.reimbursements.Command.drop_all') - @patch('jarbas.core.management.commands.reimbursements.output') - @patch('jarbas.core.management.commands.reimbursements.Command.mark_not_updated_reimbursements') + @patch('jarbas.chamber_of_deputies.management.commands.reimbursements.print') + @patch('jarbas.chamber_of_deputies.management.commands.reimbursements.Command.reimbursements') + @patch('jarbas.chamber_of_deputies.management.commands.reimbursements.Command.create_or_update') + @patch('jarbas.chamber_of_deputies.management.commands.reimbursements.Command.drop_all') + @patch('jarbas.chamber_of_deputies.management.commands.reimbursements.output') + @patch('jarbas.chamber_of_deputies.management.commands.reimbursements.Command.mark_not_updated_reimbursements') def test_handler_with_options(self, mark, output, drop_all, create, reimbursements, print_): status = MagicMock() output.return_value.__enter__.return_value = status @@ -179,9 +179,9 @@ def test_handler_with_options(self, mark, output, drop_all, create, reimbursemen class TestFileLoader(TestCommand): - @patch('jarbas.core.management.commands.reimbursements.lzma') - @patch('jarbas.core.management.commands.reimbursements.csv.DictReader') - @patch('jarbas.core.management.commands.reimbursements.Command.serialize') + @patch('jarbas.chamber_of_deputies.management.commands.reimbursements.lzma') + @patch('jarbas.chamber_of_deputies.management.commands.reimbursements.csv.DictReader') + @patch('jarbas.chamber_of_deputies.management.commands.reimbursements.Command.serialize') def test_reimbursement_property(self, serializer, row, lzma): lzma.return_value = StringIO() row.return_value = dict(ahoy=42) diff --git a/jarbas/core/tests/test_searchvector_command.py b/jarbas/core/tests/test_searchvector_command.py index 6555fc9..22048c0 100644 --- a/jarbas/core/tests/test_searchvector_command.py +++ b/jarbas/core/tests/test_searchvector_command.py @@ -2,14 +2,14 @@ from django.test import TestCase -from jarbas.core.management.commands.searchvector import Command +from jarbas.chamber_of_deputies.management.commands.searchvector import Command from jarbas.chamber_of_deputies.models import Reimbursement class TestCommandHandler(TestCase): @patch.object(Reimbursement.objects, 'update') - @patch('jarbas.core.management.commands.searchvector.print') + @patch('jarbas.chamber_of_deputies.management.commands.searchvector.print') def test_handler(self, print_, update): command = Command() command.handle() diff --git a/jarbas/core/tests/test_suspicions_command.py b/jarbas/core/tests/test_suspicions_command.py index 542978e..283a2b8 100644 --- a/jarbas/core/tests/test_suspicions_command.py +++ b/jarbas/core/tests/test_suspicions_command.py @@ -3,7 +3,7 @@ from django.test import TestCase -from jarbas.core.management.commands.suspicions import Command +from jarbas.chamber_of_deputies.management.commands.suspicions import Command from jarbas.chamber_of_deputies.models import Reimbursement @@ -70,9 +70,9 @@ def test_serializer_without_suspicions(self): class TestCustomMethods(TestCommand): - @patch('jarbas.core.management.commands.suspicions.Command.suspicions') - @patch('jarbas.core.management.commands.suspicions.Command.schedule_update') - @patch('jarbas.core.management.commands.suspicions.Command.update') + @patch('jarbas.chamber_of_deputies.management.commands.suspicions.Command.suspicions') + @patch('jarbas.chamber_of_deputies.management.commands.suspicions.Command.schedule_update') + @patch('jarbas.chamber_of_deputies.management.commands.suspicions.Command.update') def test_main(self, update, schedule_update, suspicions): suspicions.return_value = (range(21), range(21, 43)) self.command.workers = 8 @@ -105,8 +105,8 @@ def test_schedule_update_non_existing_record(self, get): get.assert_called_once_with(document_id=42) self.assertEqual([], self.command.queue) - @patch('jarbas.core.management.commands.suspicions.bulk_update') - @patch('jarbas.core.management.commands.suspicions.print') + @patch('jarbas.chamber_of_deputies.management.commands.suspicions.bulk_update') + @patch('jarbas.chamber_of_deputies.management.commands.suspicions.print') def test_update(self, print_, bulk_update): self.command.count = 40 self.command.queue = list(range(2)) @@ -134,10 +134,10 @@ def test_bool(self): class TestConventionMethods(TestCommand): - @patch('jarbas.core.management.commands.suspicions.Command.suspicions') - @patch('jarbas.core.management.commands.suspicions.Command.main') - @patch('jarbas.core.management.commands.suspicions.os.path.exists') - @patch('jarbas.core.management.commands.suspicions.print') + @patch('jarbas.chamber_of_deputies.management.commands.suspicions.Command.suspicions') + @patch('jarbas.chamber_of_deputies.management.commands.suspicions.Command.main') + @patch('jarbas.chamber_of_deputies.management.commands.suspicions.os.path.exists') + @patch('jarbas.chamber_of_deputies.management.commands.suspicions.print') def test_handler_with_options(self, print_, exists, main, suspicions): self.command.handle(dataset='suspicions.xz', batch_size=42, workers=7) main.assert_called_once_with() @@ -146,10 +146,10 @@ def test_handler_with_options(self, print_, exists, main, suspicions): self.assertEqual(self.command.batch_size, 42) self.assertEqual(self.command.workers, 7) - @patch('jarbas.core.management.commands.suspicions.Command.suspicions') - @patch('jarbas.core.management.commands.suspicions.Command.main') - @patch('jarbas.core.management.commands.suspicions.os.path.exists') - @patch('jarbas.core.management.commands.suspicions.print') + @patch('jarbas.chamber_of_deputies.management.commands.suspicions.Command.suspicions') + @patch('jarbas.chamber_of_deputies.management.commands.suspicions.Command.main') + @patch('jarbas.chamber_of_deputies.management.commands.suspicions.os.path.exists') + @patch('jarbas.chamber_of_deputies.management.commands.suspicions.print') def test_handler_without_options(self, print_, exists, main, suspicions): self.command.handle(dataset='suspicions.xz', batch_size=4096, workers=8) main.assert_called_once_with() @@ -158,9 +158,9 @@ def test_handler_without_options(self, print_, exists, main, suspicions): self.assertEqual(self.command.batch_size, 4096) self.assertEqual(self.command.workers, 8) - @patch('jarbas.core.management.commands.suspicions.Command.suspicions') - @patch('jarbas.core.management.commands.suspicions.Command.main') - @patch('jarbas.core.management.commands.suspicions.os.path.exists') + @patch('jarbas.chamber_of_deputies.management.commands.suspicions.Command.suspicions') + @patch('jarbas.chamber_of_deputies.management.commands.suspicions.Command.main') + @patch('jarbas.chamber_of_deputies.management.commands.suspicions.os.path.exists') def test_handler_with_non_existing_file(self, exists, update, suspicions): exists.return_value = False with self.assertRaises(FileNotFoundError): @@ -170,10 +170,10 @@ def test_handler_with_non_existing_file(self, exists, update, suspicions): class TestFileLoader(TestCommand): - @patch('jarbas.core.management.commands.suspicions.print') - @patch('jarbas.core.management.commands.suspicions.lzma') - @patch('jarbas.core.management.commands.suspicions.csv.DictReader') - @patch('jarbas.core.management.commands.suspicions.Command.serialize') + @patch('jarbas.chamber_of_deputies.management.commands.suspicions.print') + @patch('jarbas.chamber_of_deputies.management.commands.suspicions.lzma') + @patch('jarbas.chamber_of_deputies.management.commands.suspicions.csv.DictReader') + @patch('jarbas.chamber_of_deputies.management.commands.suspicions.Command.serialize') def test_suspicions(self, serialize, rows, lzma, print_): serialize.return_value = '.' lzma.return_value = StringIO() diff --git a/jarbas/core/tests/test_tweets_command.py b/jarbas/core/tests/test_tweets_command.py index 34738d7..b54416a 100644 --- a/jarbas/core/tests/test_tweets_command.py +++ b/jarbas/core/tests/test_tweets_command.py @@ -6,7 +6,7 @@ from mixer.backend.django import mixer from jarbas.chamber_of_deputies.models import Reimbursement, Tweet -from jarbas.core.management.commands.tweets import Command +from jarbas.chamber_of_deputies.management.commands.tweets import Command from jarbas.chamber_of_deputies.tests import random_tweet_status @@ -29,8 +29,8 @@ def setUp(self): class TestAuthWithoutCredential(TestCommand): - @patch('jarbas.core.management.commands.tweets.logging.getLogger') - @patch('jarbas.core.management.commands.tweets.twitter.api') + @patch('jarbas.chamber_of_deputies.management.commands.tweets.logging.getLogger') + @patch('jarbas.chamber_of_deputies.management.commands.tweets.twitter.api') @patch.object(Tweet.objects, 'first') def test_handler_without_credentials(self, first, api, log): missing_values = tuple(set(permutations(['', '42', '42', '42']))) @@ -45,7 +45,7 @@ def test_handler_without_credentials(self, first, api, log): class TestAuthWithCredentials(TestCommand): - @patch('jarbas.core.management.commands.tweets.twitter.Api') + @patch('jarbas.chamber_of_deputies.management.commands.tweets.twitter.Api') @patch.object(Tweet.objects, 'first') def test_credentials(self, first, api): with self.settings(**self.credentials): @@ -131,7 +131,7 @@ def test_save_duplicated_tweet(self): class TestProperties(TestCommand): - @patch('jarbas.core.management.commands.tweets.twitter.Api') + @patch('jarbas.chamber_of_deputies.management.commands.tweets.twitter.Api') def test_tweets_with_clean_database(self, api): api.return_value.GetUserTimeline.return_value = range(3) with self.settings(**self.credentials): @@ -148,7 +148,7 @@ def test_tweets_with_clean_database(self, api): exclude_replies=True ) - @patch('jarbas.core.management.commands.tweets.twitter.Api') + @patch('jarbas.chamber_of_deputies.management.commands.tweets.twitter.Api') def test_tweets_with_database(self, api): tweet = mixer.blend( Tweet, diff --git a/jarbas/frontend/tests/test_static_files.py b/jarbas/frontend/tests/test_static_files.py index 24edd94..d243d4f 100644 --- a/jarbas/frontend/tests/test_static_files.py +++ b/jarbas/frontend/tests/test_static_files.py @@ -27,7 +27,7 @@ def setUp(self): if path.exists(file_path): remove(file_path) - @patch('jarbas.core.management.commands.ceapdatasets.urlretrieve') + @patch('jarbas.chamber_of_deputies.management.commands.ceapdatasets.urlretrieve') def test_ceap_datasets(self, mock_urlretrieve): # backup existing file if exists From 10f5abc58ab4f2b820f4fb06566871233fec8030 Mon Sep 17 00:00:00 2001 From: Giovani Date: Sat, 14 Oct 2017 17:27:33 -0300 Subject: [PATCH 15/34] Move chamber_of_deputies commands tests from core to chamber_of_deputies tests --- .../{core => chamber_of_deputies}/tests/test_receipts_command.py | 0 .../tests/test_receipts_text_command.py | 0 .../tests/test_reimbursements_command.py | 0 .../tests/test_searchvector_command.py | 0 .../tests/test_suspicions_command.py | 0 jarbas/{core => chamber_of_deputies}/tests/test_tweets_command.py | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename jarbas/{core => chamber_of_deputies}/tests/test_receipts_command.py (100%) rename jarbas/{core => chamber_of_deputies}/tests/test_receipts_text_command.py (100%) rename jarbas/{core => chamber_of_deputies}/tests/test_reimbursements_command.py (100%) rename jarbas/{core => chamber_of_deputies}/tests/test_searchvector_command.py (100%) rename jarbas/{core => chamber_of_deputies}/tests/test_suspicions_command.py (100%) rename jarbas/{core => chamber_of_deputies}/tests/test_tweets_command.py (100%) diff --git a/jarbas/core/tests/test_receipts_command.py b/jarbas/chamber_of_deputies/tests/test_receipts_command.py similarity index 100% rename from jarbas/core/tests/test_receipts_command.py rename to jarbas/chamber_of_deputies/tests/test_receipts_command.py diff --git a/jarbas/core/tests/test_receipts_text_command.py b/jarbas/chamber_of_deputies/tests/test_receipts_text_command.py similarity index 100% rename from jarbas/core/tests/test_receipts_text_command.py rename to jarbas/chamber_of_deputies/tests/test_receipts_text_command.py diff --git a/jarbas/core/tests/test_reimbursements_command.py b/jarbas/chamber_of_deputies/tests/test_reimbursements_command.py similarity index 100% rename from jarbas/core/tests/test_reimbursements_command.py rename to jarbas/chamber_of_deputies/tests/test_reimbursements_command.py diff --git a/jarbas/core/tests/test_searchvector_command.py b/jarbas/chamber_of_deputies/tests/test_searchvector_command.py similarity index 100% rename from jarbas/core/tests/test_searchvector_command.py rename to jarbas/chamber_of_deputies/tests/test_searchvector_command.py diff --git a/jarbas/core/tests/test_suspicions_command.py b/jarbas/chamber_of_deputies/tests/test_suspicions_command.py similarity index 100% rename from jarbas/core/tests/test_suspicions_command.py rename to jarbas/chamber_of_deputies/tests/test_suspicions_command.py diff --git a/jarbas/core/tests/test_tweets_command.py b/jarbas/chamber_of_deputies/tests/test_tweets_command.py similarity index 100% rename from jarbas/core/tests/test_tweets_command.py rename to jarbas/chamber_of_deputies/tests/test_tweets_command.py From cc2fa839b4236393c37d4168ef741fdc1051fa37 Mon Sep 17 00:00:00 2001 From: Giovani Date: Sun, 15 Oct 2017 15:01:14 -0200 Subject: [PATCH 16/34] Data migration --- .../migrations/0001_initial.py | 10 ++++++++- ...igrate_data_to_chamber_of_deputies_app.py} | 22 +++++++++++-------- 2 files changed, 22 insertions(+), 10 deletions(-) rename jarbas/core/migrations/{0041_auto_20171014_0445.py => 0041_migrate_data_to_chamber_of_deputies_app.py} (52%) diff --git a/jarbas/chamber_of_deputies/migrations/0001_initial.py b/jarbas/chamber_of_deputies/migrations/0001_initial.py index 0f5056d..65a0f95 100644 --- a/jarbas/chamber_of_deputies/migrations/0001_initial.py +++ b/jarbas/chamber_of_deputies/migrations/0001_initial.py @@ -16,9 +16,10 @@ class Migration(migrations.Migration): dependencies = [ migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('core', '0041_migrate_data_to_chamber_of_deputies_app'), ] - operations = [ + state_operations = [ migrations.CreateModel( name='HistoricalReimbursement', fields=[ @@ -70,6 +71,7 @@ class Migration(migrations.Migration): 'get_latest_by': 'history_date', 'ordering': ('-history_date', '-history_id'), 'verbose_name': 'historical reembolso', + 'db_table': 'chamber_of_deputies_historicalreimbursement', }, ), migrations.CreateModel( @@ -120,6 +122,7 @@ class Migration(migrations.Migration): 'verbose_name_plural': 'reembolsos', 'ordering': ('-year', '-issue_date'), 'verbose_name': 'reembolso', + 'db_table': 'chamber_of_deputies_reimbursement', }, ), migrations.CreateModel( @@ -131,6 +134,7 @@ class Migration(migrations.Migration): ], options={ 'ordering': ('-status',), + 'db_table': 'chamber_of_deputies_tweet', }, ), migrations.AddIndex( @@ -147,3 +151,7 @@ class Migration(migrations.Migration): field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL), ), ] + + operations = [ + migrations.SeparateDatabaseAndState(state_operations=state_operations) + ] diff --git a/jarbas/core/migrations/0041_auto_20171014_0445.py b/jarbas/core/migrations/0041_migrate_data_to_chamber_of_deputies_app.py similarity index 52% rename from jarbas/core/migrations/0041_auto_20171014_0445.py rename to jarbas/core/migrations/0041_migrate_data_to_chamber_of_deputies_app.py index 2ffb0da..1615935 100644 --- a/jarbas/core/migrations/0041_auto_20171014_0445.py +++ b/jarbas/core/migrations/0041_migrate_data_to_chamber_of_deputies_app.py @@ -11,18 +11,16 @@ class Migration(migrations.Migration): ('core', '0040_create_gin_index_with_search_vector'), ] - operations = [ - migrations.RemoveField( - model_name='historicalreimbursement', - name='history_user', - ), + database_operations = [ + migrations.AlterModelTable('Reimbursement', 'chamber_of_deputies_reimbursement'), + migrations.AlterModelTable('HistoricalReimbursement', 'chamber_of_deputies_historicalreimbursement'), + migrations.AlterModelTable('Tweet', 'chamber_of_deputies_tweet'), + ] + + state_operations = [ migrations.DeleteModel( name='Reimbursement', ), - migrations.RemoveField( - model_name='tweet', - name='reimbursement', - ), migrations.DeleteModel( name='HistoricalReimbursement', ), @@ -30,3 +28,9 @@ class Migration(migrations.Migration): name='Tweet', ), ] + + operations = [ + migrations.SeparateDatabaseAndState( + database_operations=database_operations, + state_operations=state_operations) + ] From bb1ad2076b766706a047cabd7d41dff3f042bb27 Mon Sep 17 00:00:00 2001 From: Giovani Date: Tue, 17 Oct 2017 21:29:07 -0200 Subject: [PATCH 17/34] Remove spaces from lines almost blank --- jarbas/chamber_of_deputies/models.py | 1 - jarbas/chamber_of_deputies/querysets.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/jarbas/chamber_of_deputies/models.py b/jarbas/chamber_of_deputies/models.py index 23ffdf1..9f64f1c 100644 --- a/jarbas/chamber_of_deputies/models.py +++ b/jarbas/chamber_of_deputies/models.py @@ -156,4 +156,3 @@ def __repr__(self): class Meta: ordering = ('-status',) - diff --git a/jarbas/chamber_of_deputies/querysets.py b/jarbas/chamber_of_deputies/querysets.py index 3154d79..336067b 100644 --- a/jarbas/chamber_of_deputies/querysets.py +++ b/jarbas/chamber_of_deputies/querysets.py @@ -28,7 +28,7 @@ def list_distinct(self, field, order_by_field, query=None): self = self.values(field, order_by_field).order_by(order_by_field) return self.distinct() - + def suspicions(self, boolean): if not boolean: return self.filter(suspicions=None) From 2bb9d7344287fc0bbc8f11b903d25af6d3ea683e Mon Sep 17 00:00:00 2001 From: Giovani Date: Tue, 17 Oct 2017 21:30:13 -0200 Subject: [PATCH 18/34] Add migrations folder to Code Climate exclude_paths --- .codeclimate.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.codeclimate.yml b/.codeclimate.yml index 7782f07..5872bfe 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -30,5 +30,5 @@ ratings: - "**.sh" exclude_paths: - - "jarbas/core/migrations/" + - "**/migrations/" - "**/tests/*.py" From f3eb7eb8a18775d476c28775ba51bd4a6170ccf4 Mon Sep 17 00:00:00 2001 From: Giovani Date: Sun, 22 Oct 2017 02:59:56 -0200 Subject: [PATCH 19/34] Move tasks to chamber_of_deputies --- jarbas/chamber_of_deputies/tasks.py | 2 +- jarbas/chamber_of_deputies/tests/test_reimbursement_task.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/jarbas/chamber_of_deputies/tasks.py b/jarbas/chamber_of_deputies/tasks.py index af69c79..24bd1e5 100644 --- a/jarbas/chamber_of_deputies/tasks.py +++ b/jarbas/chamber_of_deputies/tasks.py @@ -1,6 +1,6 @@ from celery import shared_task -from jarbas.core.models import Reimbursement +from jarbas.chamber_of_deputies.models import Reimbursement from jarbas.core.management.commands import LoadCommand diff --git a/jarbas/chamber_of_deputies/tests/test_reimbursement_task.py b/jarbas/chamber_of_deputies/tests/test_reimbursement_task.py index 0d72ca0..6bfcbb5 100644 --- a/jarbas/chamber_of_deputies/tests/test_reimbursement_task.py +++ b/jarbas/chamber_of_deputies/tests/test_reimbursement_task.py @@ -1,8 +1,8 @@ from django.test import TestCase from mixer.backend.django import mixer -from jarbas.core.models import Reimbursement -from jarbas.core.tasks import ( +from jarbas.chamber_of_deputies.models import Reimbursement +from jarbas.chamber_of_deputies.tasks import ( create_or_update_reimbursement, serialize_reimbursement ) From f0983db59386a653f8a410d05f32ef67ca8c9bdd Mon Sep 17 00:00:00 2001 From: Giovani Date: Sun, 22 Oct 2017 03:05:01 -0200 Subject: [PATCH 20/34] Remove MagicMock from test_reimbursements_command imports --- .../chamber_of_deputies/tests/test_reimbursements_command.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jarbas/chamber_of_deputies/tests/test_reimbursements_command.py b/jarbas/chamber_of_deputies/tests/test_reimbursements_command.py index 25436fe..7242ec0 100644 --- a/jarbas/chamber_of_deputies/tests/test_reimbursements_command.py +++ b/jarbas/chamber_of_deputies/tests/test_reimbursements_command.py @@ -1,6 +1,6 @@ -from datetime import date + from io import StringIO -from unittest.mock import MagicMock, call, patch +from unittest.mock import call, patch from django.test import TestCase From 3993ff536434894d47ad76da3cbd9b99a900ca9f Mon Sep 17 00:00:00 2001 From: Giovani Date: Sun, 22 Oct 2017 03:07:56 -0200 Subject: [PATCH 21/34] Remove blank lines --- .../chamber_of_deputies/management/commands/reimbursements.py | 1 - jarbas/chamber_of_deputies/tests/test_reimbursements_command.py | 2 -- 2 files changed, 3 deletions(-) diff --git a/jarbas/chamber_of_deputies/management/commands/reimbursements.py b/jarbas/chamber_of_deputies/management/commands/reimbursements.py index f9977db..92fa6d8 100644 --- a/jarbas/chamber_of_deputies/management/commands/reimbursements.py +++ b/jarbas/chamber_of_deputies/management/commands/reimbursements.py @@ -4,7 +4,6 @@ from django.utils.timezone import now from jarbas.core.management.commands import LoadCommand - from jarbas.chamber_of_deputies.models import Reimbursement from jarbas.chamber_of_deputies.tasks import create_or_update_reimbursement diff --git a/jarbas/chamber_of_deputies/tests/test_reimbursements_command.py b/jarbas/chamber_of_deputies/tests/test_reimbursements_command.py index 7242ec0..4154af9 100644 --- a/jarbas/chamber_of_deputies/tests/test_reimbursements_command.py +++ b/jarbas/chamber_of_deputies/tests/test_reimbursements_command.py @@ -1,4 +1,3 @@ - from io import StringIO from unittest.mock import call, patch @@ -20,7 +19,6 @@ class TestCreate(TestCommand): @patch('jarbas.chamber_of_deputies.management.commands.reimbursements.print') @patch('jarbas.chamber_of_deputies.management.commands.reimbursements.create_or_update_reimbursement') def test_create_or_update(self, create, print_, print_count): - reimbursements = ( dict(ahoy=42, document_id=1), dict(ahoy=84, document_id=2) From 48aeac8184c541f16bd5ffefcea27e33221249a6 Mon Sep 17 00:00:00 2001 From: Giovani Date: Mon, 23 Oct 2017 00:03:22 -0200 Subject: [PATCH 22/34] Update app's verbose name --- jarbas/chamber_of_deputies/app.py | 2 +- jarbas/core/app.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jarbas/chamber_of_deputies/app.py b/jarbas/chamber_of_deputies/app.py index d5a36de..e47a6dd 100644 --- a/jarbas/chamber_of_deputies/app.py +++ b/jarbas/chamber_of_deputies/app.py @@ -3,4 +3,4 @@ class ChamberOfDeputiesConfig(AppConfig): name = 'jarbas.chamber_of_deputies' - verbose_name = 'Câmara dos Deputados' + verbose_name = 'Câmara dos Deputados - Cota para Exercício da Atividade Parlamentar' diff --git a/jarbas/core/app.py b/jarbas/core/app.py index 8876609..cbcd3f0 100644 --- a/jarbas/core/app.py +++ b/jarbas/core/app.py @@ -3,4 +3,4 @@ class CoreConfig(AppConfig): name = 'jarbas.core' - verbose_name = 'Cota para Exercício da Atividade Parlamentar' + verbose_name = 'Jarbas' From 51922a029eb8590b11f0a1fc343bbe8a5976edcb Mon Sep 17 00:00:00 2001 From: Giovani Date: Mon, 23 Oct 2017 00:21:50 -0200 Subject: [PATCH 23/34] Update api endpoints --- README.md | 26 +++++++++---------- jarbas/api/urls.py | 12 ++++----- .../elm/Reimbursement/Receipt/Update.elm | 1 + .../elm/Reimbursement/SameDay/Update.elm | 3 ++- .../elm/Reimbursement/SameSubquota/Update.elm | 4 +-- jarbas/frontend/elm/Reimbursement/Update.elm | 2 +- 6 files changed, 25 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index dd24672..310466a 100644 --- a/README.md +++ b/README.md @@ -31,23 +31,23 @@ Each `Reimbursement` object is a reimbursement claimed by a congressperson and i #### Retrieving a specific reimbursement -##### `GET /api/reimbursement//` +##### `GET /api/chamber_of_deputies/reimbursement//` Details from a specific reimbursement. If `receipt_url` wasn't fetched yet, the server **won't** try to fetch it automatically. -##### `GET /api/reimbursement//receipt/` +##### `GET /api/chamber_of_deputies/reimbursement//receipt/` URL of the digitalized version of the receipt of this specific reimbursement. If `receipt_url` wasn't fetched yet, the server **will** try to fetch it automatically. -If you append the parameter `force` (i.e. `GET /api/reimbursement//receipt/?force=1`) the server will re-fetch the receipt URL. +If you append the parameter `force` (i.e. `GET /api/chamber_of_deputies/reimbursement//receipt/?force=1`) the server will re-fetch the receipt URL. Not all receipts are available, so this URL can be `null`. #### Listing reimbursements -##### `GET /api/reimbursement/` +##### `GET /api/chamber_of_deputies/reimbursement/` Lists all reimbursements. @@ -72,7 +72,7 @@ All these endpoints accepts any combination of the following parameters: For example: ``` -GET /api/reimbursement/?year=2016&cnpj_cpf=11111111111111&subquota_id=42&order_by=probability +GET /api/chamber_of_deputies/reimbursement/?year=2016&cnpj_cpf=11111111111111&subquota_id=42&order_by=probability ``` This request will list: @@ -84,7 +84,7 @@ This request will list: Also you can pass more than one value per field (e.g. `document_id=111111,222222`). -##### `GET /api/reimbursement//same_day/` +##### `GET /api/chamber_of_deputies/reimbursement//same_day/` Lists all reimbursements of expenses from the same day as `document_id`. @@ -94,13 +94,13 @@ Subqoutas are categories of expenses that can be reimbursed by congresspeople. #### Listing subquotas -##### `GET /api/subquota/` +##### `GET /api/chamber_of_deputies/subquota/` Lists all subquotas names and IDs. ##### Filtering -Accepts a case-insensitve `LIKE` filter in as the `q` URL parameter (e.g. `GET /api/subquota/?q=meal` list all applicant that have `meal` in their names. +Accepts a case-insensitve `LIKE` filter in as the `q` URL parameter (e.g. `GET /api/chamber_of_deputies/subquota/?q=meal` list all applicant that have `meal` in their names. ### Applicant @@ -108,13 +108,13 @@ An applicant is the person (congressperson or theleadership of aparty or governm #### List applicants -##### `GET /api/applicant/` +##### `GET /api/chamber_of_deputies/applicant/` Lists all names of applicants together with their IDs. ##### Filtering -Accepts a case-insensitve `LIKE` filter in as the `q` URL parameter (e.g. `GET /api/applicant/?q=lideranca` list all applicant that have `lideranca` in their names. +Accepts a case-insensitve `LIKE` filter in as the `q` URL parameter (e.g. `GET /api/chamber_of_deputies/applicant/?q=lideranca` list all applicant that have `lideranca` in their names. ### Company @@ -217,12 +217,12 @@ $ docker-compose run --rm django python manage.py suspicions /mnt/data/suspicion $ docker-compose run --rm django python manage.py tweets ``` -If you're interesting in having a database full of data you can get the datasets running [Rosie](https://github.com/datasciencebr/rosie). +If you're interesting in having a database full of data you can get the datasets running [Rosie](https://github.com/datasciencebr/rosie). To add a fresh new `reimbursements.xz` or `suspicions.xz` brewed by [Rosie](https://github.com/datasciencebr/rosie), or a `companies.xz` you've got from the [toolbox](https://github.com/datasciencebr/serenata-toolbox), you just need copy these files to `contrib/data` and refer to them inside the container from the path `/mnt/data/`. #### Acessing Jabas -You can access it at [`localhost:8000`](http://localhost:8000/) in development mode or [`localhost`](http://localhost:80/) in production mode. +You can access it at [`localhost:8000`](http://localhost:8000/) in development mode or [`localhost`](http://localhost:80/) in production mode. ```console @@ -309,4 +309,4 @@ If you would like to access the Django Admin for an alternative view of the reim ```console $ python manage.py createsuperuser -``` \ No newline at end of file +``` diff --git a/jarbas/api/urls.py b/jarbas/api/urls.py index 7d1e03d..8ec56ef 100644 --- a/jarbas/api/urls.py +++ b/jarbas/api/urls.py @@ -13,22 +13,22 @@ urlpatterns = [ url( - r'^reimbursement/$', + r'^chamber_of_deputies/reimbursement/$', ReimbursementListView.as_view(), name='reimbursement-list' ), url( - r'^reimbursement/(?P\d+)/$', + r'^chamber_of_deputies/reimbursement/(?P\d+)/$', ReimbursementDetailView.as_view(), name='reimbursement-detail' ), url( - r'^reimbursement/(?P\d+)/receipt/$', + r'^chamber_of_deputies/reimbursement/(?P\d+)/receipt/$', ReceiptDetailView.as_view(), name='reimbursement-receipt' ), url( - r'^reimbursement/(?P\d+)/same_day/$', + r'^chamber_of_deputies/reimbursement/(?P\d+)/same_day/$', SameDayReimbursementListView.as_view(), name='reimbursement-same-day' ), @@ -37,6 +37,6 @@ CompanyDetailView.as_view(), name='company-detail' ), - url(r'^applicant/$', ApplicantListView.as_view(), name='applicant-list'), - url(r'^subquota/$', SubquotaListView.as_view(), name='subquota-list') + url(r'^chamber_of_deputies/applicant/$', ApplicantListView.as_view(), name='applicant-list'), + url(r'^chamber_of_deputies/subquota/$', SubquotaListView.as_view(), name='subquota-list') ] diff --git a/jarbas/frontend/elm/Reimbursement/Receipt/Update.elm b/jarbas/frontend/elm/Reimbursement/Receipt/Update.elm index 9cfc590..423e6b8 100644 --- a/jarbas/frontend/elm/Reimbursement/Receipt/Update.elm +++ b/jarbas/frontend/elm/Reimbursement/Receipt/Update.elm @@ -52,6 +52,7 @@ loadUrl reimbursement = path = String.join "/" [ "/api" + , "chamber_of_deputies" , "reimbursement" , toString reimbursement.year , toString reimbursement.applicantId diff --git a/jarbas/frontend/elm/Reimbursement/SameDay/Update.elm b/jarbas/frontend/elm/Reimbursement/SameDay/Update.elm index 83c080c..ba796fe 100644 --- a/jarbas/frontend/elm/Reimbursement/SameDay/Update.elm +++ b/jarbas/frontend/elm/Reimbursement/SameDay/Update.elm @@ -6,7 +6,7 @@ import String {-| Creates an URL from an UniqueId: - getUrl 42 --> "/api/reimbursement/42/same_day/?format=json" + getUrl 42 --> "/api/chamber_of_deputies/reimbursement/42/same_day/?format=json" -} getUrl : Int -> String @@ -14,6 +14,7 @@ getUrl documentId = String.join "/" [ "/api" + , "chamber_of_deputies" , "reimbursement" , toString documentId , "same_day/?format=json" diff --git a/jarbas/frontend/elm/Reimbursement/SameSubquota/Update.elm b/jarbas/frontend/elm/Reimbursement/SameSubquota/Update.elm index 6fc0092..754d923 100644 --- a/jarbas/frontend/elm/Reimbursement/SameSubquota/Update.elm +++ b/jarbas/frontend/elm/Reimbursement/SameSubquota/Update.elm @@ -15,12 +15,12 @@ type alias Filter = {-| Creates an URL from a Filter: getUrl { year = 2016, applicantId = 13, subquotaId = 42, month = 2 } - --> "/api/reimbursement/?applicant_id=13&year=2016&month=2&subquota_id=42&format=json" + --> "/api/chamber_of_deputies/reimbursement/?applicant_id=13&year=2016&month=2&subquota_id=42&format=json" -} getUrl : Filter -> String getUrl filter = - url "/api/reimbursement/" + url "/api/chamber_of_deputies/reimbursement/" [ ( "applicant_id", toString filter.applicantId ) , ( "year", toString filter.year ) , ( "month", toString filter.month ) diff --git a/jarbas/frontend/elm/Reimbursement/Update.elm b/jarbas/frontend/elm/Reimbursement/Update.elm index cab2392..a01da4f 100644 --- a/jarbas/frontend/elm/Reimbursement/Update.elm +++ b/jarbas/frontend/elm/Reimbursement/Update.elm @@ -393,7 +393,7 @@ loadReimbursements lang apiKey query = jsonQuery = ( "format", "json" ) :: convertQuery query in - Http.get (url "/api/reimbursement/" jsonQuery) + Http.get (url "/api/chamber_of_deputies/reimbursement/" jsonQuery) (decoder lang apiKey jsonQuery) |> Http.send LoadReimbursements From e7bf9fb394af969fd3cad17eaa9387e02832e013 Mon Sep 17 00:00:00 2001 From: Giovani Date: Tue, 24 Oct 2017 00:41:44 -0200 Subject: [PATCH 24/34] Divide split api.serializers in chamber_of_deputies.serializers and core.serializers --- .../serializers.py | 31 ++++--------------- jarbas/core/serializers.py | 21 +++++++++++++ 2 files changed, 27 insertions(+), 25 deletions(-) rename jarbas/{api => chamber_of_deputies}/serializers.py (88%) create mode 100644 jarbas/core/serializers.py diff --git a/jarbas/api/serializers.py b/jarbas/chamber_of_deputies/serializers.py similarity index 88% rename from jarbas/api/serializers.py rename to jarbas/chamber_of_deputies/serializers.py index 3acf352..1079162 100644 --- a/jarbas/api/serializers.py +++ b/jarbas/chamber_of_deputies/serializers.py @@ -1,7 +1,7 @@ from rest_framework import serializers from jarbas.chamber_of_deputies.models import Reimbursement -from jarbas.core.models import Activity, Company +from jarbas.core.models import Company class ReimbursementSerializer(serializers.ModelSerializer): @@ -122,23 +122,11 @@ class Meta: fields = ('subquota_id', 'subquota_description') -class ActivitySerializer(serializers.ModelSerializer): - - class Meta: - model = Activity - fields = ('code', 'description') - - -class CompanySerializer(serializers.ModelSerializer): - - main_activity = ActivitySerializer(many=True, read_only=True) - secondary_activity = ActivitySerializer(many=True, read_only=True) - - class Meta: - model = Company - exclude = ('id',) - depth = 1 - +def to_float(number): + try: + return float(number) + except TypeError: + return None def format_cnpj(cnpj): return '{}.{}.{}/{}-{}'.format( @@ -148,10 +136,3 @@ def format_cnpj(cnpj): cnpj[8:12], cnpj[12:14] ) - - -def to_float(number): - try: - return float(number) - except TypeError: - return None diff --git a/jarbas/core/serializers.py b/jarbas/core/serializers.py new file mode 100644 index 0000000..78e558e --- /dev/null +++ b/jarbas/core/serializers.py @@ -0,0 +1,21 @@ +from rest_framework import serializers + +from jarbas.core.models import Activity, Company + + +class ActivitySerializer(serializers.ModelSerializer): + + class Meta: + model = Activity + fields = ('code', 'description') + + +class CompanySerializer(serializers.ModelSerializer): + + main_activity = ActivitySerializer(many=True, read_only=True) + secondary_activity = ActivitySerializer(many=True, read_only=True) + + class Meta: + model = Company + exclude = ('id',) + depth = 1 From 06b1d827522530119424fbfd7d2545fc93217bac Mon Sep 17 00:00:00 2001 From: Giovani Date: Tue, 24 Oct 2017 00:42:29 -0200 Subject: [PATCH 25/34] Update serializers references --- jarbas/api/tests/test_same_day_view.py | 2 +- jarbas/api/views.py | 26 ++++++++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/jarbas/api/tests/test_same_day_view.py b/jarbas/api/tests/test_same_day_view.py index 2fbf45f..82b0742 100644 --- a/jarbas/api/tests/test_same_day_view.py +++ b/jarbas/api/tests/test_same_day_view.py @@ -7,7 +7,7 @@ from jarbas.core.models import Company from jarbas.chamber_of_deputies.tests import sample_reimbursement_data from jarbas.core.tests import sample_company_data -from jarbas.api.serializers import format_cnpj +from jarbas.chamber_of_deputies.serializers import format_cnpj class TestSameDay(TestCase): diff --git a/jarbas/api/views.py b/jarbas/api/views.py index e95ce2f..d9f189a 100644 --- a/jarbas/api/views.py +++ b/jarbas/api/views.py @@ -1,15 +1,21 @@ from django.shortcuts import get_object_or_404 from rest_framework.generics import ListAPIView, RetrieveAPIView -from jarbas.api import serializers -from jarbas.chamber_of_deputies.models import Reimbursement from jarbas.core.models import Company +from jarbas.core.serializers import CompanySerializer +from jarbas.chamber_of_deputies.models import Reimbursement +from jarbas.chamber_of_deputies.serializers import (ReimbursementSerializer, + ReceiptSerializer, + SameDayReimbursementSerializer, + ApplicantSerializer, + SubquotaSerializer, + format_cnpj) class ReimbursementListView(ListAPIView): queryset = Reimbursement.objects.all() - serializer_class = serializers.ReimbursementSerializer + serializer_class = ReimbursementSerializer def get(self, request): @@ -68,14 +74,14 @@ class ReimbursementDetailView(RetrieveAPIView): lookup_field = 'document_id' queryset = Reimbursement.objects.all() - serializer_class = serializers.ReimbursementSerializer + serializer_class = ReimbursementSerializer class ReceiptDetailView(RetrieveAPIView): lookup_field = 'document_id' queryset = Reimbursement.objects.all() - serializer_class = serializers.ReceiptSerializer + serializer_class = ReceiptSerializer def get_object(self): obj = super().get_object() @@ -86,7 +92,7 @@ def get_object(self): class SameDayReimbursementListView(ListAPIView): - serializer_class = serializers.SameDayReimbursementSerializer + serializer_class = SameDayReimbursementSerializer def get_queryset(self): return Reimbursement.objects.same_day_as(**self.kwargs) @@ -94,7 +100,7 @@ def get_queryset(self): class ApplicantListView(ListAPIView): - serializer_class = serializers.ApplicantSerializer + serializer_class = ApplicantSerializer def get_queryset(self): query = self.request.query_params.get('q') @@ -104,7 +110,7 @@ def get_queryset(self): class SubquotaListView(ListAPIView): - serializer_class = serializers.SubquotaSerializer + serializer_class = SubquotaSerializer def get_queryset(self): query = self.request.query_params.get('q') @@ -116,8 +122,8 @@ class CompanyDetailView(RetrieveAPIView): lookup_field = 'cnpj' queryset = Company.objects.all() - serializer_class = serializers.CompanySerializer + serializer_class = CompanySerializer def get_object(self): cnpj = self.kwargs.get(self.lookup_field, '00000000000000') - return get_object_or_404(Company, cnpj=serializers.format_cnpj(cnpj)) + return get_object_or_404(Company, cnpj=format_cnpj(cnpj)) From 219538486fd401a613d58dd64944bf62b74d7560 Mon Sep 17 00:00:00 2001 From: Giovani Date: Tue, 24 Oct 2017 00:47:17 -0200 Subject: [PATCH 26/34] 2 blank lines - pep8 fix --- jarbas/chamber_of_deputies/serializers.py | 1 + 1 file changed, 1 insertion(+) diff --git a/jarbas/chamber_of_deputies/serializers.py b/jarbas/chamber_of_deputies/serializers.py index 1079162..553f6dc 100644 --- a/jarbas/chamber_of_deputies/serializers.py +++ b/jarbas/chamber_of_deputies/serializers.py @@ -128,6 +128,7 @@ def to_float(number): except TypeError: return None + def format_cnpj(cnpj): return '{}.{}.{}/{}-{}'.format( cnpj[0:2], From fb5aa3f3bcb74b4aab182c9dab39c821a709e333 Mon Sep 17 00:00:00 2001 From: Giovani Date: Thu, 26 Oct 2017 10:48:46 -0200 Subject: [PATCH 27/34] Move api urls and views to chamber of deputies and core --- jarbas/{api => chamber_of_deputies}/urls.py | 14 ++++---------- jarbas/{api => chamber_of_deputies}/views.py | 17 +---------------- jarbas/core/urls.py | 12 ++++++++++++ jarbas/core/views.py | 16 ++++++++++++++++ 4 files changed, 33 insertions(+), 26 deletions(-) rename jarbas/{api => chamber_of_deputies}/urls.py (85%) rename jarbas/{api => chamber_of_deputies}/views.py (87%) create mode 100644 jarbas/core/urls.py create mode 100644 jarbas/core/views.py diff --git a/jarbas/api/urls.py b/jarbas/chamber_of_deputies/urls.py similarity index 85% rename from jarbas/api/urls.py rename to jarbas/chamber_of_deputies/urls.py index 8ec56ef..a835cab 100644 --- a/jarbas/api/urls.py +++ b/jarbas/chamber_of_deputies/urls.py @@ -1,12 +1,11 @@ from django.conf.urls import url -from jarbas.api.views import ( - ApplicantListView, - CompanyDetailView, - ReceiptDetailView, - ReimbursementDetailView, +from jarbas.chamber_of_deputies.views import ( ReimbursementListView, + ReimbursementDetailView, + ReceiptDetailView, SameDayReimbursementListView, + ApplicantListView, SubquotaListView, ) @@ -32,11 +31,6 @@ SameDayReimbursementListView.as_view(), name='reimbursement-same-day' ), - url( - r'^company/(?P\d{14})/$', - CompanyDetailView.as_view(), - name='company-detail' - ), url(r'^chamber_of_deputies/applicant/$', ApplicantListView.as_view(), name='applicant-list'), url(r'^chamber_of_deputies/subquota/$', SubquotaListView.as_view(), name='subquota-list') ] diff --git a/jarbas/api/views.py b/jarbas/chamber_of_deputies/views.py similarity index 87% rename from jarbas/api/views.py rename to jarbas/chamber_of_deputies/views.py index d9f189a..5a3dc21 100644 --- a/jarbas/api/views.py +++ b/jarbas/chamber_of_deputies/views.py @@ -1,15 +1,11 @@ -from django.shortcuts import get_object_or_404 from rest_framework.generics import ListAPIView, RetrieveAPIView -from jarbas.core.models import Company -from jarbas.core.serializers import CompanySerializer from jarbas.chamber_of_deputies.models import Reimbursement from jarbas.chamber_of_deputies.serializers import (ReimbursementSerializer, ReceiptSerializer, SameDayReimbursementSerializer, ApplicantSerializer, - SubquotaSerializer, - format_cnpj) + SubquotaSerializer) class ReimbursementListView(ListAPIView): @@ -116,14 +112,3 @@ def get_queryset(self): query = self.request.query_params.get('q') args = ('subquota_id', 'subquota_description', query) return Reimbursement.objects.list_distinct(*args) - - -class CompanyDetailView(RetrieveAPIView): - - lookup_field = 'cnpj' - queryset = Company.objects.all() - serializer_class = CompanySerializer - - def get_object(self): - cnpj = self.kwargs.get(self.lookup_field, '00000000000000') - return get_object_or_404(Company, cnpj=format_cnpj(cnpj)) diff --git a/jarbas/core/urls.py b/jarbas/core/urls.py new file mode 100644 index 0000000..cce3df2 --- /dev/null +++ b/jarbas/core/urls.py @@ -0,0 +1,12 @@ +from django.conf.urls import url + +from jarbas.core.views import CompanyDetailView + + +urlpatterns = [ + url( + r'^company/(?P\d{14})/$', + CompanyDetailView.as_view(), + name='company-detail' + ), +] diff --git a/jarbas/core/views.py b/jarbas/core/views.py new file mode 100644 index 0000000..9cc29ce --- /dev/null +++ b/jarbas/core/views.py @@ -0,0 +1,16 @@ +from django.shortcuts import get_object_or_404 +from rest_framework.generics import RetrieveAPIView + +from jarbas.core.models import Company +from jarbas.core.serializers import CompanySerializer +from jarbas.chamber_of_deputies.serializers import format_cnpj + +class CompanyDetailView(RetrieveAPIView): + + lookup_field = 'cnpj' + queryset = Company.objects.all() + serializer_class = CompanySerializer + + def get_object(self): + cnpj = self.kwargs.get(self.lookup_field, '00000000000000') + return get_object_or_404(Company, cnpj=format_cnpj(cnpj)) From ea125aa2a1d73ac9d2fb173a0b40e84fe537332f Mon Sep 17 00:00:00 2001 From: Giovani Date: Thu, 26 Oct 2017 11:02:18 -0200 Subject: [PATCH 28/34] Update api/chamber_of_deputies urls and related --- jarbas/chamber_of_deputies/urls.py | 12 ++++++------ jarbas/urls.py | 8 ++++++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/jarbas/chamber_of_deputies/urls.py b/jarbas/chamber_of_deputies/urls.py index a835cab..0890a69 100644 --- a/jarbas/chamber_of_deputies/urls.py +++ b/jarbas/chamber_of_deputies/urls.py @@ -12,25 +12,25 @@ urlpatterns = [ url( - r'^chamber_of_deputies/reimbursement/$', + r'^reimbursement/$', ReimbursementListView.as_view(), name='reimbursement-list' ), url( - r'^chamber_of_deputies/reimbursement/(?P\d+)/$', + r'^reimbursement/(?P\d+)/$', ReimbursementDetailView.as_view(), name='reimbursement-detail' ), url( - r'^chamber_of_deputies/reimbursement/(?P\d+)/receipt/$', + r'^reimbursement/(?P\d+)/receipt/$', ReceiptDetailView.as_view(), name='reimbursement-receipt' ), url( - r'^chamber_of_deputies/reimbursement/(?P\d+)/same_day/$', + r'^reimbursement/(?P\d+)/same_day/$', SameDayReimbursementListView.as_view(), name='reimbursement-same-day' ), - url(r'^chamber_of_deputies/applicant/$', ApplicantListView.as_view(), name='applicant-list'), - url(r'^chamber_of_deputies/subquota/$', SubquotaListView.as_view(), name='subquota-list') + url(r'^applicant/$', ApplicantListView.as_view(), name='applicant-list'), + url(r'^subquota/$', SubquotaListView.as_view(), name='subquota-list') ] diff --git a/jarbas/urls.py b/jarbas/urls.py index 1862aac..b5776d3 100644 --- a/jarbas/urls.py +++ b/jarbas/urls.py @@ -21,8 +21,12 @@ urlpatterns = [ url(r'^$', home, name='home'), - url(r'^api/', include('jarbas.api.urls', namespace='api')), - url(r'^dashboard/', include('jarbas.dashboard.urls')) + url(r'^dashboard/', include('jarbas.dashboard.urls')), + url(r'^api/', include('jarbas.core.urls', namespace='core')), + url( + r'^api/chamber_of_deputies/', + include('jarbas.chamber_of_deputies.urls', namespace='chamber_of_deputies') + ) ] if settings.DEBUG: From cef9e5220b3a895db737fc04853effa88819c0cc Mon Sep 17 00:00:00 2001 From: Giovani Date: Thu, 26 Oct 2017 11:03:05 -0200 Subject: [PATCH 29/34] Update namespaces related to api --- jarbas/api/tests/test_applicant_view.py | 2 +- jarbas/api/tests/test_company_view.py | 4 ++-- jarbas/api/tests/test_reimbursement_view.py | 16 ++++++++++------ jarbas/api/tests/test_same_day_view.py | 2 +- jarbas/api/tests/test_subquota_view.py | 2 +- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/jarbas/api/tests/test_applicant_view.py b/jarbas/api/tests/test_applicant_view.py index e34ffd6..87fae87 100644 --- a/jarbas/api/tests/test_applicant_view.py +++ b/jarbas/api/tests/test_applicant_view.py @@ -12,7 +12,7 @@ class TestApplicant(TestCase): def setUp(self): Reimbursement.objects.create(**sample_reimbursement_data) - self.url = resolve_url('api:applicant-list') + self.url = resolve_url('chamber_of_deputies:applicant-list') def test_status_code(self): resp = self.client.get(self.url) diff --git a/jarbas/api/tests/test_company_view.py b/jarbas/api/tests/test_company_view.py index 7f32b7b..d106481 100644 --- a/jarbas/api/tests/test_company_view.py +++ b/jarbas/api/tests/test_company_view.py @@ -16,7 +16,7 @@ def setUp(self): self.company.main_activity.add(activity) self.company.save() cnpj = re.compile(r'\D').sub('', self.company.cnpj) - self.url = resolve_url('api:company-detail', cnpj) + self.url = resolve_url('core:company-detail', cnpj) class TestGet(TestApi): @@ -42,7 +42,7 @@ def test_content(self): class TestGetNonExistentCompany(TestApi): def setUp(self): - url = resolve_url('api:company-detail', '42424242424242') + url = resolve_url('core:company-detail', '42424242424242') self.resp = self.client.get(url) def test_status_code(self): diff --git a/jarbas/api/tests/test_reimbursement_view.py b/jarbas/api/tests/test_reimbursement_view.py index db21b84..33ec8eb 100644 --- a/jarbas/api/tests/test_reimbursement_view.py +++ b/jarbas/api/tests/test_reimbursement_view.py @@ -26,7 +26,7 @@ class TestListApi(TestCase): def setUp(self): get_reimbursement(quantity=3) - self.url = resolve_url('api:reimbursement-list') + self.url = resolve_url('chamber_of_deputies:reimbursement-list') def test_status(self): resp = self.client.get(self.url) @@ -104,7 +104,7 @@ def setUp(self): self.sample_response = get_sample_reimbursement_api_response( self.reimbursement ) - url = resolve_url('api:reimbursement-detail', + url = resolve_url('chamber_of_deputies:reimbursement-detail', document_id=self.reimbursement.document_id) self.resp = self.client.get(url) self.maxDiff = 2 ** 11 @@ -122,7 +122,7 @@ def test_contents_with_tweet(self): mixer.blend(Tweet, reimbursement=self.reimbursement, status=status) expected = self.sample_response expected['rosies_tweet'] = self.reimbursement.tweet.get_url() - url = resolve_url('api:reimbursement-detail', + url = resolve_url('chamber_of_deputies:reimbursement-detail', document_id=self.reimbursement.document_id) resp = self.client.get(url) contents = loads(resp.content.decode('utf-8')) @@ -132,7 +132,7 @@ def test_contents_with_receipt_text(self): expected = self.sample_response expected['rosies_tweet'] = None expected['receipt_text'] = self.reimbursement.receipt_text - url = resolve_url('api:reimbursement-detail', + url = resolve_url('chamber_of_deputies:reimbursement-detail', document_id=self.reimbursement.document_id) resp = self.client.get(url) contents = loads(resp.content.decode('utf-8')) @@ -150,9 +150,13 @@ def setUp(self): ) self.reimbursement_no_receipt = get_reimbursement(receipt_url=None) self.url = resolve_url( - 'api:reimbursement-receipt', document_id=self.reimbursement.document_id) + 'chamber_of_deputies:reimbursement-receipt', + document_id=self.reimbursement.document_id + ) self.url_no_receipt = resolve_url( - 'api:reimbursement-receipt', document_id=self.reimbursement_no_receipt.document_id) + 'chamber_of_deputies:reimbursement-receipt', + document_id=self.reimbursement_no_receipt.document_id + ) @patch('jarbas.chamber_of_deputies.models.head') def test_fetch_existing_receipt(self, mocked_head): diff --git a/jarbas/api/tests/test_same_day_view.py b/jarbas/api/tests/test_same_day_view.py index 82b0742..aed92e5 100644 --- a/jarbas/api/tests/test_same_day_view.py +++ b/jarbas/api/tests/test_same_day_view.py @@ -46,7 +46,7 @@ def setUp(self): data4['cnpj_cpf'] = '11111111111111' Reimbursement.objects.create(**data4) - url = resolve_url('api:reimbursement-same-day', document_id=84) + url = resolve_url('chamber_of_deputies:reimbursement-same-day', document_id=84) self.resp = self.client.get(url) def test_status_code(self): diff --git a/jarbas/api/tests/test_subquota_view.py b/jarbas/api/tests/test_subquota_view.py index 8b62628..dfec513 100644 --- a/jarbas/api/tests/test_subquota_view.py +++ b/jarbas/api/tests/test_subquota_view.py @@ -12,7 +12,7 @@ class TestSubquota(TestCase): def setUp(self): Reimbursement.objects.create(**sample_reimbursement_data) - self.url = resolve_url('api:subquota-list') + self.url = resolve_url('chamber_of_deputies:subquota-list') def test_status_code(self): resp = self.client.get(self.url) From c0464b16326ecfc03b4fb175faf230639768409b Mon Sep 17 00:00:00 2001 From: Giovani Date: Thu, 26 Oct 2017 11:13:59 -0200 Subject: [PATCH 30/34] Move tests from api to chamber_of_deputies and core --- jarbas/chamber_of_deputies/tests/__init__.py | 48 +++++++++++++++++++ .../tests/test_applicant_view.py | 0 .../tests/test_reimbursement_view.py | 2 +- .../tests/test_same_day_view.py | 0 .../tests/test_subquota_view.py | 0 .../{api => core}/tests/test_company_view.py | 0 6 files changed, 49 insertions(+), 1 deletion(-) rename jarbas/{api => chamber_of_deputies}/tests/test_applicant_view.py (100%) rename jarbas/{api => chamber_of_deputies}/tests/test_reimbursement_view.py (98%) rename jarbas/{api => chamber_of_deputies}/tests/test_same_day_view.py (100%) rename jarbas/{api => chamber_of_deputies}/tests/test_subquota_view.py (100%) rename jarbas/{api => core}/tests/test_company_view.py (100%) diff --git a/jarbas/chamber_of_deputies/tests/__init__.py b/jarbas/chamber_of_deputies/tests/__init__.py index b66658b..563f5af 100644 --- a/jarbas/chamber_of_deputies/tests/__init__.py +++ b/jarbas/chamber_of_deputies/tests/__init__.py @@ -1,5 +1,6 @@ from datetime import date from random import randrange +from django.utils import timezone from jarbas.chamber_of_deputies.models import Tweet @@ -56,3 +57,50 @@ def random_tweet_status(): min_range = 9223372036854775807 # max big integer should be the minimum max_range = 10 ** status.max_digits # field limit return randrange(min_range, max_range) + + +def get_sample_reimbursement_api_response(obj): + + # freezegun API to return timezone aware objects is not simple + last_update_naive = timezone.make_naive(obj.last_update) + + return dict( + applicant_id=obj.applicant_id, + batch_number=obj.batch_number, + cnpj_cpf=obj.cnpj_cpf, + congressperson_document=obj.congressperson_document, + congressperson_id=obj.congressperson_id, + congressperson_name=obj.congressperson_name, + document_id=obj.document_id, + document_number=obj.document_number, + document_type=obj.document_type, + document_value=float(obj.document_value), + installment=obj.installment, + issue_date=obj.issue_date.strftime('%Y-%m-%d'), + leg_of_the_trip=obj.leg_of_the_trip, + month=obj.month, + party=obj.party, + passenger=obj.passenger, + all_reimbursement_numbers=obj.all_reimbursement_numbers, + all_reimbursement_values=obj.all_reimbursement_values, + all_net_values=obj.all_net_values, + remark_value=obj.remark_value, + state=obj.state, + subquota_description=obj.subquota_description, + subquota_group_description=obj.subquota_group_description, + subquota_group_id=obj.subquota_group_id, + subquota_id=obj.subquota_id, + supplier=obj.supplier, + term=obj.term, + term_id=obj.term_id, + total_net_value=float(obj.total_net_value), + total_reimbursement_value=obj.total_reimbursement_value, + year=obj.year, + probability=obj.probability, + suspicions=obj.suspicions, + receipt_text=obj.receipt_text, + last_update=last_update_naive.strftime('%Y-%m-%dT%H:%M:%S-03:00'), + available_in_latest_dataset=obj.available_in_latest_dataset, + receipt=dict(fetched=obj.receipt_fetched, url=obj.receipt_url), + search_vector=None + ) diff --git a/jarbas/api/tests/test_applicant_view.py b/jarbas/chamber_of_deputies/tests/test_applicant_view.py similarity index 100% rename from jarbas/api/tests/test_applicant_view.py rename to jarbas/chamber_of_deputies/tests/test_applicant_view.py diff --git a/jarbas/api/tests/test_reimbursement_view.py b/jarbas/chamber_of_deputies/tests/test_reimbursement_view.py similarity index 98% rename from jarbas/api/tests/test_reimbursement_view.py rename to jarbas/chamber_of_deputies/tests/test_reimbursement_view.py index 33ec8eb..0a65530 100644 --- a/jarbas/api/tests/test_reimbursement_view.py +++ b/jarbas/chamber_of_deputies/tests/test_reimbursement_view.py @@ -7,7 +7,7 @@ from freezegun import freeze_time from mixer.backend.django import mixer -from jarbas.api.tests import get_sample_reimbursement_api_response +from jarbas.chamber_of_deputies.tests import get_sample_reimbursement_api_response from jarbas.chamber_of_deputies.models import Reimbursement, Tweet from jarbas.chamber_of_deputies.tests import random_tweet_status diff --git a/jarbas/api/tests/test_same_day_view.py b/jarbas/chamber_of_deputies/tests/test_same_day_view.py similarity index 100% rename from jarbas/api/tests/test_same_day_view.py rename to jarbas/chamber_of_deputies/tests/test_same_day_view.py diff --git a/jarbas/api/tests/test_subquota_view.py b/jarbas/chamber_of_deputies/tests/test_subquota_view.py similarity index 100% rename from jarbas/api/tests/test_subquota_view.py rename to jarbas/chamber_of_deputies/tests/test_subquota_view.py diff --git a/jarbas/api/tests/test_company_view.py b/jarbas/core/tests/test_company_view.py similarity index 100% rename from jarbas/api/tests/test_company_view.py rename to jarbas/core/tests/test_company_view.py From eb6ba526fead822869af6fc7a262054879a2cae9 Mon Sep 17 00:00:00 2001 From: Giovani Date: Thu, 26 Oct 2017 11:14:20 -0200 Subject: [PATCH 31/34] Remove api folder --- jarbas/api/__init__.py | 0 jarbas/api/tests/__init__.py | 48 ------------------------------------ 2 files changed, 48 deletions(-) delete mode 100644 jarbas/api/__init__.py delete mode 100644 jarbas/api/tests/__init__.py diff --git a/jarbas/api/__init__.py b/jarbas/api/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/jarbas/api/tests/__init__.py b/jarbas/api/tests/__init__.py deleted file mode 100644 index 3a402cb..0000000 --- a/jarbas/api/tests/__init__.py +++ /dev/null @@ -1,48 +0,0 @@ -from django.utils import timezone - - -def get_sample_reimbursement_api_response(obj): - - # freezegun API to return timezone aware objects is not simple - last_update_naive = timezone.make_naive(obj.last_update) - - return dict( - applicant_id=obj.applicant_id, - batch_number=obj.batch_number, - cnpj_cpf=obj.cnpj_cpf, - congressperson_document=obj.congressperson_document, - congressperson_id=obj.congressperson_id, - congressperson_name=obj.congressperson_name, - document_id=obj.document_id, - document_number=obj.document_number, - document_type=obj.document_type, - document_value=float(obj.document_value), - installment=obj.installment, - issue_date=obj.issue_date.strftime('%Y-%m-%d'), - leg_of_the_trip=obj.leg_of_the_trip, - month=obj.month, - party=obj.party, - passenger=obj.passenger, - all_reimbursement_numbers=obj.all_reimbursement_numbers, - all_reimbursement_values=obj.all_reimbursement_values, - all_net_values=obj.all_net_values, - remark_value=obj.remark_value, - state=obj.state, - subquota_description=obj.subquota_description, - subquota_group_description=obj.subquota_group_description, - subquota_group_id=obj.subquota_group_id, - subquota_id=obj.subquota_id, - supplier=obj.supplier, - term=obj.term, - term_id=obj.term_id, - total_net_value=float(obj.total_net_value), - total_reimbursement_value=obj.total_reimbursement_value, - year=obj.year, - probability=obj.probability, - suspicions=obj.suspicions, - receipt_text=obj.receipt_text, - last_update=last_update_naive.strftime('%Y-%m-%dT%H:%M:%S-03:00'), - available_in_latest_dataset=obj.available_in_latest_dataset, - receipt=dict(fetched=obj.receipt_fetched, url=obj.receipt_url), - search_vector=None - ) From 30e050b836a4e8df3f918738b78552a070a1a176 Mon Sep 17 00:00:00 2001 From: Giovani Date: Thu, 26 Oct 2017 11:16:28 -0200 Subject: [PATCH 32/34] Add blank line - pep8 --- jarbas/core/views.py | 1 + 1 file changed, 1 insertion(+) diff --git a/jarbas/core/views.py b/jarbas/core/views.py index 9cc29ce..1aa2c47 100644 --- a/jarbas/core/views.py +++ b/jarbas/core/views.py @@ -5,6 +5,7 @@ from jarbas.core.serializers import CompanySerializer from jarbas.chamber_of_deputies.serializers import format_cnpj + class CompanyDetailView(RetrieveAPIView): lookup_field = 'cnpj' From 70cb4d1aa590d967d6cf87c69bed5f2026a09bcd Mon Sep 17 00:00:00 2001 From: Giovani Date: Thu, 26 Oct 2017 11:18:05 -0200 Subject: [PATCH 33/34] Remove api from installed apps --- jarbas/settings.py | 1 - 1 file changed, 1 deletion(-) diff --git a/jarbas/settings.py b/jarbas/settings.py index 44ca3d2..25d55d3 100644 --- a/jarbas/settings.py +++ b/jarbas/settings.py @@ -46,7 +46,6 @@ 'rest_framework', 'jarbas.core.app.CoreConfig', 'jarbas.chamber_of_deputies.app.ChamberOfDeputiesConfig', - 'jarbas.api', 'jarbas.frontend', 'jarbas.dashboard', 'django.contrib.admin', From fa2053e6c6985da9b4c098fdb735d17f71dada12 Mon Sep 17 00:00:00 2001 From: Giovani Date: Thu, 26 Oct 2017 11:24:37 -0200 Subject: [PATCH 34/34] Omit chamber_of_deputies tests and migrations from coverage --- .coveragerc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.coveragerc b/.coveragerc index 0bdbe6e..f875d66 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,7 +1,8 @@ [run] source = jarbas omit = - jarbas/api/tests/*.py + jarbas/chamber_of_deputies/tests/*.py + jarbas/chamber_of_deputies/migrations/*.py jarbas/core/migrations/*.py jarbas/core/tests/*.py jarbas/frontend/tests/*.py