This repository has been archived by the owner on Feb 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 503
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 #247 from danielquinn/issue/235
Allow correspondents to be deleted without deleting their documents
- Loading branch information
Showing
6 changed files
with
82 additions
and
2 deletions.
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
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ pytz>=2016.10 | |
gunicorn==19.6.0 | ||
|
||
# For the tests | ||
factory-boy | ||
pytest | ||
pytest-django | ||
pytest-sugar | ||
|
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,21 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.10.5 on 2017-07-15 17:12 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('documents', '0017_auto_20170512_0507'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='document', | ||
name='correspondent', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='documents', to='documents.Correspondent'), | ||
), | ||
] |
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
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,17 @@ | ||
import factory | ||
|
||
from ..models import Document, Correspondent | ||
|
||
|
||
class CorrespondentFactory(factory.DjangoModelFactory): | ||
|
||
class Meta: | ||
model = Correspondent | ||
|
||
name = factory.Faker("name") | ||
|
||
|
||
class DocumentFactory(factory.DjangoModelFactory): | ||
|
||
class Meta: | ||
model = Document |
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,31 @@ | ||
from django.test import TestCase | ||
|
||
from ..models import Document, Correspondent | ||
from .factories import DocumentFactory, CorrespondentFactory | ||
|
||
|
||
class CorrespondentTestCase(TestCase): | ||
|
||
def test___str__(self): | ||
for s in ("test", "οχι", "test with fun_charÅc'\"terß"): | ||
correspondent = CorrespondentFactory.create(name=s) | ||
self.assertEqual(str(correspondent), s) | ||
|
||
|
||
class DocumentTestCase(TestCase): | ||
|
||
def test_correspondent_deletion_does_not_cascade(self): | ||
|
||
self.assertEqual(Correspondent.objects.all().count(), 0) | ||
correspondent = CorrespondentFactory.create() | ||
self.assertEqual(Correspondent.objects.all().count(), 1) | ||
|
||
self.assertEqual(Document.objects.all().count(), 0) | ||
DocumentFactory.create(correspondent=correspondent) | ||
self.assertEqual(Document.objects.all().count(), 1) | ||
self.assertIsNotNone(Document.objects.all().first().correspondent) | ||
|
||
correspondent.delete() | ||
self.assertEqual(Correspondent.objects.all().count(), 0) | ||
self.assertEqual(Document.objects.all().count(), 1) | ||
self.assertIsNone(Document.objects.all().first().correspondent) |