mirror of https://github.com/doccano/doccano.git
Hironsan
2 years ago
4 changed files with 114 additions and 0 deletions
Split View
Diff Options
-
5backend/labels/managers.py
-
61backend/labels/migrations/0015_create_boundingbox_table.py
-
19backend/labels/models.py
-
29backend/labels/tests/test_bbox.py
@ -0,0 +1,61 @@ |
|||
# Generated by Django 4.0.4 on 2022-06-29 06:19 |
|||
|
|||
from django.conf import settings |
|||
from django.db import migrations, models |
|||
import django.db.models.deletion |
|||
import uuid |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
("label_types", "0007_delete_relationtypeold"), |
|||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), |
|||
("examples", "0006_alter_example_upload_name"), |
|||
("labels", "0014_remove_uuid_null"), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.CreateModel( |
|||
name="BoundingBox", |
|||
fields=[ |
|||
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), |
|||
("uuid", models.UUIDField(default=uuid.uuid4, unique=True)), |
|||
("prob", models.FloatField(default=0.0)), |
|||
("manual", models.BooleanField(default=False)), |
|||
("created_at", models.DateTimeField(auto_now_add=True)), |
|||
("updated_at", models.DateTimeField(auto_now=True)), |
|||
("x", models.FloatField()), |
|||
("y", models.FloatField()), |
|||
("width", models.FloatField()), |
|||
("height", models.FloatField()), |
|||
( |
|||
"example", |
|||
models.ForeignKey( |
|||
on_delete=django.db.models.deletion.CASCADE, related_name="bboxes", to="examples.example" |
|||
), |
|||
), |
|||
( |
|||
"label", |
|||
models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="label_types.categorytype"), |
|||
), |
|||
("user", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), |
|||
], |
|||
), |
|||
migrations.AddConstraint( |
|||
model_name="boundingbox", |
|||
constraint=models.CheckConstraint(check=models.Q(("x__gte", 0)), name="x >= 0"), |
|||
), |
|||
migrations.AddConstraint( |
|||
model_name="boundingbox", |
|||
constraint=models.CheckConstraint(check=models.Q(("y__gte", 0)), name="y >= 0"), |
|||
), |
|||
migrations.AddConstraint( |
|||
model_name="boundingbox", |
|||
constraint=models.CheckConstraint(check=models.Q(("width__gte", 0)), name="width >= 0"), |
|||
), |
|||
migrations.AddConstraint( |
|||
model_name="boundingbox", |
|||
constraint=models.CheckConstraint(check=models.Q(("height__gte", 0)), name="height >= 0"), |
|||
), |
|||
] |
@ -0,0 +1,29 @@ |
|||
from django.db import IntegrityError |
|||
from django.test import TestCase |
|||
from model_mommy import mommy |
|||
|
|||
from projects.tests.utils import prepare_project |
|||
|
|||
|
|||
class TestBoundingBox(TestCase): |
|||
@classmethod |
|||
def setUpTestData(cls): |
|||
cls.project = prepare_project() |
|||
cls.example = mommy.make("Example", project=cls.project.item) |
|||
cls.user = cls.project.admin |
|||
|
|||
def test_cannot_create_label_if_x_is_less_than_zero(self): |
|||
with self.assertRaises(IntegrityError): |
|||
mommy.make("BoundingBox", example=self.example, x=-1, y=0, width=0, height=0) |
|||
|
|||
def test_cannot_create_label_if_y_is_less_than_zero(self): |
|||
with self.assertRaises(IntegrityError): |
|||
mommy.make("BoundingBox", example=self.example, x=0, y=-1, width=0, height=0) |
|||
|
|||
def test_cannot_create_label_if_width_is_less_than_zero(self): |
|||
with self.assertRaises(IntegrityError): |
|||
mommy.make("BoundingBox", example=self.example, x=0, y=0, width=-1, height=0) |
|||
|
|||
def test_cannot_create_label_if_height_is_less_than_zero(self): |
|||
with self.assertRaises(IntegrityError): |
|||
mommy.make("BoundingBox", example=self.example, x=0, y=0, width=0, height=-1) |
Write
Preview
Loading…
Cancel
Save