From 2898a6f10390ce2c54a67851389668c8c729f8a6 Mon Sep 17 00:00:00 2001 From: b_crocker Date: Fri, 17 Sep 2021 13:58:38 -0400 Subject: [PATCH] Added Rubric Factory Tests --- .../0002_alter_rubriccell_options.py | 17 +++++++ Main/models.py | 3 ++ tests/test_rubric.json | 33 +++++++++++++ tests/test_rubric.py | 49 +++++++++++++++++++ 4 files changed, 102 insertions(+) create mode 100644 Main/migrations/0002_alter_rubriccell_options.py create mode 100644 tests/test_rubric.json create mode 100644 tests/test_rubric.py diff --git a/Main/migrations/0002_alter_rubriccell_options.py b/Main/migrations/0002_alter_rubriccell_options.py new file mode 100644 index 0000000..69dd4c6 --- /dev/null +++ b/Main/migrations/0002_alter_rubriccell_options.py @@ -0,0 +1,17 @@ +# Generated by Django 3.2.7 on 2021-09-17 17:57 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('Main', '0001_initial'), + ] + + operations = [ + migrations.AlterModelOptions( + name='rubriccell', + options={'ordering': ['-score']}, + ), + ] diff --git a/Main/models.py b/Main/models.py index 0b97d59..7c99f19 100644 --- a/Main/models.py +++ b/Main/models.py @@ -29,6 +29,9 @@ class RubricCell(BaseModel): score = models.FloatField() parent_row = models.ForeignKey(RubricRow, on_delete=models.CASCADE) + class Meta: + ordering = ['-score'] + class Review(BaseModel): diff --git a/tests/test_rubric.json b/tests/test_rubric.json new file mode 100644 index 0000000..9569dbe --- /dev/null +++ b/tests/test_rubric.json @@ -0,0 +1,33 @@ +{ + "name": "Test Rubric", + "rows": [ + { + "name": "row 1", + "description": "row desc 1", + "cells": [ + { + "description": "cell 1 row 1", + "score": 5 + }, + { + "description": "cell 2 row 1", + "score": 10 + } + ] + }, + { + "name": "row 2", + "description": "row desc 2", + "cells": [ + { + "description": "cell 1 row 2", + "score": 2 + }, + { + "description": "cell 2 row 2", + "score": 1 + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/test_rubric.py b/tests/test_rubric.py new file mode 100644 index 0000000..79e3e33 --- /dev/null +++ b/tests/test_rubric.py @@ -0,0 +1,49 @@ +from Main.models import Rubric, RubricRow, RubricCell + +from django.test import TestCase +from Main.views import rubric_factory + + +class RubricFactory(TestCase): + + new_rubric = None + rows = [] + + def setUp(self) -> None: + with open("tests/test_rubric.json", 'r') as file: + test_json = file.read() + self.new_rubric = rubric_factory(test_json) + self.rows = RubricRow.objects.filter(parent_rubric=self.new_rubric) + + def test_rubric_main(self): + self.assertEquals(self.new_rubric.name, "Test Rubric") + self.assertEquals(self.new_rubric.max_score, 12) + + def test_rubric_rows(self): + row_1 = self.rows[0] + self.assertEquals(row_1.name, "row 1") + self.assertEquals(row_1.description, "row desc 1") + self.assertEquals(row_1.max_score, 10) + row_2 = self.rows[1] + self.assertEquals(row_2.name, "row 2") + self.assertEquals(row_2.description, "row desc 2") + self.assertEquals(row_2.max_score, 2) + + def test_rubric_cells(self): + row_1_cells = RubricCell.objects.filter(parent_row=self.rows[0]) + row_1_cell_1 = row_1_cells[0] + row_1_cell_2 = row_1_cells[1] + self.assertEquals(row_1_cell_1.description, "cell 2 row 1") + self.assertEquals(row_1_cell_2.description, "cell 1 row 1") + self.assertEquals(row_1_cell_1.score, 10) + self.assertEquals(row_1_cell_2.score, 5) + + row_2_cells = RubricCell.objects.filter(parent_row=self.rows[1]) + row_2_cell_1 = row_2_cells[0] + row_2_cell_2 = row_2_cells[1] + self.assertEquals(row_2_cell_1.description, "cell 1 row 2") + self.assertEquals(row_2_cell_2.description, "cell 2 row 2") + self.assertEquals(row_2_cell_1.score, 2) + self.assertEquals(row_2_cell_2.score, 1) + + -- knotmirror 0.0.1