Skip to content

Commit

Permalink
dockerize, adding test tools
Browse files Browse the repository at this point in the history
  • Loading branch information
bumper-bugra-caglar committed Apr 1, 2024
1 parent a165d99 commit 23134f4
Show file tree
Hide file tree
Showing 22 changed files with 573 additions and 73 deletions.
14 changes: 14 additions & 0 deletions dev.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
SECRET_KEY=django-insecure-(q_xc+d@c4wzz0@80)nraq&7k^^*@yhj-_8h$a5ax!d0zpgfi$


# DATABASE
DB_NAME="skillforge"
DB_USER="django"
DB_PASSWORD="django"
DB_HOST="db"
DB_PORT="5432"


# LOGGIN
ROOT_LOG_LEVEL="INFO"
DJANGO_LOG_LEVEL="ERROR"
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[tool.pyright]
include = ["core", "asf"]

[tool.coverage.run]
include = ["core/*"]
omit = [
"*migrations*",
"*tests*",
"*scripts*",
]
plugins = ["django_coverage_plugin"]
37 changes: 37 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[pytest]
minversion = 6.0
DJANGO_SETTINGS_MODULE=skillforge.settings.test
testpaths = tests
addopts =
# Pass as opts
# https://github.com/pytest-dev/pytest-django/issues/673
--ds=asf.settings.test
# Disable migrations
--no-migrations
# log sys logs
--capture=sys
# --reuse-db
--verbose
# exit at first fail
--exitfirst
# use ipdb instead of pdb
--pdbcls=IPython.terminal.debugger:Pdb
# unknown marks trigger errors
--strict-markers
# show extra info on xfailed, xpassed, and skipped tests
# -rxXs
# omitted dirs/files
--ignore-glob=**/scripts/**
# https://docs.pytest.org/en/7.1.x/explanation/goodpractices.html#choosing-a-test-layout-import-rules
# allow same file names in different dirs
--import-mode=importlib
python_files =
test_*.py
filterwarnings =
# Ignore 3rd party deprecation warnings
ignore::DeprecationWarning
markers =
slow: marks tests as slow (deselect with '-m "not slow"')
current: current working tests
e2e: End-to-End tests
external: 3rd party calls
28 changes: 28 additions & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
celery==5.3.6
Django==4.2.7
django-celery-beat==2.5.0
django-cors-headers==4.3.1
django-debug-toolbar==4.2.0
django-filter==23.4
django-redis==5.4.0
django-rest-swagger==2.2.0
djangorestframework==3.14.0
djangorestframework-jwt==1.11.0
djangorestframework-simplejwt==5.3.0
drf-yasg==1.21.7
Faker==20.1.0
flower==2.0.1
Jinja2==3.1.2
model-bakery==1.17.0
numpy==1.24.4
Pillow==10.1.0
PyJWT==1.7.1
pytz==2023.3.post1
PyYAML==6.0.1
redis==5.0.1
requests==2.31.0
simplejson==3.19.2
six==1.16.0
sqlparse==0.4.4
swagger-spec-validator==3.0.3
urllib3==2.1.0
24 changes: 24 additions & 0 deletions requirements/local.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-r ./base.txt

# Django
# ------------------------------------------------------------------------------
django-extensions==3.1.5 # https://github.com/django-extensions/django-extensions
django-debug-toolbar==3.2.3 # https://github.com/jazzband/django-debug-toolbar
django-stubs==1.12.0 # https://github.com/typeddjango/django-stubs
djangorestframework-stubs==1.7.0 # https://github.com/typeddjango/djangorestframework-stubs
# django-silk==4.4.1 # https://pypi.org/project/django-silk

# Code quality
# ------------------------------------------------------------------------------
# flake8==5.0.4 # https://github.com/PyCQA/flake8
# flake8-isort==4.2.0 # https://github.com/gforcada/flake8-isort
black==24.3.0 # https://github.com/psf/black
# pylint-django==2.5.3 # https://github.com/PyCQA/pylint-django
# pylint-celery==0.3 # https://github.com/PyCQA/pylint-celery
# pre-commit==2.20.0 # https://github.com/pre-commit/pre-commit

# Debugger
# ------------------------------------------------------------------------------
ipdb==0.13.9 # https://github.com/gotcha/ipdb
pudb==2022.1.2 # https://github.com/inducer/pudb
debugpy==1.6.5 # https://pypi.org/project/debugpy
15 changes: 15 additions & 0 deletions requirements/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-r ./base.txt

# pytest
# ------------------------------------------------------------------------------
pytest==7.4.3
pytest-django==4.7.0
pytest-sugar==0.9.5 # https://github.com/Frozenball/pytest-sugar
# Coverage
# ------------------------------------------------------------------------------
factory-boy==3.3.0 # https://github.com/FactoryBoy/factory_boy
coverage==6.4.2 # https://github.com/nedbat/coveragepy
django-coverage-plugin==2.0.3 # https://github.com/nedbat/django_coverage_plugin
# Mock
# ------------------------------------------------------------------------------
requests-mock==1.11.0 # https://github.com/jamielennox/requests-mock
25 changes: 13 additions & 12 deletions skillforge/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from rest_framework import status
from rest_framework.response import Response

import logging

logger = logging.getLogger(__name__)


class BaseResponse:
def __init__(self, status_code=status.HTTP_200_OK, message="", data=None):
Expand All @@ -9,19 +13,16 @@ def __init__(self, status_code=status.HTTP_200_OK, message="", data=None):
self.data = data

def success(self):
return Response({
"success": status.HTTP_201_CREATED,
"message": self.message
}, self.status_code)
return Response({"success": status.HTTP_201_CREATED, "message": self.message}, self.status_code)

def error(self):
return Response({
"success": False,
"message": self.message,
}, self.status_code)
return Response(
{
"success": False,
"message": self.message,
},
self.status_code,
)

def success_with_data(self):
return Response({
"success": self.success,
"data": self.data
}, self.status_code)
return Response({"success": self.success, "data": self.data}, self.status_code)
2 changes: 1 addition & 1 deletion skillforge/generics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

class StandardResultsSetPagination(PageNumberPagination):
page_size = 25
page_size_query_param = 'page_size'
page_size_query_param = "page_size"
max_page_size = 1000
10 changes: 7 additions & 3 deletions skillforge/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@

class SkillForgeBaseQuerySet(models.QuerySet):
def update(self, *args, **kwargs):
if 'last_updated' not in kwargs:
kwargs['last_updated'] = datetime.datetime.now()
if "last_updated" not in kwargs:
kwargs["last_updated"] = datetime.datetime.now()
return super().update(**kwargs)


class BaseModel(models.Model):
pass
created_at = models.DateTimeField(auto_now=True, auto_now_add=True)
last_updated = models.DateTimeField(auto_now=False, auto_now_add=True, null=True)
created_by = models.ForeignKey(null=True, on_deleted=models.SET_NULL, related_name="created_by_+")
updated_by = models.ForeignKey(null=True, on_deleted=models.SET_NULL, related_name="updated_by_+")
102 changes: 51 additions & 51 deletions skillforge/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,36 @@
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-(q_xc+d@c4wzz0@80)nraq&7k^^*@yhj-_8h$a5ax!d0zpgfi$'
SECRET_KEY = "django-insecure-(q_xc+d@c4wzz0@80)nraq&7k^^*@yhj-_8h$a5ax!d0zpgfi$"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['*']
ALLOWED_HOSTS = ["*"]

AUTH_USER_MODEL = 'user.User'
AUTH_USER_MODEL = "user.User"

# Application definition

DJANGO_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
]

THIRD_PARTY_APPS = [
'rest_framework',
'rest_framework_swagger',
'django_filters',
'rest_framework_simplejwt',
'drf_yasg',
"rest_framework",
"rest_framework_swagger",
"django_filters",
"rest_framework_simplejwt",
"drf_yasg",
]

LOCAL_APPS = [
'user',
"user",
]

if DEBUG:
Expand All @@ -60,48 +60,48 @@
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS

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',
"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",
"corsheaders.middleware.CorsMiddleware",
]

ROOT_URLCONF = 'skillforge.urls'
ROOT_URLCONF = "skillforge.urls"

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['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',
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": ["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 = 'skillforge.wsgi.application'
WSGI_APPLICATION = "skillforge.wsgi.application"


# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'skillforge',
'USER': 'django',
'PASSWORD': 'django',
'HOST': 'db',
'PORT': 5432,
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": "skillforge",
"USER": "django",
"PASSWORD": "django",
"HOST": "db",
"PORT": 5432,
}
}

Expand All @@ -123,44 +123,44 @@

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
]


# Internationalization
# https://docs.djangoproject.com/en/4.2/topics/i18n/

LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = "en-us"

TIME_ZONE = 'UTC'
TIME_ZONE = "UTC"

USE_I18N = True

USE_TZ = True

MEDIA_URL = '/media/'
MEDIA_URL = "/media/"

CKEDITOR_UPLOAD_PATH = '/media/'
CKEDITOR_UPLOAD_PATH = "/media/"

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/

STATIC_URL = 'static/'
STATIC_URL = "static/"

# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

# CORS
# ------------------------------------------------------------------------------
Expand All @@ -185,4 +185,4 @@

# Celery
# ------------------------------------------------------------------------------
# BROKER_URL = os.environ.get("BROKER_URL", "amqp://guest:guest@localhost//")
# BROKER_URL = os.environ.get("BROKER_URL", "amqp://guest:guest@localhost//")
Loading

0 comments on commit 23134f4

Please sign in to comment.