<commit_before># -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os
from datetime import date

from django.urls import reverse
from django.conf import settings
from rest_framework import status as statuses

from partner.models import (
    Partner,
    PartnerProfile,
    PartnerMailingAddress,
    PartnerHeadOrganization,
    PartnerAuditAssessment,
    PartnerReporting,
    PartnerMandateMission,
    PartnerFunding,
    PartnerOtherInfo,
    PartnerInternalControl,
)
from common.models import Point
from common.tests.base import BaseAPITestCase
from common.factories import (
    AgencyFactory,
    UserFactory,
    PartnerFactory,
    OtherAgencyFactory,
    PointFactory,
)
from common.consts import (
    BUDGET_CHOICES,
    FUNCTIONAL_RESPONSIBILITY_CHOICES,
)


class TestPartnerCountryProfileAPIView(BaseAPITestCase):

    quantity = 1
    initial_factories = [
        OtherAgencyFactory,
        AgencyFactory,
        UserFactory,
        PartnerFactory,
    ]

    def test_create_country_profile(self):
        partner = Partner.objects.first()
        url = reverse('partners:country-profile', kwargs={"pk": partner.id})
        response = self.client.get(url, format='json')
        chosen_country_to_create = map(lambda x: x['country_code'],
                                       filter(lambda x: x['exist'] is False, response.data['countries_profile']))
        payload = {
            'chosen_country_to_create': chosen_country_to_create,
        }
        response = self.client.post(url, data=payload, format='json')
        expected_count = len(chosen_country_to_create)
        self.assertTrue(statuses.is_success(response.status_code))
        self.assertEquals(Partner.objects.filter(hq_id=partner.id).count(), expected_count)
        self.assertEquals(PartnerProfile.objects.filter(partner__hq=partner).count(), expected_count)
        self.assertEquals(PartnerMailingAddress.objects.filter(partner__hq=partner).count(), expected_count)
        self.assertEquals(PartnerHeadOrganization.objects.filter(partner__hq=partner).count(), expected_count)
        self.assertEquals(PartnerAuditAssessment.objects.filter(partner__hq=partner).count(), expected_count)
        self.assertEquals(PartnerReporting.objects.filter(partner__hq=partner).count(), expected_count)
        self.assertEquals(PartnerMandateMission.objects.filter(partner__hq=partner).count(), expected_count)
        self.assertEquals(PartnerFunding.objects.filter(partner__hq=partner).count(), expected_count)
        self.assertEquals(PartnerOtherInfo.objects.filter(partner__hq=partner).count(), expected_count)
        self.assertEquals(PartnerInternalControl.objects.filter(partner__hq=partner).count(),
                          expected_count*len(list(FUNCTIONAL_RESPONSIBILITY_CHOICES._db_values)))

<commit_msg>fix unit test for country profile<commit_after># -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os
from datetime import date

from django.urls import reverse
from django.conf import settings
from rest_framework import status as statuses

from partner.models import (
    Partner,
    PartnerProfile,
    PartnerMailingAddress,
    PartnerHeadOrganization,
    PartnerAuditAssessment,
    PartnerReporting,
    PartnerMandateMission,
    PartnerFunding,
    PartnerOtherInfo,
    PartnerInternalControl,
)
from common.models import Point
from common.tests.base import BaseAPITestCase
from common.factories import (
    AgencyFactory,
    UserFactory,
    PartnerFactory,
    OtherAgencyFactory,
    PointFactory,
)
from common.consts import (
    BUDGET_CHOICES,
    FUNCTIONAL_RESPONSIBILITY_CHOICES,
)


class TestPartnerCountryProfileAPIView(BaseAPITestCase):

    quantity = 1
    initial_factories = [
        OtherAgencyFactory,
        AgencyFactory,
        UserFactory,
        PartnerFactory,
    ]

    def test_create_country_profile(self):
        partner = Partner.objects.first()
        url = reverse('partners:country-profile', kwargs={"pk": partner.id})
        response = self.client.get(url, format='json')
        chosen_country_to_create = map(lambda x: x['country_code'],
                                       filter(lambda x: x['exist'] is False, response.data['countries_profile']))
        payload = {
            'chosen_country_to_create': chosen_country_to_create,
        }
        response = self.client.post(url, data=payload, format='json')
        expected_count = len(chosen_country_to_create)
        self.assertTrue(statuses.is_success(response.status_code))
        self.assertEquals(Partner.objects.filter(hq_id=partner.id).count(), expected_count)
        self.assertEquals(PartnerProfile.objects.filter(partner__hq=partner).count(), expected_count)
        self.assertEquals(PartnerMailingAddress.objects.filter(partner__hq=partner).count(), expected_count)
        self.assertEquals(PartnerHeadOrganization.objects.filter(partner__hq=partner).count(), 0)
        self.assertEquals(PartnerAuditAssessment.objects.filter(partner__hq=partner).count(), expected_count)
        self.assertEquals(PartnerReporting.objects.filter(partner__hq=partner).count(), expected_count)
        self.assertEquals(PartnerMandateMission.objects.filter(partner__hq=partner).count(), expected_count)
        self.assertEquals(PartnerFunding.objects.filter(partner__hq=partner).count(), expected_count)
        self.assertEquals(PartnerOtherInfo.objects.filter(partner__hq=partner).count(), expected_count)
        self.assertEquals(PartnerInternalControl.objects.filter(partner__hq=partner).count(),
                          expected_count*len(list(FUNCTIONAL_RESPONSIBILITY_CHOICES._db_values)))


{'fraction_non_alphanumeric': 0.09268722466960352, 'fraction_numerical': 0.000881057268722467, 'mean_word_length': 4.031914893617022, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '364839', 'n_tokens_mistral': 1629, 'n_tokens_neox': 1628, 'n_words': 247}