Skip to content

Commit

Permalink
tests: Extract TestCase class
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Jan 20, 2023
1 parent b0f8382 commit 5db9f25
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
25 changes: 25 additions & 0 deletions backend/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django.db import connections
from django.test import TransactionTestCase

from api.models import DataItem, Dataset, FieldLevelCheck, ProgressMonitorDataset


class TestCase(TransactionTestCase):
databases = {"default", "data"}
unmanaged = {DataItem, Dataset, FieldLevelCheck, ProgressMonitorDataset}

def setUp(self):
with connections["data"].schema_editor() as schema_editor:
for model in self.unmanaged:
schema_editor.create_model(model)

def tearDown(self):
with connections["data"].schema_editor() as schema_editor:
for model in self.unmanaged:
schema_editor.delete_model(model)

def create(self, model, **kwargs):
obj = model(**kwargs)
obj.full_clean()
obj.save()
return obj
File renamed without changes.
Empty file.
Original file line number Diff line number Diff line change
@@ -1,31 +1,10 @@
from unittest.mock import patch

from django.db import connections
from django.test import TransactionTestCase

from api.models import DataItem, Dataset, FieldLevelCheck, ProgressMonitorDataset
from tests import TestCase


class ViewsTests(TransactionTestCase):
databases = {"default", "data"}
unmanaged = {DataItem, Dataset, FieldLevelCheck, ProgressMonitorDataset}

def setUp(self):
with connections["data"].schema_editor() as schema_editor:
for model in self.unmanaged:
schema_editor.create_model(model)

def tearDown(self):
with connections["data"].schema_editor() as schema_editor:
for model in self.unmanaged:
schema_editor.delete_model(model)

def create(self, model, **kwargs):
obj = model(**kwargs)
obj.full_clean()
obj.save()
return obj

class ViewsTests(TestCase):
@patch("controller.views.publish")
def test_create_invalid(self, publish):
response = self.client.post("/datasets/", {"name": "anything", "collection_id": "xxx"}, "application/json")
Expand Down

0 comments on commit 5db9f25

Please sign in to comment.