-
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.
Testes com banco de Dados + Django Admin
- Loading branch information
1 parent
a605107
commit 46b2dc3
Showing
12 changed files
with
317 additions
and
244 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 |
---|---|---|
|
@@ -162,4 +162,4 @@ cython_debug/ | |
|
||
# postgres files for local development | ||
|
||
.pgdata | ||
.pgdata/ |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,10 @@ | ||
from django.contrib.admin import ModelAdmin, register | ||
|
||
from pypro.aperitivos.models import Video | ||
|
||
|
||
@register(Video) | ||
class VideoAdmin(ModelAdmin): | ||
list_display = ('titulo', 'slug', 'vimeo_id') | ||
ordering = ('creation',) | ||
prepopulated_fields = {'slug': ('titulo',)} |
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,24 @@ | ||
# Generated by Django 4.2.5 on 2023-09-23 17:18 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Video', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('slug', models.CharField(max_length=32)), | ||
('titulo', models.CharField(max_length=32)), | ||
('vimeo_id', models.CharField(max_length=32)), | ||
('creation', models.DateTimeField(auto_now_add=True)), | ||
], | ||
), | ||
] |
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,31 @@ | ||
import pytest | ||
from django.urls import reverse | ||
from model_mommy import mommy | ||
|
||
from pypro.aperitivos.models import Video | ||
from pypro.django_assertions import assert_contains | ||
|
||
|
||
@pytest.fixture | ||
def videos(db): | ||
return mommy.make(Video, 3) | ||
|
||
|
||
@pytest.fixture | ||
def resp(client, videos): | ||
return client.get(reverse('aperitivos:indice')) | ||
|
||
|
||
def test_status_code(resp): | ||
assert resp.status_code == 200 | ||
|
||
|
||
def test_titulo_video(resp, videos): | ||
for video in videos: | ||
assert_contains(resp, video.titulo) | ||
|
||
|
||
def teste_link_video(resp, videos): | ||
for video in videos: | ||
video_link = reverse('aperitivos:video', args=(video.slug,)) | ||
assert_contains(resp, f'href="{video_link}"') |
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,37 @@ | ||
import pytest | ||
from django.urls import reverse | ||
from model_mommy import mommy | ||
|
||
from pypro.aperitivos.models import Video | ||
from pypro.django_assertions import assert_contains | ||
|
||
|
||
@pytest.fixture | ||
def video(db): | ||
return mommy.make(Video) | ||
|
||
|
||
@pytest.fixture | ||
def resp(client, video): | ||
return client.get(reverse('aperitivos:video', args=(video.slug,))) | ||
|
||
|
||
@pytest.fixture | ||
def resp_video_nao_encontrado(client, video): | ||
return client.get(reverse('aperitivos:video', args=(video.slug+'video_nao_existente',))) | ||
|
||
|
||
def test_status_code_video_nao_encontrado(resp_video_nao_encontrado): | ||
assert resp_video_nao_encontrado.status_code == 404 | ||
|
||
|
||
def test_status_code(resp): | ||
assert resp.status_code == 200 | ||
|
||
|
||
def test_titulo_video(resp, video): | ||
assert_contains(resp, video.titulo) | ||
|
||
|
||
def test_conteudo_video(resp, video): | ||
assert_contains(resp, f'<iframe src="https://player.vimeo.com/video/{video.vimeo_id}"') |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,19 +1,12 @@ | ||
from pypro.aperitivos.models import Video | ||
from django.shortcuts import render | ||
|
||
videos = [ | ||
Video(slug='oo', titulo='Vídeo Aperitivo: OO em Python sem sotaque', vimeo_id='856570782'), | ||
Video(slug='iot', titulo='IOT com Luciano Ramalho', vimeo_id='861071461'), | ||
] | ||
|
||
|
||
videos_dct = {v.slug: v for v in videos} | ||
from django.shortcuts import render, get_object_or_404 | ||
|
||
|
||
def indice(request): | ||
videos = Video.objects.order_by('creation').all() | ||
return render(request, 'aperitivos/indice.html', context={'videos': videos}) | ||
|
||
|
||
def video(request, slug): | ||
video = Video.objects.get(slug=slug) | ||
video = get_object_or_404(Video, slug=slug) | ||
return render(request, 'aperitivos/video.html', context={'video': video}) |