Skip to content

Commit

Permalink
failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nulzo committed Oct 28, 2023
1 parent 19a6406 commit 9417892
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 82 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,5 @@ lerna-debug.log
.DS_Store
Thumbs.db
.ruff_cache/

poetry.toml
2 changes: 1 addition & 1 deletion backend/base/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from django.contrib import admin
from django.urls import path

from backend.src.api import views as routing
from src.api import views as routing

urlpatterns = [
# Admin URLS
Expand Down
2 changes: 1 addition & 1 deletion backend/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ format:

.PHONY test:
test:
pytest .
coverage run --source=src/. -m pytest tests/ --capture=no
36 changes: 32 additions & 4 deletions backend/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ websockets = "^11.0.3"
channels = {extras = ["daphne"], version = "^4.0.0"}
pandas = "^2.1.1"
django-extensions = "^3.2.3"
coverage = "^7.3.2"
pytest-cov = "^4.1.0"
pytest-django = "^4.5.2"

[tool.poetry.group.dev.dependencies]
bruhcolor = "^0.0.56"
Expand Down
3 changes: 3 additions & 0 deletions backend/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
DJANGO_SETTINGS_MODULE = base.settings
# django_find_project = false
58 changes: 4 additions & 54 deletions backend/src/api/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Generated by Django 4.2.6 on 2023-10-25 03:19
# Generated by Django 4.2.6 on 2023-10-28 01:51

from django.db import migrations, models
import django.db.models.deletion
import django.db.models.manager
from django.db import migrations, models


class Migration(migrations.Migration):
Expand All @@ -26,46 +26,7 @@ class Migration(migrations.Migration):
("course_department", models.CharField(default="CSCI", max_length=10)),
("course_name", models.CharField(max_length=100)),
("course_id", models.CharField(max_length=25)),
("is_active", models.BooleanField(default=True)),
],
),
migrations.CreateModel(
name="CSLC_Hours",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("mondayOpen", models.TimeField()),
("mondayClose", models.TimeField()),
("tuesdayOpen", models.TimeField()),
("tuesdayClose", models.TimeField()),
("wednesdayOpen", models.TimeField()),
("wednesdayClose", models.TimeField()),
("thursdayOpen", models.TimeField()),
("thursdayClose", models.TimeField()),
("fridayOpen", models.TimeField()),
("fridayClose", models.TimeField()),
("saturdayOpen", models.TimeField()),
("saturdayClose", models.TimeField()),
("sundayOpen", models.TimeField()),
("sundayClose", models.TimeField()),
("mondayIsOpen", models.BooleanField(default=True)),
("tuesdayIsOpen", models.BooleanField(default=True)),
("wednesdayIsOpen", models.BooleanField(default=True)),
("thursdayIsOpen", models.BooleanField(default=True)),
("fridayIsOpen", models.BooleanField(default=True)),
("saturdayIsOpen", models.BooleanField(default=True)),
("sundayIsOpen", models.BooleanField(default=False)),
],
options={
"verbose_name_plural": "CSLC_Hours",
},
),
migrations.CreateModel(
name="Issues",
Expand All @@ -74,7 +35,7 @@ class Migration(migrations.Migration):
"issue_id",
models.AutoField(editable=False, primary_key=True, serialize=False),
),
("problem_type", models.CharField(max_length=25)),
("problem_type", models.CharField(default="Problem", max_length=25)),
(
"severity",
models.CharField(
Expand Down Expand Up @@ -162,18 +123,7 @@ class Migration(migrations.Migration):
verbose_name="ID",
),
),
(
"modality",
models.CharField(
choices=[
("Online", "850"),
("In-Person", "001"),
("Hybrid", "002"),
],
default="In-Person",
max_length=10,
),
),
("modality", models.CharField(default="001", max_length=10)),
(
"course",
models.ForeignKey(
Expand Down
17 changes: 0 additions & 17 deletions backend/src/api/migrations/0002_alter_section_modality.py

This file was deleted.

4 changes: 2 additions & 2 deletions backend/src/api/models/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
class Course(models.Model):
course_department = models.CharField(max_length=10, blank=False, default="CSCI")
course_name = models.CharField(max_length=100, blank=False)
course_id = models.CharField(max_length=25, blank=False)
is_active = models.BooleanField(default=True, null=False)
course_id = models.CharField(max_length=25, blank=False, null=False)
# is_active = models.BooleanField(default=True, null=False)

def __str__(self):
return str(self.course_name)
3 changes: 0 additions & 3 deletions backend/src/api/tests.py

This file was deleted.

97 changes: 97 additions & 0 deletions backend/tests/test_course.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import pytest
from src.api.models.course import Course
from django.db.utils import IntegrityError
from pytest_django.asserts import assertFieldOutput

@pytest.fixture
def course():
return Course.objects.create(
course_name="Computer Science I",
course_id="1400",
course_department="CIST",
)

@pytest.mark.django_db
def test_course_exists(course):
assert Course.objects.filter(course_name="Computer Science I").exists()

@pytest.mark.django_db
def test_course_str_method(course):
"""
Test the __str__ method of the Course model.
"""
assert str(course) == "Computer Science I"

@pytest.mark.django_db
def test_default_values():
"""
Test that default values are correctly set for course_department and is_active.
"""
course = Course.objects.create(
course_name="Random Name",
course_id="Random_ID"
)
assert course.course_department == "CSCI"

@pytest.mark.django_db
def test_blank_course_department(course):
"""
Test that the course_department field cannot be blank.
"""
assert assertFieldOutput(course)
# with pytest.raises(IntegrityError) as error:

# @pytest.mark.django_db
# def test_blank_course_name():
# """
# Test that the course_name field cannot be blank.
# """
# with pytest.raises(Exception):
# Course.objects.create(
# course_name="",
# course_id="INVALID"
# )

# @pytest.mark.django_db
# def test_blank_course_id():
# """
# Test that the course_id field cannot be blank.
# """
# with pytest.raises(Exception):
# Course.objects.create(
# course_name="Invalid Course",
# course_id=""
# )

# @pytest.mark.django_db
# def test_max_length_course_name():
# """
# Test that the course_name field enforces its maximum length.
# """
# with pytest.raises(Exception):
# Course.objects.create(
# course_name="A" * 101, # Exceeds max_length of 100
# course_id="INVALID"
# )

# @pytest.mark.django_db
# def test_max_length_course_id():
# """
# Test that the course_id field enforces its maximum length.
# """
# with pytest.raises(Exception):
# Course.objects.create(
# course_name="Invalid Course",
# course_id="A" * 26 # Exceeds max_length of 25
# )

# @pytest.mark.django_db
# def test_is_active_default():
# """
# Test that the is_active field is set to True by default.
# """
# course = Course.objects.create(
# course_name="Active Course",
# course_id="ACTIVE123"
# )
# assert course.is_active is True

0 comments on commit 9417892

Please sign in to comment.