Skip to content

Commit

Permalink
Persiste a inscrição
Browse files Browse the repository at this point in the history
  • Loading branch information
matheuspdf committed Mar 25, 2024
1 parent 93e3a18 commit 9d89615
Show file tree
Hide file tree
Showing 9 changed files with 1,204 additions and 95 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ipython = "*"
notebook = "==6.5.5"
django-extensions = "*"
traitlets = "==5.9.0"
django-test-without-migrations = "*"

[dev-packages]
flake8 = "*"
Expand Down
1,222 changes: 1,127 additions & 95 deletions Pipfile.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions eventex/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"test_without_migrations",
"django_extensions",
"eventex.core",
"eventex.subscriptions",
Expand Down
32 changes: 32 additions & 0 deletions eventex/subscriptions/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 5.0.3 on 2024-03-25 23:37

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = []

operations = [
migrations.CreateModel(
name="Subscription",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=100)),
("cpf", models.CharField(max_length=11)),
("email", models.EmailField(max_length=254)),
("phone", models.CharField(max_length=20)),
("created_at", models.DateTimeField(auto_now_add=True)),
],
),
]
File renamed without changes.
9 changes: 9 additions & 0 deletions eventex/subscriptions/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.db import models


class Subscription(models.Model):
name = models.CharField(max_length=100)
cpf = models.CharField(max_length=11)
email = models.EmailField()
phone = models.CharField(max_length=20)
created_at = models.DateTimeField(auto_now_add=True)
22 changes: 22 additions & 0 deletions eventex/subscriptions/tests/test_model_subscription.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from datetime import datetime

from django.test import TestCase
from eventex.subscriptions.models import Subscription


class SubscriptionModelTest(TestCase):
def setUp(self):
self.obj = Subscription(
name='Matheus Lopes',
cpf='12345678912',
email='[email protected]',
phone='11984028729'
)
self.obj.save()

def test_create(self):
self.assertTrue(Subscription.objects.exists())

def test_created_at(self):
"""Subscription must have an auto created_at attr."""
self.assertIsInstance(self.obj.created_at, datetime)
8 changes: 8 additions & 0 deletions eventex/subscriptions/tests/test_view_subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from eventex.subscriptions.forms import SubscriptionForm
from django.core import mail

from eventex.subscriptions.models import Subscription


class SubscribeGet(TestCase):
def setUp(self):
Expand Down Expand Up @@ -51,6 +53,9 @@ def test_post(self):
def test_send_subscribe_email(self):
self.assertEqual(1, len(mail.outbox))

def test_save_subscription(self):
self.assertTrue(Subscription.objects.exists())


class SubscribePostInvalid(TestCase):
def setUp(self):
Expand All @@ -71,6 +76,9 @@ def test_form_has_errors(self):
form = self.resp.context['form']
self.assertTrue(form.errors)

def test_dont_save_subscription(self):
self.assertFalse(Subscription.objects.exists())


class SubscribeSuccessMessage(TestCase):
def test_message(self):
Expand Down
4 changes: 4 additions & 0 deletions eventex/subscriptions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from django.template.loader import render_to_string
from django.contrib import messages

from eventex.subscriptions.models import Subscription


def subscribe(request):
if request.method == 'POST':
Expand All @@ -27,6 +29,8 @@ def create(request):
'subscriptions/subscription_email.txt',
form.cleaned_data)

Subscription.objects.create(**form.cleaned_data)
# Success feedback
messages.success(request, 'Inscrição realizada com sucesso!')

return HttpResponseRedirect('/inscricao/')
Expand Down

0 comments on commit 9d89615

Please sign in to comment.