<commit_before>from django.urls import reverse
from django.test import TestCase
from rest_framework import status
from rest_framework.test import APITestCase
from registries.models import Organization, Person
from gwells.models.ProvinceStateCode import ProvinceStateCode

# Note: see postman/newman for more API tests.
# Postman API tests include making requests with incomplete data, missing required fields etc.
# They are located at {base-dir}/api-tests/

# Django unit tests

class OrganizationTests(TestCase):
    """
    Tests for the Organization model
    """

    def setUp(self):
        # Create a ProvinceStateCode object for our Organization's foreign key field
        ProvinceStateCode.objects.create(
            code = 'BC',
            description = 'British Columbia',
            sort_order = 1
        )

        Organization.objects.create(
            name='Frankie and Betty Well Drilling Co.',
            city='Victoria',
            province_state = ProvinceStateCode.objects.get(code='BC')
        )

    def test_organization_was_created(self):
        org = Organization.objects.get(name='Frankie and Betty Well Drilling Co.')
        self.assertEqual(org.city, 'Victoria')


class PersonTests(TestCase):
    """
    Tests for Person model
    """

    def setUp(self):
        Person.objects.create(
            first_name='Bobby',
            surname='Driller'
        )

    def test_person_was_created(self):
        person = Person.objects.get(first_name='Bobby')
        self.assertEqual(person.first_name, 'Bobby')


# Django REST Framework tests

class APIOrganizationTests(APITestCase):
    """
    Tests for the Organization resource endpoint

    Includes tests for create, list, update (patch and put), and delete
    using Django REST Framework's APIClient
    """

    def test_create_organization(self):
        """
        Create a new organization object.
        """
        initial_data = {
            'name': '<NAME>',
            'city': 'Victoria'
        }

        url = reverse('organization-list')
        count_before = Organization.objects.count()

        response = self.client.post(url, initial_data, format='json')

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(Organization.objects.count(), count_before + 1)
<commit_msg>Better tests for including a province when creating an organization<commit_after>from django.urls import reverse
from django.test import TestCase
from rest_framework import status
from rest_framework.test import APITestCase
from registries.models import Organization, Person
from gwells.models.ProvinceStateCode import ProvinceStateCode

# Note: see postman/newman for more API tests.
# Postman API tests include making requests with incomplete data, missing required fields etc.
# They are located at {base-dir}/api-tests/

# Django unit tests

class OrganizationTests(TestCase):
    """
    Tests for the Organization model
    """

    def setUp(self):
        # Create a ProvinceStateCode object for our Organization's foreign key field
        province = ProvinceStateCode.objects.create(
            code = 'BC',
            description = 'British Columbia',
            sort_order = 1
        )

        Organization.objects.create(
            name='Frankie and Betty Well Drilling Co.',
            city='Victoria',
            province_state = province
        )

    def test_organization_was_created(self):
        org = Organization.objects.get(name='Frankie and Betty Well Drilling Co.')
        self.assertEqual(org.city, 'Victoria')


class PersonTests(TestCase):
    """
    Tests for Person model
    """

    def setUp(self):
        Person.objects.create(
            first_name='Bobby',
            surname='Driller'
        )

    def test_person_was_created(self):
        person = Person.objects.get(first_name='Bobby')
        self.assertEqual(person.first_name, 'Bobby')


# Django REST Framework tests

class APIOrganizationTests(APITestCase):
    """
    Tests for the Organization resource endpoint

    Includes tests for create, list, update (patch and put), and delete
    using Django REST Framework's APIClient
    """

    def test_create_organization(self):
        """
        Create a new organization object.
        """

        # create a ProvinceStateCode object
        province = ProvinceStateCode.objects.create(
            code = 'BC',
            description = 'British Columbia',
            sort_order = 1
        )

        initial_data = {
            'name': '<NAME>',
            'city': 'Victoria',
            'province_state': province.province_state_guid
        }

        url = reverse('organization-list')
        count_before = Organization.objects.count()

        response = self.client.post(url, initial_data, format='json')

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(Organization.objects.count(), count_before + 1)

{'fraction_non_alphanumeric': 0.08769106999195495, 'fraction_numerical': 0.0022123893805309734, 'mean_word_length': 2.7223053892215567, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2598876', 'n_tokens_mistral': 1343, 'n_tokens_neox': 1273, 'n_words': 367}