<commit_before>from django.test import TestCase
#from django.urls import reverse
from django.contrib.auth.models import User

from rest_framework import status
from rest_framework.test import APIRequestFactory
from rest_framework.test import force_authenticate
from rest_framework.test import APITestCase

from cbe.party.models import Individual, Organisation, TelephoneNumber, EmailContact, GenericPartyRole
from cbe.party.views import IndividualViewSet
from cbe.party.admin import GenericPartyRoleAdminForm, GenericPartyRoleAdmin


class PartyTests(TestCase):
    def setUp(self):
        self.individual = Individual.objects.create(given_names="John", family_names="Doe", form_of_address='Mr', middle_names='Hubert')
        self.organisation = Organisation.objects.create(name='Pen Inc.')
        self.phone = TelephoneNumber.objects.create(number="021123456")
        self.email = EmailContact.objects.create(email_address="<EMAIL>")
        self.role = GenericPartyRole.objects.create(party=self.organisation, name="Generic")

        
    def test_names(self):
        """
        Make sure the names display as expected
        """
        john = Individual.objects.get(given_names="John", family_names="Doe")
        self.assertEqual('{}'.format(john), 'Mr <NAME>')
        self.assertEqual('{}'.format(self.organisation), 'Pen Inc.')
        self.assertEqual('{}'.format(self.phone), '021123456')
        self.assertEqual('{}'.format(self.email), '<EMAIL>')
        
        
    def test_role_asignment(self):
        """
        Make sure the party roles can be assigned to individuals and organisations
        """
        self.assertEqual('{}'.format(self.role), 'Pen Inc. as a Generic')
        self.role.individual = self.individual
        self.assertEqual('{}'.format(self.role.party), '{}'.format(self.role.individual))
        self.role.organisation = self.organisation
        self.assertEqual('{}'.format(self.role.party), '{}'.format(self.role.organisation))
        
        with self.assertRaises(Exception):
            self.role.individual = self.organisation
        with self.assertRaises(Exception):
            self.role.organisation = self.individual

            
class PartyAdminTests(TestCase):
    def setUp(self):
        self.individual = Individual.objects.create(given_names="John", family_names="Doe", form_of_address='Mr', middle_names='Hubert')
        self.organisation = Organisation.objects.create(name='Pen Inc.')
        self.phone = TelephoneNumber.objects.create(number="021123456")
        self.email = EmailContact.objects.create(email_address="<EMAIL>")
        self.role = GenericPartyRole.objects.create(party=self.organisation, name="Generic")
        
        self.superuser = User.objects.create_superuser('john', '<EMAIL>', '<PASSWORD>')
        self.client.login(username='john', password='<PASSWORD>')
        
    def test_genericpartyrole(self):
        """
        Test the genericpartyrole object admin.
        """
        url = '/admin/party/genericpartyrole/{}/'.format(self.role.pk)
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        
class PartyAPITests(APITestCase):
    def setUp(self):
        self.superuser = User.objects.create_superuser('john', '<EMAIL>', '<PASSWORD>')
        self.client.login(username='john', password='<PASSWORD>')
        self.individual = Individual.objects.create(given_names="John", family_names="Doe")
        self.factory = APIRequestFactory()

        
    def test_get_individual(self):<commit_msg>Party admin tests<commit_after>from django.test import TestCase
#from django.urls import reverse
from django.contrib.auth.models import User

from rest_framework import status
from rest_framework.test import APIRequestFactory
from rest_framework.test import force_authenticate
from rest_framework.test import APITestCase

from cbe.party.models import Individual, Organisation, TelephoneNumber, EmailContact, GenericPartyRole
from cbe.party.views import IndividualViewSet
from cbe.party.admin import GenericPartyRoleAdminForm, GenericPartyRoleAdmin


class PartyTests(TestCase):
    def setUp(self):
        self.individual = Individual.objects.create(given_names="John", family_names="Doe", form_of_address='Mr', middle_names='Hubert')
        self.organisation = Organisation.objects.create(name='Pen Inc.')
        self.phone = TelephoneNumber.objects.create(number="021123456")
        self.email = EmailContact.objects.create(email_address="<EMAIL>")
        self.role = GenericPartyRole.objects.create(party=self.organisation, name="Generic")

        
    def test_names(self):
        """
        Make sure the names display as expected
        """
        john = Individual.objects.get(given_names="John", family_names="Doe")
        self.assertEqual('{}'.format(john), 'Mr <NAME>')
        self.assertEqual('{}'.format(self.organisation), 'Pen Inc.')
        self.assertEqual('{}'.format(self.phone), '021123456')
        self.assertEqual('{}'.format(self.email), '<EMAIL>')
        
        
    def test_role_asignment(self):
        """
        Make sure the party roles can be assigned to individuals and organisations
        """
        self.assertEqual('{}'.format(self.role), 'Pen Inc. as a Generic')
        self.role.individual = self.individual
        self.assertEqual('{}'.format(self.role.party), '{}'.format(self.role.individual))
        self.role.organisation = self.organisation
        self.assertEqual('{}'.format(self.role.party), '{}'.format(self.role.organisation))
        
        with self.assertRaises(Exception):
            self.role.individual = self.organisation
        with self.assertRaises(Exception):
            self.role.organisation = self.individual

            
class PartyAdminTests(TestCase):
    def setUp(self):
        self.individual = Individual.objects.create(given_names="John", family_names="Doe", form_of_address='Mr', middle_names='Hubert')
        self.organisation = Organisation.objects.create(name='Pen Inc.')
        self.phone = TelephoneNumber.objects.create(number="021123456")
        self.email = EmailContact.objects.create(email_address="<EMAIL>")
        self.role = GenericPartyRole.objects.create(party=self.organisation, name="Generic")
        
        self.superuser = User.objects.create_superuser('john', '<EMAIL>', '<PASSWORD>')
        self.client.login(username='john', password='<PASSWORD>')
        
    def test_genericpartyrole(self):
        """
        Test the genericpartyrole object admin.
        """
        url = 'http://127.0.0.1/admin/party/genericpartyrole/{}/'.format(self.role.pk)
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        
class PartyAPITests(APITestCase):
    def setUp(self):
        self.superuser = User.objects.create_superuser('john', '<EMAIL>', '<PASSWORD>')
        self.client.login(username='john', password='<PASSWORD>')
        self.individual = Individual.objects.create(given_names="John", family_names="Doe")
        self.factory = APIRequestFactory()

        
    def test_get_individual(self):
{'fraction_non_alphanumeric': 0.1288069293098631, 'fraction_numerical': 0.009220452640402346, 'mean_word_length': 3.5081863979848866, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '2802601', 'n_tokens_mistral': 2088, 'n_tokens_neox': 1970, 'n_words': 355}