Commit 23c8279c authored by Evili del Rio's avatar Evili del Rio

Initial import

parents
[run]
omit =
# omit anything in a .env directory anywhere
*/.env*/*
/usr/*
*/site-packages/*
*/lib/python*
manage.py
# VS Studio Code
.vscode
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# Emacs
*~
\#*\#
.\#*
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# IPython Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# dotenv
.env
# virtualenv
venv/
ENV/
# Spyder project settings
.spyderproject
# Rope project settings
.ropeproject
default.sqlite3
#
# Test migrations (for legacy databases)
#
test_migrations/
*.sqlite3
# IOS files
.DS_Store
"""
Django settings for birding project.
Generated by 'django-admin startproject' using Django 2.2.7.
For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'i-34llrf+@e+xa9*raqhan0)3!=^cp#z!bt0q%_-vfw8a!v+2c'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'behave_django',
'clades',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'birding.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'birding.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/
STATIC_URL = '/static/'
"""birding URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('accounts/', include('django.contrib.auth.urls')),
path('clades/', include('clades.urls'))
]
"""
WSGI config for birding project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'birding.settings')
application = get_wsgi_application()
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class CladesConfig(AppConfig):
name = 'clades'
# Generated by Django 2.2.7 on 2019-12-11 12:02
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Genus',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=127, unique=True)),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='Species',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=127, unique=True)),
('genus', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='clades.Genus')),
],
options={
'abstract': False,
},
),
]
from django.db import models
class BaseName(models.Model):
name = models.CharField(max_length=127, unique=True)
class Meta:
abstract = True
def __str__(self):
return self.name
def get_absolute_url(self):
return '/'
class Genus(BaseName):
pass
class Species(BaseName):
genus = models.ForeignKey(Genus, on_delete=models.PROTECT)
{% extends "_base_form.html" %}
{% extends "clades/_base_form.html" %}
{% extends "clades/_base_form.html" %}
from django.test import TestCase
from django.urls import reverse_lazy
from django.contrib.auth import get_user_model
from .models import Species, Genus
class CladesTest(TestCase):
@classmethod
def setUpClass(cls):
cls.fixture = {}
cls.fixture['user'] = {
'username': 'ijon_titxi',
'email': 'ijon.titxi@stanislaw.lem',
'password': 'solaris',
}
user = get_user_model().objects.get_or_create(
username=cls.fixture['user']['username'],
email=cls.fixture['user']['email']
)[0]
user.set_password(cls.fixture['user']['password'])
user.save()
super().setUpClass()
def login(self):
user = self.fixture['user']
self.client.login(
username=user['username'],
password=user['password']
)
class GenusTest(CladesTest):
def test_add_genus(self):
self.login()
self.client.post(reverse_lazy('genus_add'),
data={'name': 'periparus'})
self.assertEqual(Genus.objects.count(), 1)
class SpeciesTest(CladesTest):
def test_add_species(self):
genus = Genus.objects.get_or_create(name='periparus')[0]
self.login()
self.client.login(username='fred', password='secret')
self.client.post(reverse_lazy('species_add'),
data={
'genus': genus.pk,
'name': 'ater'
})
self.assertEqual(Species.objects.count(), 1)
from django.urls import path
from .views import SpeciesAdd, GenusAdd
urlpatterns = [
path('genus/add', GenusAdd.as_view(), name='genus_add'),
path('species/add', SpeciesAdd.as_view(), name='species_add'),
]
from django.contrib.auth.mixins import LoginRequiredMixin
from django.shortcuts import render
from django.views.generic.edit import CreateView
from .models import Species, Genus
# LoginRequiredMixin,
# LoginRequiredMixin,
class GenusAdd(LoginRequiredMixin, CreateView):
model = Genus
fields = ['name']
class SpeciesAdd(LoginRequiredMixin, CreateView):
model = Species
fields = ['genus', 'name']
from django.conf import settings
from django.contrib.auth import BACKEND_SESSION_KEY, SESSION_KEY, get_user_model
from django.contrib.sessions.backends.db import SessionStore
from selenium import webdriver
User = get_user_model()
def before_all(context):
context.browser = webdriver.Firefox()
context.browser.implicitly_wait(10)
context.user ={
'username': 'edith',
'email': 'edith@example.com',
'password': 'cmFuZG9tdGV4dAo',
}
user = User.objects.get_or_create(**context.user)[0]
user.set_password(context.user['password'])
user.save()
def after_all(context):
context.browser.quit()
def before_feature(context, feature):
print("Before feature", feature)
def after_feature(context, feature):
print("After feature", feature)
Feature: Species
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 I create a genus named "Periparus"
Then I will see the genus "Periparus" page
And I will see a link to "Genuses"
When I click the link to "Genuses"
Then I will see a link to genus "Periparus"
Feature: Species
As a logged-in user
I want to be able to see all species 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 two species and see them on the Species page
Given I am a logged-in user
When I create a species named "Periparus ater"
Then I will see the species "Periparus ater" page
And I will see a link to "Species"
When I create a species named "Sylvia atricapilla"
Then I will see the species "Sylvia atricapilla" page
And I will see a link to "Species"
When I click the link to "Species"
Then I will see a link to species "Periparus ater"
And I will see a link to species "Sylvia atricapilla"
@when(u'I create a genus named "{genus}"')
def genus_add(context, genus):
context.browser.get(context.get_url('/clades/species/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,))
@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"')
@when(u'I click the link to "Genuses"')
def step_impl(context):
raise NotImplementedError(u'STEP: When I click the link to "Genuses"')
@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,))
import os
from behave import given, when, then
from django.conf import settings
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
@given(u'I am a logged-in user')
def given_i_am_logged(context):
context.browser.get(context.get_url("/accounts/login?next=/"))
context.browser.find_element_by_name('username').send_keys(context.user['username'])
context.browser.find_element_by_name('password').send_keys(context.user['password'])
context.browser.find_element_by_name('submit').click()
@given(u'I create a genus named "{genus}"')
def step_impl(context, genus):
raise NotImplementedError(u'STEP: Given I create a genus named "%s"' % (genus,))
@when(u'I create a species named "{genus} {species}"')
def create_species(context, genus, species):
context.browser.get(context.get_url('/clades/species/add'))
genus_dropdown = Select(context.browser.find_element_by_name('genus'))
genus_dropdown.select_by_visible_text(genus)
context.browser.find_element_by_name('species').send_keys(species)
context.browser.find_element_by_name('save').click()
@then(u'I will see the species "{genus} {species}" page')
def species_page(context, genus, species):
raise NotImplementedError(u'STEP: Then I will see the species "%s %s" page' % (genus, species))
@then(u'I will see a link to "Species"')
def step_impl(context):
raise NotImplementedError(u'STEP: Then I will see a link to "Species"')
@when(u'I click the link to "Species"')
def step_impl(context):
raise NotImplementedError(u'STEP: When I click the link to "Species"')
@then(u'I will see a link to species "{genus} {species}"')
def step_impl(context):
raise NotImplementedError(u'STEP: Then I will see a link to "%s %s"' % (genus, species))
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'birding.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
<!DOCTYPE html>
<html>
<head>
<meta name="generator" content=
"HTML Tidy for HTML5 for Linux version 5.7.28">
<title>Photo Bird</title>
</head>
<body>
<h1>Photo Bird</h1>
{% block content %}
{% endblock %}
</body>
</html>
{% extends "_base.html" %}
{% block content %}
<div>
<form method="POST">{% csrf_token %}
{{ form.as_p }}
{% block form_buttons%}
<button type="submit" name="submit">Submit</button>
<button type="reset" name="reset">Reset</cancel>
{% endblock form_buttons %}
</form>
</div>
{% endblock content %}
{% extends "_base_form.html" %}
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