From 1000bb7099c39ca18ecf208d716e11ea66c07e70 Mon Sep 17 00:00:00 2001 From: Gilles Pavan Date: Wed, 8 May 2019 17:15:33 +0000 Subject: [PATCH] starting project --- Dockerfile | 6 ++ README.md | 21 +++++ build.sh | 1 + db.sqlite3 | Bin 0 -> 135168 bytes docker-compose.yml | 12 +++ election/__init__.py | 0 election/admin.py | 4 + election/apps.py | 5 ++ election/migrations/0001_initial.py | 21 +++++ election/migrations/__init__.py | 0 election/models.py | 6 ++ election/serializers.py | 7 ++ election/tests.py | 13 +++ election/urls.py | 8 ++ election/views.py | 8 ++ makemigrations.sh | 1 + manage.py | 15 ++++ migrate.sh | 1 + mvapi/__init__.py | 0 mvapi/settings.py | 124 ++++++++++++++++++++++++++++ mvapi/urls.py | 26 ++++++ mvapi/wsgi.py | 16 ++++ requirements.txt | 5 ++ test.sh | 1 + 24 files changed, 301 insertions(+) create mode 100644 Dockerfile create mode 100644 README.md create mode 100755 build.sh create mode 100644 db.sqlite3 create mode 100644 docker-compose.yml create mode 100644 election/__init__.py create mode 100644 election/admin.py create mode 100644 election/apps.py create mode 100644 election/migrations/0001_initial.py create mode 100644 election/migrations/__init__.py create mode 100644 election/models.py create mode 100644 election/serializers.py create mode 100644 election/tests.py create mode 100644 election/urls.py create mode 100644 election/views.py create mode 100755 makemigrations.sh create mode 100755 manage.py create mode 100755 migrate.sh create mode 100644 mvapi/__init__.py create mode 100644 mvapi/settings.py create mode 100644 mvapi/urls.py create mode 100644 mvapi/wsgi.py create mode 100644 requirements.txt create mode 100755 test.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7464ccc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM python:3.6 +ENV PYTHONUNBUFFERED 1 +RUN mkdir /code +WORKDIR /code +COPY requirements.txt /code/ +RUN pip install -r requirements.txt diff --git a/README.md b/README.md new file mode 100644 index 0000000..b3fe6cf --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +## Build the docker image + +sudo ./build.sh + +## Run the docker container + +sudo docker-compose up -d + +## Initialize the database + +sudo ./makemigrations. + +sudo ./migrate.sh + +## Run the tests + +sudo ./test.sh + +## Browse the admin + +[http://localhost:8012/admin/](http://localhost:8012/admin/) diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..a23db72 --- /dev/null +++ b/build.sh @@ -0,0 +1 @@ +docker build -t drf-tdd:latest . diff --git a/db.sqlite3 b/db.sqlite3 new file mode 100644 index 0000000000000000000000000000000000000000..1aaea161b7bee543ddba1e694ab61096dfd78e38 GIT binary patch literal 135168 zcmeI5Uu+x6eaCmjB`I1YSJof%?kt@t**crh$>Q$vudatgwq;p9i;89WWVt6;8x#oACVjY~DEc==+O%kz7HwYAqD@j1XcC|; z(3#VxC>m8m%gbRYITemhg%d$3 zJR`?uqRGp#WIP;;C?d;L(JK{_r_wc3G#HN0L?bhi$mK{pE=QyDekV74cUIe}ZjcN~ zRm)fPvbs|tL0+p=)uL9=)q?g=&FjTnb)#9j-BB!-NG7lQh@(3VM+v(l>g_Ool%yPs zzTqW)-fH-Xn|^k+yph$arE*2pvRPFxmrG@}Kx(Sx^h#Gzk`j+9vwg(bLc>{1E$a_< zjIyp~O2w*PtXB88^@>XBEq8OFBqdpvuACw+-e|ap+UvytGRvS)a z)5*48E*PxK9Hz0Aa4Zpx-*7p(iTPPOMoN+JEtGbfcvZ@mIqim5CTJ4z1*ek>5KY;F zLA$x45}u@G%KNOHHP-#r^}Lo-GaDr%)4j3fh!jbNX9ePlP&Qr3mMc>h>EtEqwyPQ` zBE@212XQgcbkTXz*_u{LNMR{H-9wm?9QE_(=^3I*EF#5uf^MQ6-P1Elax|&<#LsXp zF)xV!BL0q;7vB@#7XR{xYEXk%5C8!X009sH0T2KI5C8!X009tq&IkmY4u#KdYQytzb<}R{55e${MpvxaRdS&00JNY0w4ea zAOHd&00JNY0w8b%0>i@SDBqZvH{RVt!suDPai5L(?ivv$&hz#=B5a?XK4Ey6tqaim zJp{in9AHPea%pGVF(?d=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; gKmY_l00ck)1V8`;KmY_l;A9bS^A2u!MXyx<7h`(^3IG5A literal 0 HcmV?d00001 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..3daa795 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +version: '3' + +services: + web: + image: drf-tdd:latest + command: python manage.py runserver 0.0.0.0:8000 + volumes: + - ./:/code + ports: + - "8012:8000" + + diff --git a/election/__init__.py b/election/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/election/admin.py b/election/admin.py new file mode 100644 index 0000000..2b3d567 --- /dev/null +++ b/election/admin.py @@ -0,0 +1,4 @@ +from django.contrib import admin +from .models import Election + +admin.site.register(Election) diff --git a/election/apps.py b/election/apps.py new file mode 100644 index 0000000..90583b8 --- /dev/null +++ b/election/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class ElectionConfig(AppConfig): + name = 'election' diff --git a/election/migrations/0001_initial.py b/election/migrations/0001_initial.py new file mode 100644 index 0000000..3c0ace2 --- /dev/null +++ b/election/migrations/0001_initial.py @@ -0,0 +1,21 @@ +# Generated by Django 2.1.2 on 2019-05-08 10:18 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Election', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=255, verbose_name='Title')), + ], + ), + ] diff --git a/election/migrations/__init__.py b/election/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/election/models.py b/election/models.py new file mode 100644 index 0000000..ebd9c86 --- /dev/null +++ b/election/models.py @@ -0,0 +1,6 @@ +from django.db import models + +# Create your models here. + +class Election(models.Model): + title = models.CharField("Title", max_length=255) \ No newline at end of file diff --git a/election/serializers.py b/election/serializers.py new file mode 100644 index 0000000..8ee3f13 --- /dev/null +++ b/election/serializers.py @@ -0,0 +1,7 @@ +from rest_framework import serializers +from election.models import Election + +class ElectionSerializer(serializers.ModelSerializer): + class Meta: + model = Election + fields = '__all__' \ No newline at end of file diff --git a/election/tests.py b/election/tests.py new file mode 100644 index 0000000..e656bdc --- /dev/null +++ b/election/tests.py @@ -0,0 +1,13 @@ +from django.test import TestCase +from rest_framework.test import APITestCase +from election.models import Election +from django.urls import reverse +# Create your tests here. + +class ElectionCreateAPIViewTestCase(APITestCase): + url = reverse("election:create") + + def test_create_election(self): + response = self.client.post(self.url, {"title": "testing election/create !"}) + self.assertEqual(201, response.status_code) + diff --git a/election/urls.py b/election/urls.py new file mode 100644 index 0000000..0d77354 --- /dev/null +++ b/election/urls.py @@ -0,0 +1,8 @@ +from django.urls import path +from election.views import ElectionCreateAPIView + +app_name = 'election' + +urlpatterns = [ + path('create/', ElectionCreateAPIView.as_view(), name="create"), +] diff --git a/election/views.py b/election/views.py new file mode 100644 index 0000000..8a15fe5 --- /dev/null +++ b/election/views.py @@ -0,0 +1,8 @@ +from django.shortcuts import render +from rest_framework.generics import CreateAPIView +from election.serializers import ElectionSerializer +# Create your views here. + + +class ElectionCreateAPIView(CreateAPIView): + serializer_class = ElectionSerializer diff --git a/makemigrations.sh b/makemigrations.sh new file mode 100755 index 0000000..d547fe3 --- /dev/null +++ b/makemigrations.sh @@ -0,0 +1 @@ +docker exec -it mvapi_web_1 python manage.py makemigrations diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..9128aa4 --- /dev/null +++ b/manage.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == '__main__': + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mvapi.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) diff --git a/migrate.sh b/migrate.sh new file mode 100755 index 0000000..d3aaea8 --- /dev/null +++ b/migrate.sh @@ -0,0 +1 @@ +docker exec -it mvapi_web_1 python manage.py migrate diff --git a/mvapi/__init__.py b/mvapi/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/mvapi/settings.py b/mvapi/settings.py new file mode 100644 index 0000000..3a21cd1 --- /dev/null +++ b/mvapi/settings.py @@ -0,0 +1,124 @@ +""" +Django settings for mvapi project. + +Generated by 'django-admin startproject' using Django 2.1.2. + +For more information on this file, see +https://docs.djangoproject.com/en/2.1/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.1/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.1/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'v7*_$#i)^@)hn-hb&ag!4^sz4hs^g2qwvi-el759gmj70(bxo%' + +# 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', + + 'rest_framework', + + 'election' +] + +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 = 'mvapi.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + '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 = 'mvapi.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.1/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.1/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.1/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.1/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/mvapi/urls.py b/mvapi/urls.py new file mode 100644 index 0000000..9a8b917 --- /dev/null +++ b/mvapi/urls.py @@ -0,0 +1,26 @@ +"""mvapi URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.1/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 include, path + +api_urls = [ + path('election/', include('election.urls')), +] + +urlpatterns = [ + path('admin/', admin.site.urls), + path('api/', include(api_urls)), +] diff --git a/mvapi/wsgi.py b/mvapi/wsgi.py new file mode 100644 index 0000000..4001c24 --- /dev/null +++ b/mvapi/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for mvapi 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.1/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mvapi.settings') + +application = get_wsgi_application() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6eb438f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +coverage==4.5.1 +Django==2.1.2 +django-nose==1.4.6 +djangorestframework==3.9.0 +nose==1.3.7 diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..816547e --- /dev/null +++ b/test.sh @@ -0,0 +1 @@ +docker exec -it mvapi_web_1 python manage.py test