Skip to content

Instantly share code, notes, and snippets.

View guilatrova's full-sized avatar
🐍
Making Python learning easy

Guilherme Latrova guilatrova

🐍
Making Python learning easy
View GitHub Profile
@guilatrova
guilatrova / bad_tests.py
Last active October 21, 2017 09:34
Example of bad Django Rest Framework tests
from transactions.models import Transaction
from rest_framework.authtoken.models import Token
from rest_framework.test import APITestCase, APIClient
from rest_framework import status
class IntegrationTests(APITestCase):
def setUp(self):
self.user = User.objects.create_user(username='testuser', email='testuser@test.com', password='testing')
token = Token.objects.create(user=self.user)
@guilatrova
guilatrova / bad_django_self_tests.py
Created October 21, 2017 09:38
Example of bad test examples testing framework itself
def test_save_transaction(self):
t = Transaction.objects.create(description='django works', value=10, user=self.user)
self.assertIsNotNone(t.id)
self.assertEqual(Transaction.objects.count(), 1)
@guilatrova
guilatrova / models.py
Last active October 21, 2017 11:04
LatrovaCommits DRF Tests 1.1
from django.db import models
from django.contrib.auth.models import User
class Transaction(models.Model):
description = models.CharField(max_length=100)
value = models.DecimalField(max_digits=5, decimal_places=2)
user = models.ForeignKey(User)
@guilatrova
guilatrova / drf_tests_urls.py
Last active October 21, 2017 11:59
Latrova Commits DRF Tests 1.2
from django.conf.urls import url
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^transactions/', include('transactions.urls'))
]
@guilatrova
guilatrova / tests.py
Created October 21, 2017 11:22
Latrova Commits DRF Tests 1.3
from django.test import TestCase
from django.urls import reverse, resolve
from transactions.views import TransactionViewSet
class TransactionsUrlsTestCase(TestCase):
def test_resolves_list_url(self):
resolver = self.resolve_by_name('transactions')
@guilatrova
guilatrova / tests.py
Last active October 21, 2017 11:36
Latrova Commits DRF Tests 1.4
def test_list_url_only_allows_get_and_post(self):
resolver = self.resolve_by_name('transactions')
self.assert_has_actions(['get', 'post'], resolver.func.actions)
def test_single_url_allows_all_methods_except_post(self):
"""All methods are: GET, PUT, PATCH and DELETE"""
resolver = self.resolve_by_name('transaction', pk=1)
self.assert_has_actions(['get', 'put', 'patch', 'delete'], resolver.func.actions)
@guilatrova
guilatrova / Procfile
Last active December 10, 2017 12:31
Latrova Commits Deploy /dist to Heroku with Express
web: node server.js
@guilatrova
guilatrova / .gitignore
Created December 10, 2017 12:44
Latrova Commits Deploy /dist to Heroku with buildpack
...
node_modules
#dist folder
#dist <- Commented, you can remove this line if you will
# IDEA/Webstorm project files
.idea
*.iml
...

Keybase proof

I hereby claim:

  • I am guilatrova on github.
  • I am latrova (https://keybase.io/latrova) on keybase.
  • I have a public key whose fingerprint is 73B4 2719 C3A1 3957 B0BC 688D 3EB9 DFEB EA17 FB67

To claim this, I am signing this object:

@guilatrova
guilatrova / .pre-commit-config.yaml
Last active December 6, 2021 15:06
Base Python Config: pre-commit hooks and pyproject.toml
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 21.11b1
hooks:
- id: black