Commit 0888262f authored by Evili del Rio's avatar Evili del Rio

Genus scenario completed

parent 23c8279c
from django.db import models
from django.urls import reverse_lazy
class BaseName(models.Model):
name = models.CharField(max_length=127, unique=True)
......@@ -10,7 +11,8 @@ class BaseName(models.Model):
return self.name
def get_absolute_url(self):
return '/'
return reverse_lazy(type(self).__name__.lower()+'_info', args=[self.pk])
class Genus(BaseName):
pass
......
{% extends "_base.html" %}
{% block content %}
<div><h2 id="genus">{{genus.name}}</h2></div>
<div><a href="{% url 'genus_list' %}">Genuses list</a></div>
{% endblock %}
{% extends "_base.html"%}
{% block content %}
<h2 id="genus_list">Genus List</h2>
<table>
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
{% for genus in object_list %}
<tr>
<td><a href="{% url 'genus_info' genus.pk %}">{{ genus.name }}</a></td>
</tr>
{% empty %}
<tr><td colspan="1"><em>No genuses found</em></td></tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
......@@ -36,6 +36,14 @@ class GenusTest(CladesTest):
data={'name': 'periparus'})
self.assertEqual(Genus.objects.count(), 1)
def test_absolute_url(self):
genus_name = 'Sylvia'
genus = Genus.objects.get_or_create(name='Sylvia')[0]
response = self.client.get(genus.get_absolute_url())
self.assertEqual(200, response.status_code, 'Genus has absolute_url')
self.assertIn('id="genus"', str(response.content))
self.assertIn(genus_name, str(response.content))
class SpeciesTest(CladesTest):
def test_add_species(self):
......
from django.urls import path
from .views import SpeciesAdd, GenusAdd
from .views import \
SpeciesAdd, SpeciesDetail, \
GenusAdd, GenusDetail, GenusList
urlpatterns = [
path('genus/add', GenusAdd.as_view(), name='genus_add'),
path('species/add', SpeciesAdd.as_view(), name='species_add'),
path('species/<int:pk>/', SpeciesDetail.as_view(), name='species_info'),
path('species/add/', SpeciesAdd.as_view(), name='species_add'),
path('genus/<int:pk>/', GenusDetail.as_view(), name='genus_info'),
path('genus/add/', GenusAdd.as_view(), name='genus_add'),
path('genus/list/', GenusList.as_view(), name='genus_list'),
]
from django.contrib.auth.mixins import LoginRequiredMixin
from django.shortcuts import render
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from django.views.generic.edit import CreateView
from .models import Species, Genus
# LoginRequiredMixin,
# LoginRequiredMixin,
class GenusAdd(LoginRequiredMixin, CreateView):
model = Genus
fields = ['name']
class SpeciesDetail(DetailView):
model = Species
class SpeciesAdd(LoginRequiredMixin, CreateView):
model = Species
fields = ['genus', 'name']
class GenusList(ListView):
model = Genus
class GenusDetail(DetailView):
model = Genus
class GenusAdd(LoginRequiredMixin, CreateView):
model = Genus
fields = ['name']
......@@ -8,7 +8,7 @@ User = get_user_model()
def before_all(context):
context.browser = webdriver.Firefox()
context.browser.implicitly_wait(10)
context.browser.implicitly_wait(4)
context.user ={
'username': 'edith',
'email': 'edith@example.com',
......
Feature: Species
Feature: Genus
As a logged-in user
I want to be able to see all genuses in one page
So that I can find them all
Background: we have some genus created
Given I create a genus named "Periparus"
And I create a genus named "Sylvia"
Scenario: Create a genus and see it on the Genuses page
Given I am a logged-in user
......
@when(u'I create a genus named "{genus}"')
def genus_add(context, genus):
context.browser.get(context.get_url('/clades/species/add'))
context.browser.get(context.get_url('/clades/genus/add'))
context.browser.find_element_by_name('name').send_keys(genus)
context.browser.find_element_by_name('submit').click()
@then(u'I will see the genus "{genus}" page')
def step_impl(context, genus):
raise NotImplementedError(u'STEP: Then I will see the genus "%s" page' % (genus,))
def genus_detail(context, genus):
genus_element = context.browser.find_element_by_id('genus')
if not(genus in genus_element.text):
raise NotFound('%s not found in %s text' % (genus, genus_element.id) )
@then(u'I will see a link to "Genuses"')
def step_impl(context):
raise NotImplementedError(u'STEP: Then I will see a link to "Genuses"')
context.browser.find_element_by_link_text('Genuses list')
@when(u'I click the link to "Genuses"')
def step_impl(context):
raise NotImplementedError(u'STEP: When I click the link to "Genuses"')
context.browser.find_element_by_link_text('Genuses list').click()
@then(u'I will see a link to genus "{genus}"')
def step_impl(context, genus):
raise NotImplementedError(u'STEP: Then I will see a link to genus "%s"' % (genus,))
context.browser.find_element_by_link_text(genus)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment