Skip to content

Commit 78cc72b

Browse files
renzonrenzon
authored andcommitted
Implemented model Sectionˆ
related to #45
1 parent 95a4ebc commit 78cc72b

4 files changed

Lines changed: 47 additions & 5 deletions

File tree

pythonpro/modules/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""Using as facade for the entire app"""
2+
3+
from pythonpro.modules.models.modules import (
4+
ALL as ALL_MODULES,
5+
PYTHONIC_OBJECTS,
6+
PYTHON_BIRDS,
7+
PYTOOLS,
8+
PYTHON_FOR_PYTHONISTS,
9+
PYTHON_PATTERNS, PYTHON_WEB,
10+
TECH_INTERVIEW
11+
)
12+
13+
ALL_MODULES
14+
PYTHON_BIRDS
15+
PYTHONIC_OBJECTS
16+
PYTOOLS
17+
PYTHON_FOR_PYTHONISTS
18+
PYTHON_PATTERNS
19+
PYTHON_WEB
20+
TECH_INTERVIEW

pythonpro/sections/models.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
from django.db import models
22

3-
# Create your models here.
3+
4+
class Section(models.Model):
5+
title = models.CharField(max_length=50)
6+
description = models.TextField()
7+
slug = models.SlugField(unique=True)
8+
_module_slug = models.SlugField()

pythonpro/sections/tests.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,27 @@
22
from django.urls import reverse
33
from model_mommy import mommy
44

5+
from pythonpro.django_assertions import dj_assert_contains
6+
from pythonpro.modules import PYTHON_BIRDS
7+
from pythonpro.sections.models import Section
8+
9+
10+
@pytest.fixture
11+
def section():
12+
return mommy.make(Section, slug='procedural', _module_slug=PYTHON_BIRDS.slug)
13+
514

615
@pytest.fixture
7-
def resp(client, django_user_model):
16+
def resp(client, django_user_model, section):
817
user = mommy.make(django_user_model)
918
client.force_login(user)
10-
return client.get(reverse('sections:detail', kwargs={'slug': 'procedural'}))
19+
return client.get(reverse('sections:detail', kwargs={'slug': section.slug}))
1120

1221

1322
def test_status_code(resp):
1423
assert resp.status_code == 200
24+
25+
26+
@pytest.mark.parametrize('property_name', ['title', 'description'])
27+
def test_title(resp, section, property_name):
28+
dj_assert_contains(resp, getattr(section, property_name))

pythonpro/sections/views.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
from django.shortcuts import render
1+
from django.shortcuts import render, get_object_or_404
2+
3+
from pythonpro.sections.models import Section
24

35

46
def detail(request, slug):
5-
return render(request, 'sections/section_detail.html')
7+
ctx = {'section': get_object_or_404(Section, slug=slug)}
8+
return render(request, 'sections/section_detail.html', ctx)

0 commit comments

Comments
 (0)