Skip to content

Commit

Permalink
Add coursework to represent completed student work.
Browse files Browse the repository at this point in the history
  • Loading branch information
mblayman committed Jan 25, 2020
1 parent b78f432 commit 2116ed6
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 4 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@ local:
heroku local -f Procfile.local

graph:
./manage.py graph_models core courses schools users -o models.png
./manage.py graph_models \
core \
courses \
schools \
students \
users \
-o models.png
33 changes: 31 additions & 2 deletions homeschool/students/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 3.0.1 on 2020-01-25 21:40
# Generated by Django 3.0.1 on 2020-01-25 22:09

import django.db.models.deletion
from django.db import migrations, models
Expand All @@ -8,7 +8,7 @@ class Migration(migrations.Migration):

initial = True

dependencies = [("schools", "0001_initial")]
dependencies = [("courses", "0001_initial"), ("schools", "0001_initial")]

operations = [
migrations.CreateModel(
Expand Down Expand Up @@ -61,4 +61,33 @@ class Migration(migrations.Migration):
),
],
),
migrations.CreateModel(
name="Coursework",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("completed_date", models.DateField()),
(
"course_task",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="courses.CourseTask",
),
),
(
"student",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="students.Student",
),
),
],
),
]
8 changes: 8 additions & 0 deletions homeschool/students/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@ class Enrollment(models.Model):

student = models.ForeignKey(Student, on_delete=models.CASCADE)
grade_level = models.ForeignKey("schools.GradeLevel", on_delete=models.CASCADE)


class Coursework(models.Model):
"""The work that student completes for course tasks"""

student = models.ForeignKey(Student, on_delete=models.CASCADE)
course_task = models.ForeignKey("courses.CourseTask", on_delete=models.CASCADE)
completed_date = models.DateField()
12 changes: 12 additions & 0 deletions homeschool/students/tests/factories.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import factory
from django.utils import timezone


class StudentFactory(factory.django.DjangoModelFactory):
Expand All @@ -18,3 +19,14 @@ class Meta:
grade_level = factory.SubFactory(
"homeschool.schools.tests.factories.GradeLevelFactory"
)


class CourseworkFactory(factory.django.DjangoModelFactory):
class Meta:
model = "students.Coursework"

student = factory.SubFactory(StudentFactory)
course_task = factory.SubFactory(
"homeschool.courses.tests.factories.CourseTaskFactory"
)
completed_date = factory.LazyFunction(lambda: timezone.now().date())
34 changes: 33 additions & 1 deletion homeschool/students/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import datetime

from homeschool.courses.tests.factories import CourseTaskFactory
from homeschool.schools.tests.factories import GradeLevelFactory, SchoolFactory
from homeschool.students.tests.factories import EnrollmentFactory, StudentFactory
from homeschool.students.tests.factories import (
CourseworkFactory,
EnrollmentFactory,
StudentFactory,
)
from homeschool.test import TestCase


Expand Down Expand Up @@ -57,3 +64,28 @@ def test_has_grade_level(self):
enrollment = EnrollmentFactory(grade_level=grade_level)

self.assertEqual(enrollment.grade_level, grade_level)


class TestCoursework(TestCase):
def test_factory(self):
coursework = CourseworkFactory()

self.assertIsNotNone(coursework)

def test_has_student(self):
student = StudentFactory()
coursework = CourseworkFactory(student=student)

self.assertEqual(coursework.student, student)

def test_has_course_task(self):
course_task = CourseTaskFactory()
coursework = CourseworkFactory(course_task=course_task)

self.assertEqual(coursework.course_task, course_task)

def test_completed_date(self):
completed_date = datetime.date.today()
coursework = CourseworkFactory(completed_date=completed_date)

self.assertEqual(coursework.completed_date, completed_date)

0 comments on commit 2116ed6

Please sign in to comment.