From d6d263d8ee0198c47899f59801f9b61dcc56d97e Mon Sep 17 00:00:00 2001 From: Gabriela Date: Fri, 4 Oct 2019 09:02:33 -0300 Subject: [PATCH 1/9] add wf python app --- .github/workflows/pythonapp.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/pythonapp.yml diff --git a/.github/workflows/pythonapp.yml b/.github/workflows/pythonapp.yml new file mode 100644 index 0000000..dc686ab --- /dev/null +++ b/.github/workflows/pythonapp.yml @@ -0,0 +1,32 @@ +name: Python application + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + - name: Set up Python 3.7 + uses: actions/setup-python@v1 + with: + python-version: 3.7 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: Pylint + run: | + # list out files that are in directory and working tree + # grep -v will exclude the files being considered for pylint + # grep -E will matches files having .py extension + # This command will help to pass required python files to pylint along with pylint_djanog plugin + # Pylint with -E option will display only if there is any error + git ls-files | grep -v 'migrations' | grep -v 'settings.py' | grep -v 'manage.py' | grep -E '.py$' | + xargs pylint -E --load-plugins=pylint_django + - name: Test with pytest + run: | + pip install pytest + pytest From ff6b92bde6489721dfabafa4487d03c731912dc6 Mon Sep 17 00:00:00 2001 From: Gabriela Date: Fri, 4 Oct 2019 09:02:42 -0300 Subject: [PATCH 2/9] add wf node --- .github/workflows/nodejs.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/nodejs.yml diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml new file mode 100644 index 0000000..b15baf3 --- /dev/null +++ b/.github/workflows/nodejs.yml @@ -0,0 +1,26 @@ +name: Node CI + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [8.x, 10.x, 12.x] + + steps: + - uses: actions/checkout@v1 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - name: npm install, build, and test + run: | + npm install + npm run build --if-present + npm test + env: + CI: true From 6566aadf61fa3704007ac3edcf50891764f2503b Mon Sep 17 00:00:00 2001 From: Gabriela Cavalcante da Silva Date: Fri, 4 Oct 2019 09:05:53 -0300 Subject: [PATCH 3/9] update requirements --- requirements.txt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 7e633f8..d5015b8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,7 +12,7 @@ django-extensions==2.1.4 django-localflavor==2.1 django-sslserver==0.20 django-webpack-loader==0.6.0 -djangorestframework~>3.9.1 +djangorestframework>=3.9.1 gunicorn==19.9.0 idna==2.7 Pillow==5.3.0 @@ -27,3 +27,12 @@ six==1.11.0 sqlparse==0.2.4 whitenoise==4.1.2 XlsxWriter==1.1.2 +# test and cov +coverage==4.5.2 +pytest +pytest-django +pytest-cov +# lint +pylint==2.3.0 +pylint-django==2.0.6 +pylint-plugin-utils==0.5 \ No newline at end of file From 505df45eee527625f26f67fc4fe3cdec0a378d77 Mon Sep 17 00:00:00 2001 From: Gabriela Date: Fri, 4 Oct 2019 09:07:44 -0300 Subject: [PATCH 4/9] Update nodejs.yml --- .github/workflows/nodejs.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index b15baf3..c7fd2c9 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -19,6 +19,8 @@ jobs: node-version: ${{ matrix.node-version }} - name: npm install, build, and test run: | + git submodule init + git submodule update npm install npm run build --if-present npm test From ff381ca3aa9c135ece4672a962010c6392e21efe Mon Sep 17 00:00:00 2001 From: Gabriela Date: Fri, 4 Oct 2019 09:10:52 -0300 Subject: [PATCH 5/9] Update nodejs.yml --- .github/workflows/nodejs.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index c7fd2c9..06facdd 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -21,8 +21,8 @@ jobs: run: | git submodule init git submodule update - npm install - npm run build --if-present - npm test + sudo apt-get install yarn + yarn install + yarn build env: CI: true From c95524fac7cb20c2434cf5b6803cf21be41310a7 Mon Sep 17 00:00:00 2001 From: Gabriela Cavalcante da Silva Date: Fri, 4 Oct 2019 09:35:56 -0300 Subject: [PATCH 6/9] fix lint but and add ignored classes --- .pylintrc | 2 ++ apps/api/senders.py | 26 +++++++++++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) create mode 100644 .pylintrc diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..d834dea --- /dev/null +++ b/.pylintrc @@ -0,0 +1,2 @@ +[TYPECHECK] +ignored-classes=__proxy__ \ No newline at end of file diff --git a/apps/api/senders.py b/apps/api/senders.py index fd469ba..e388e8e 100644 --- a/apps/api/senders.py +++ b/apps/api/senders.py @@ -2,13 +2,13 @@ from django.conf import settings from django.utils.translation import gettext as _ -from sendgrid import * -from sendgrid.helpers.mail import * +from sendgrid import SendGridAPIClient +from sendgrid.helpers.mail import Mail, Email, Attachment, Personalization, Substitution, Category from apps.api.qrcode import gen_qrcode from .models import Attendee, Event -sg = sendgrid.SendGridAPIClient(apikey=settings.SENDGRID_API_KEY) +sg = SendGridAPIClient(apikey=settings.SENDGRID_API_KEY) templates = settings.SENDGRID_TEMPLATES @@ -27,7 +27,8 @@ def send_registration_mail(attendee: Attendee, event: Event): mail.add_attachment(attachment1) personalization = Personalization() - personalization.add_substitution(Substitution("%first_name%", attendee.name.split()[0])) + personalization.add_substitution(Substitution( + "%first_name%", attendee.name.split()[0])) personalization.add_substitution(Substitution("%event_name%", event.name)) personalization.add_to(Email(attendee.email, attendee.name)) mail.add_personalization(personalization) @@ -60,20 +61,22 @@ def send_certificate_mail(name, email, event, cpf=None): event_date = event.event_day.event.formated_dates event_min_percent = event.event_day.event.certificate_minimum_time - - cpf_text = _(', bearer of the registry number %(cpf)s,') % {'cpf': cpf} if cpf else '' + cpf_text = _(', bearer of the registry number %(cpf)s,') % { + 'cpf': cpf} if cpf else '' data = {'name': name, 'event': event.name, 'cpf': cpf_text, 'event_date': event_date, 'event_place': event_place, 'event_duration': event_duration, 'event_min_percent': event_min_percent} certificate_data = event.certificate_model.generate_certificate(data) - attachment1.content = base64.b64encode(certificate_data.read()).decode('ascii') + attachment1.content = base64.b64encode( + certificate_data.read()).decode('ascii') attachment1.filename = template['FILENAME'] mail.add_attachment(attachment1) personalization = Personalization() - personalization.add_substitution(Substitution("%first_name%", name.split()[0])) + personalization.add_substitution( + Substitution("%first_name%", name.split()[0])) personalization.add_substitution(Substitution("%event_name%", event.name)) personalization.add_to(Email(email, name)) mail.add_personalization(personalization) @@ -82,7 +85,7 @@ def send_certificate_mail(name, email, event, cpf=None): response = sg.client.mail.send.post(request_body=mail.get()) return True except Exception as e: - print(e.body) + print(response.body) raise e @@ -95,7 +98,8 @@ def send_no_certificate_mail(name, email, event): mail.add_category(Category(template['CATEGORY'])) personalization = Personalization() - personalization.add_substitution(Substitution("%first_name%", name.split()[0])) + personalization.add_substitution( + Substitution("%first_name%", name.split()[0])) personalization.add_substitution(Substitution("%event_name%", event.name)) personalization.add_to(Email(email, name)) mail.add_personalization(personalization) @@ -104,5 +108,5 @@ def send_no_certificate_mail(name, email, event): response = sg.client.mail.send.post(request_body=mail.get()) return True except Exception as e: - print(e.body) + print(response.body) raise e From fbea7d3610b87535494e874b35d5186b7ef722fa Mon Sep 17 00:00:00 2001 From: Gabriela Cavalcante da Silva Date: Fri, 4 Oct 2019 10:15:09 -0300 Subject: [PATCH 7/9] add test file --- jararaca/test_settings.py | 8 ++++++++ pytest.ini | 3 +++ 2 files changed, 11 insertions(+) create mode 100644 jararaca/test_settings.py create mode 100644 pytest.ini diff --git a/jararaca/test_settings.py b/jararaca/test_settings.py new file mode 100644 index 0000000..31b6d87 --- /dev/null +++ b/jararaca/test_settings.py @@ -0,0 +1,8 @@ +from .settings import * + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': ':memory:' + } +} \ No newline at end of file diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..8063037 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +DJANGO_SETTINGS_MODULE=jararaca.test_settings +addopts = --nomigrations --cov=. --cov-report=html \ No newline at end of file From a3b59617fbcb5a662c03b23ac40a42bdcd3aa293 Mon Sep 17 00:00:00 2001 From: Gabriela Cavalcante da Silva Date: Fri, 4 Oct 2019 10:17:30 -0300 Subject: [PATCH 8/9] remove tests wf --- .github/workflows/pythonapp.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pythonapp.yml b/.github/workflows/pythonapp.yml index dc686ab..918414f 100644 --- a/.github/workflows/pythonapp.yml +++ b/.github/workflows/pythonapp.yml @@ -26,7 +26,7 @@ jobs: # Pylint with -E option will display only if there is any error git ls-files | grep -v 'migrations' | grep -v 'settings.py' | grep -v 'manage.py' | grep -E '.py$' | xargs pylint -E --load-plugins=pylint_django - - name: Test with pytest - run: | - pip install pytest - pytest + #- name: Test with pytest + # run: | + # pip install pytest + # pytest From 068fdd8ed2d015c90889d7cff67625248c396c62 Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Sat, 5 Oct 2019 21:44:45 -0300 Subject: [PATCH 9/9] Update version six to 1.12.0 in requirements --- requirements.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index d5015b8..dce6d25 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,7 +23,7 @@ PyQRCode==1.2.1 python-http-client==3.1.0 pytz==2018.9 sendgrid==5.6.0 -six==1.11.0 +six==1.12.0 sqlparse==0.2.4 whitenoise==4.1.2 XlsxWriter==1.1.2 @@ -35,4 +35,5 @@ pytest-cov # lint pylint==2.3.0 pylint-django==2.0.6 -pylint-plugin-utils==0.5 \ No newline at end of file +pylint-plugin-utils==0.5 +