Last active
December 29, 2015 13:48
-
-
Save murilobsd/7679246 to your computer and use it in GitHub Desktop.
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
# encoding: utf-8 | |
from django.test import TestCase | |
from django.contrib.auth.models import User | |
from django.test.client import Client | |
from django.template.defaultfilters import slugify | |
from django.test.client import RequestFactory | |
from fazenda.core.models import Fazenda | |
from fazenda.core.views import FazendaDetail | |
class FazendaTesteCase(TestCase): | |
''' | |
Simples teste para criacao da fazenda | |
''' | |
def setUp(self): | |
''' | |
Criacao da fazenda do Murilo uhuuuu | |
Area Integral em Hectares | |
Area Nao Cultivada em Hectares | |
''' | |
self.murilo = User.objects.create(username='murilobsd', password='murilobsd') | |
self.muriloslug = Fazenda.objects.create(nome='Murilo Ijanc', usuario=self.murilo, area_integral=123.45, arean_cultivada=0.00) | |
self.murilo_fazenda = Fazenda.objects.create(nome='Murilo', usuario=self.murilo, area_integral=123.45, arean_cultivada=0.00) | |
self.factory = RequestFactory() | |
def testeCriacao(self): | |
''' | |
Realmento criou? | |
''' | |
self.assertEquals(self.murilo_fazenda.nome, 'Murilo') | |
self.assertEquals(self.murilo_fazenda.area_integral, 123.45) | |
self.assertEquals(self.murilo_fazenda.arean_cultivada, 0.00) | |
self.assertEquals(self.muriloslug.slug, slugify('Murilo Ijanc')) | |
self.assertEquals(self.muriloslug.get_absolute_url(), '/fazenda/murilo-ijanc/') | |
def testeRequisicaoFazenda(self): | |
# Requisicoes | |
request = self.factory.get(self.muriloslug.get_absolute_url()) | |
response = FazendaDetail.as_view()(request) | |
print response | |
self.assertEqual(response.status_code, 200) | |
def tearDown(self): | |
''' | |
Removendo | |
''' | |
self.murilo_fazenda.delete() | |
self.muriloslug.delete() | |
self.murilo.delete() |
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
from django.conf.urls import patterns, include, url | |
from fazenda.core.views import FazendaDetail | |
from django.contrib import admin | |
admin.autodiscover() | |
urlpatterns = patterns('', | |
url(r'^$', 'fazenda.core.views.home', name='home'), | |
url(r'^fazenda/(?P<slug>[-_\w]+)/$', FazendaDetail.as_view(), name='fazenda'), | |
# Examples: | |
# url(r'^$', 'fazenda.views.home', name='home'), | |
# url(r'^blog/', include('blog.urls')), | |
url(r'^admin/', include(admin.site.urls)), | |
) |
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
# encoding: utf-8 | |
from django.shortcuts import render_to_response | |
from django.conf import settings | |
from django.views.generic import DetailView | |
from fazenda.core.models import Fazenda | |
from django.shortcuts import get_object_or_404 | |
class FazendaDetail(DetailView): | |
'''' | |
Detalhes da Fazenda | |
''' | |
model = Fazenda | |
context_object_name = 'fazenda' | |
template_name = 'fazenda_detail.html' | |
def get_context_data(self, **kwargs): | |
context = super(FazendaDetail, self).get_context_data(**kwargs) | |
return context |
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
# encoding: utf-8 | |
class Fazenda(models.Model): | |
''' | |
Classe para instanciar as Fazendas | |
# Criando a Fazenda do Murilo | |
>>> fazenda_m = Fazenda.objects.create(nome="Fazenda do Murilo", area_integral='123.45', arean_cultivada='0.00') | |
>>> fazenda_m.nome | |
Fazenda do Murilo | |
>>> fazenda_m | |
Fazenda do Murilo | |
''' | |
usuario = models.ForeignKey(User) | |
nome = models.CharField(max_length=200) | |
slug = models.SlugField(max_length=200) | |
area_integral = models.DecimalField(max_digits=10, decimal_places=2) # Área Integra | |
arean_cultivada = models.DecimalField(max_digits=10, decimal_places=2) # Área Não Cultivada | |
criacao = models.DateTimeField(auto_now_add=True) | |
class Meta: | |
ordering = ['-criacao'] | |
def __unicode__(self): | |
return self.nome | |
def get_absolute_url(self): | |
return reverse('fazenda', None, [str(self.slug)]) | |
def save(self, *args, **kwargs): | |
if self.pk is None: | |
self.slug = slugify(self.nome) | |
super(Fazenda, self).save(*args, **kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment