-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Kalkuli/hotfix_170_atualizar_coberturas_co…
…deClimate Solve #127 Hotfix Atualizar Cobertura Code Climate
- Loading branch information
Showing
9 changed files
with
133 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,6 @@ __pycache__ | |
env | ||
.vscode/ | ||
htmlcov/ | ||
arquivo.csv | ||
.coverage | ||
coverage.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import csv | ||
from flask import Flask, jsonify, Blueprint, request, send_file | ||
|
||
|
||
export_blueprint = Blueprint('export', __name__) | ||
|
||
@export_blueprint.route('/export', methods=['POST']) | ||
def exports(): | ||
post_data = request.get_json() | ||
|
||
error_response = { | ||
'status': 'fail', | ||
'message': 'wrong json' | ||
} | ||
|
||
if not post_data: | ||
return jsonify(error_response), 400 | ||
|
||
|
||
employ_data = open('./project/assets/arquivo.csv', 'w') | ||
csvwriter = csv.writer(employ_data) | ||
|
||
receipts = post_data.get('receipts') | ||
total_cost = post_data.get('total_cost') | ||
|
||
csvwriter.writerow(['CNPJ','ID da Empresa','Data de Emissão','Local','Imposto','Valor', 'Valor total']) | ||
|
||
count = 0 | ||
|
||
for emp in receipts: | ||
if not count: | ||
csvwriter.writerow([emp['cnpj'], | ||
emp['company_id'], | ||
emp['emission_date'], | ||
emp['emission_place'], | ||
emp['tax_value'], | ||
emp['total_price'], | ||
total_cost]) | ||
count += 1 | ||
else: | ||
csvwriter.writerow([emp['cnpj'], | ||
emp['company_id'], | ||
emp['emission_date'], | ||
emp['emission_place'], | ||
emp['tax_value'], | ||
emp['total_price']]) | ||
|
||
employ_data.close() | ||
|
||
return send_file('./assets/arquivo.csv', mimetype='text/csv', | ||
attachment_filename='arquivo.csv', | ||
as_attachment=True), 200 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import json | ||
from project.tests.base import BaseTestCase | ||
import unittest | ||
|
||
|
||
class TestExportService(BaseTestCase): | ||
|
||
def test_exports(self): | ||
|
||
with self.client: | ||
|
||
response = self.client.post( | ||
'/export', | ||
data=json.dumps({ | ||
"receipts": [ | ||
{ | ||
"cnpj": "000.000.000/0000-00", | ||
"company_id": 1234, | ||
"emission_date": "2018-11-10", | ||
"emission_place": "place", | ||
"id": 1, | ||
"tax_value": 123.12, | ||
"total_price": 456.45 | ||
}, | ||
{ | ||
"cnpj": "000.000.000/0000-00", | ||
"company_id": 1234, | ||
"emission_date": "2018-10-10", | ||
"emission_place": "place", | ||
"id": 2, | ||
"tax_value": 123.12, | ||
"total_price": 456.45 | ||
}, | ||
{ | ||
"cnpj": "000.000.000/0000-00", | ||
"company_id": 1234, | ||
"emission_date": "2018-10-12", | ||
"emission_place": "place", | ||
"id": 3, | ||
"tax_value": 123.12, | ||
"total_price": 456.45 | ||
} | ||
], | ||
"total_cost": "1369.35" | ||
}), | ||
content_type='application/json', | ||
) | ||
|
||
self.assertEqual(response.status_code, 200) | ||
|
||
def test_not_json(self): | ||
|
||
with self.client: | ||
|
||
response = self.client.post( | ||
'/export', | ||
data=json.dumps({}), | ||
content_type='application/json', | ||
) | ||
|
||
data = json.loads(response.data.decode()) | ||
|
||
self.assertEqual(response.status_code, 400) | ||
self.assertIn('wrong json', data['message']) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |