-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from NyoriK/develop
added new app and added tests for the models.py and admin.py; updated…
- Loading branch information
Showing
11 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ services: | |
- .:/code | ||
ports: | ||
- "8000:8000" | ||
env_file: | ||
- .env | ||
depends_on: | ||
db: | ||
condition: service_healthy |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from django.contrib import admin | ||
from . import models | ||
|
||
|
||
class TaskAdmin(admin.ModelAdmin): | ||
model = models.Task | ||
list_display = ('excerpt',) | ||
|
||
def excerpt(self, obj): | ||
return obj.get_excerpt(8) | ||
|
||
|
||
admin.site.register(models.Task, TaskAdmin) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class TasksConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'tasks' |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.db import models | ||
|
||
|
||
class Task(models.Model): | ||
title = models.CharField(max_length=100) | ||
is_completed = models.BooleanField(default=False) | ||
|
||
def get_excerpt(self, total_char): | ||
return self.title[:total_char] |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from .. import models | ||
from .. import admin | ||
from django.contrib.admin.sites import AdminSite | ||
import pytest | ||
from mixer.backend.django import mixer | ||
|
||
|
||
@pytest.mark.django_db | ||
class TestTaskAdmin: | ||
def test_excerpt(self): | ||
site = AdminSite() | ||
task_admin = admin.TaskAdmin(models.Task, site) | ||
|
||
obj = mixer.blend('tasks.Task', title='Buy milk from the market') | ||
result = task_admin.excerpt(obj) | ||
assert result == 'Buy milk', 'Should return first few characters' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import pytest | ||
from mixer.backend.django import mixer | ||
|
||
|
||
@pytest.mark.django_db | ||
class TestTask: | ||
def test_model(self): | ||
obj = mixer.blend('tasks.Task') | ||
assert obj.pk == 1, 'Should create a task instance' | ||
|
||
def test_excerpt(self): | ||
obj = mixer.blend('tasks.Task', title='Buy milk from the market') | ||
result = obj.get_excerpt(8) | ||
assert result == 'Buy milk', 'Should return first few characters' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.shortcuts import render | ||
|
||
# Create your views here. |
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