Skip to content

Admin

Admin page for Occurrence models.

SurveyMethodAdmin

Bases: ModelAdmin

Admin page for SurveyMethod model

Factories

SamplingSizeUnitFactory

Bases: DjangoModelFactory

Sampling size unit factory.

SurveyMethodFactory

Bases: DjangoModelFactory

Survey method factory.

Models

SamplingSizeUnit

Bases: Model

Sampling size unit model.

SurveyMethod

Bases: Model

Survey method model.

Test Case

SamplingSizeUnitTestCase

Bases: TestCase

Sampling size unit testcase.

setUpTestData classmethod

setUpTestData()

Setup test data.

Source code in django_project/occurrence/test_occurrence_models.py
@classmethod
def setUpTestData(cls):
    """Setup test data."""
    cls.sampling_size_unit = SamplingSizeUnitFactory(unit='cm')

test_create_sampling_size_unit

test_create_sampling_size_unit()

Test create sampling size unit.

Source code in django_project/occurrence/test_occurrence_models.py
def test_create_sampling_size_unit(self):
    """Test create sampling size unit."""
    self.assertTrue(isinstance(self.sampling_size_unit, SamplingSizeUnit))
    self.assertEqual(SamplingSizeUnit.objects.count(), 1)
    self.assertEqual(self.sampling_size_unit.unit, 'cm')

test_delete_sampling_size_unit

test_delete_sampling_size_unit()

Test delete sampling size unit.

Source code in django_project/occurrence/test_occurrence_models.py
def test_delete_sampling_size_unit(self):
    """Test delete sampling size unit."""
    self.sampling_size_unit.delete()
    self.assertEqual(SamplingSizeUnit.objects.count(), 0)

test_sampling_size_unit_unique_unit_constraint

test_sampling_size_unit_unique_unit_constraint()

Testing unique values for the unit.

Source code in django_project/occurrence/test_occurrence_models.py
def test_sampling_size_unit_unique_unit_constraint(self):
    """Testing unique values for the unit."""
    with self.assertRaises(Exception) as raised:
        SamplingSizeUnitFactory(unit='mm')
        self.assertEqual(raised.exception, IntegrityError)

test_update_sampling_size_unit

test_update_sampling_size_unit()

Test update sampling size unit.

Source code in django_project/occurrence/test_occurrence_models.py
def test_update_sampling_size_unit(self):
    """Test update sampling size unit."""
    self.sampling_size_unit.unit = 'mm'
    self.sampling_size_unit.save()
    self.assertEqual(SamplingSizeUnit.objects.get(id=self.sampling_size_unit.id).unit, 'mm')

SurveyMethodTestCase

Bases: TestCase

Survey method test case.

setUpTestData classmethod

setUpTestData()

Setup test data.

Source code in django_project/occurrence/test_occurrence_models.py
@classmethod
def setUpTestData(cls):
    """Setup test data."""
    cls.survey_method = SurveyMethodFactory()

test_create_survey_method

test_create_survey_method()

Test create survey method.

Source code in django_project/occurrence/test_occurrence_models.py
def test_create_survey_method(self):
    """Test create survey method."""
    self.assertTrue(
        isinstance(self.survey_method, SurveyMethod)
    )
    self.assertEqual(SurveyMethod.objects.count(), 1)
    self.assertEqual(self.survey_method.name, SurveyMethod.objects.get(id=self.survey_method.id).name)

test_delete_survey_method

test_delete_survey_method()

Test delete survey method.

Source code in django_project/occurrence/test_occurrence_models.py
def test_delete_survey_method(self):
    """Test delete survey method."""
    self.survey_method.delete()
    self.assertEqual(SurveyMethod.objects.count(), 0)

test_survey_method_unique_name_constraint

test_survey_method_unique_name_constraint()

Test survey method unique name constraint.

Source code in django_project/occurrence/test_occurrence_models.py
def test_survey_method_unique_name_constraint(self):
    """Test survey method unique name constraint."""
    with self.assertRaises(Exception) as raised:
        SurveyMethodFactory(name='survey method 0')
        self.assertEqual(IntegrityError, type(raised.exception))

test_survey_method_unique_sort_id_constraint

test_survey_method_unique_sort_id_constraint()

Test survey method unique sort id constraint.

Source code in django_project/occurrence/test_occurrence_models.py
def test_survey_method_unique_sort_id_constraint(self):
    """Test survey method unique sort id constraint."""
    with self.assertRaises(Exception) as raised:
        SurveyMethodFactory(sort_id=0)
        self.assertEqual(IntegrityError, type(raised.exception))

test_update_survey_method

test_update_survey_method()

Test update survey method.

Source code in django_project/occurrence/test_occurrence_models.py
def test_update_survey_method(self):
    """Test update survey method."""
    self.survey_method.name = 'survey method 1'
    self.survey_method.save()
    self.assertEqual(
        SurveyMethod.objects.get(id=self.survey_method.id).name,
        'survey method 1',
    )