<commit_before>import json

from django.core.urlresolvers import reverse
from django.test import TestCase

from censusdata.models import Census2010RaceStats
from hmda.models import LendingStats

class ViewsTest(TestCase):
    fixtures = ['dummy_tracts']

    def setUp(self):
        stats = Census2010RaceStats(
            total_pop=10, hispanic=1, non_hisp_white_only=2,
            non_hisp_black_only=4, non_hisp_asian_only=5)
        stats.geoid_id = '1122233300'
        stats.save()
        stats = Census2010RaceStats(
            total_pop=20, hispanic=2, non_hisp_white_only=1,
            non_hisp_black_only=5, non_hisp_asian_only=4)
        stats.geoid_id = '1122233400'
        stats.save()
        stats = Census2010RaceStats(
            total_pop=100, hispanic=10, non_hisp_white_only=20,
            non_hisp_black_only=30, non_hisp_asian_only=4)
        stats.geoid_id = '1122333300'
        stats.save()
        stats = Census2010RaceStats(
            total_pop=100, hispanic=0, non_hisp_white_only=0,
            non_hisp_black_only=0, non_hisp_asian_only=7)
        stats.geoid_id = '1222233300'
        stats.save()
        lendstats = LendingStats(
            geo_id='10000', institution_id="736-4045996",
            lar_median=3, lar_count=4,
            fha_count=2, fha_bucket=2)
        lendstats.save()

    def tearDown(self):
        Census2010RaceStats.objects.all().delete()


    def test_race_summary(self):
        resp = self.client.get(reverse('censusdata:race_summary'),
                               {'neLat':'1',
                                    'neLon':'1',
                                    'swLat':'0',
                                    'swLon':'0',
                                    'year':'2013',
                                    'action_taken':'1,2,3,4,5',
                                    'lender':'736-4045996'})
        resp = json.loads(resp.content)
        self.assertEqual(len(resp), 4)
        self.assertTrue('1122233300' in resp)
        self.assertEqual(resp['1122233300']['total_pop'], 10)
        self.assertEqual(resp['1122233300']['hispanic'], 1)
        self.assertEqual(resp['1122233300']['non_hisp_white_only'], 2)
        self.assertEqual(resp['1122233300']['non_hisp_black_only'], 4)
        self.assertEqual(resp['1122233300']['non_hisp_asian_only'], 5)
        self.assertEqual(resp['1122233300']['hispanic_perc'], .1)
        self.assertEqual(resp['1122233300']['non_hisp_white_only_perc'], .2)
        self.assertEqual(resp['1122233300']['non_hisp_black_only_perc'], .4)
        self.assertEqual(resp['1122233300']['non_hisp_asian_only_perc'], .5)
        self.assertTrue('1122233400' in resp)
        self.assertEqual(resp['1122233400']['total_pop'], 20)
        self.assertEqual(resp['1122233400']['hispanic'], 2)
        self.assertEqual(resp['1122233400']['non_hisp_white_only'], 1)
        self.assertEqual(resp['1122233400']['non_hisp_black_only'], 5)
        self.assertEqual(resp['1122233400']['non_hisp_asian_only'], 4)
        self.assertEqual(resp['1122233400']['hispanic_perc'], .1)
        self.assertEqual(resp['1122233400']['non_hisp_white_only_perc'], .05)
        self.assertEqual(resp['1122233400']['non_hisp_black_only_perc'], .25)
        self.assertEqual(resp['1122233400']['non_hisp_asian_only_perc'], .2)

    def test_race_summary_csv(self):
        resp = self.client.get(reverse('censusdata:race_summary_csv'),
            {'metro':'10000', 'lender':'736-4045996', 'action_taken':'1,2,3,4'})
        resp = resp.content
        self.assertTrue('1122233300' in resp)
        self.assertTrue('1122233400' in resp)
        self.assertTrue('1122333300' in resp)




<commit_msg>Updating tests<commit_after>import json

from django.core.urlresolvers import reverse
from django.test import TestCase
from respondents.models import Institution
from geo.models import Geo
from censusdata.models import Census2010RaceStats
from hmda.models import HMDARecord, LendingStats

class ViewsTest(TestCase):
    fixtures = ['agency', 'fake_respondents', 'dummy_tracts', 'fake_msa']

    def setUp(self):
        stats = Census2010RaceStats(
            total_pop=10, hispanic=1, non_hisp_white_only=2,
            non_hisp_black_only=4, non_hisp_asian_only=5)
        stats.geoid_id = '1122233300'
        stats.save()
        stats = Census2010RaceStats(
            total_pop=20, hispanic=2, non_hisp_white_only=1,
            non_hisp_black_only=5, non_hisp_asian_only=4)
        stats.geoid_id = '1122233400'
        stats.save()
        stats = Census2010RaceStats(
            total_pop=100, hispanic=10, non_hisp_white_only=20,
            non_hisp_black_only=30, non_hisp_asian_only=4)
        stats.geoid_id = '1122333300'
        stats.save()
        stats = Census2010RaceStats(
            total_pop=100, hispanic=0, non_hisp_white_only=0,
            non_hisp_black_only=0, non_hisp_asian_only=7)
        stats.geoid_id = '1222233300'
        stats.save()
        lendstats = LendingStats(
            geo_id='10000', institution_id="736-4045996",
            lar_median=3, lar_count=4,
            fha_count=2, fha_bucket=2)
        lendstats.save()

        def mkrecord(institution_id, action_taken, countyfp, geoid):
            respondent = Institution.objects.get(institution_id=institution_id)
            geo = Geo.objects.get(geoid=geoid)
            record = HMDARecord(
                as_of_year=2014, respondent_id=respondent.respondent_id, agency_code=respondent.agency_id,
                loan_type=1, property_type=1, loan_purpose=1, owner_occupancy=1,
                loan_amount_000s=222, preapproval='1', action_taken=action_taken,
                msamd='01234', statefp='11', countyfp=countyfp,
                census_tract_number ='01234', applicant_ethnicity='1',
                co_applicant_ethnicity='1', applicant_race_1='1', co_applicant_race_1='1',
                applicant_sex='1', co_applicant_sex='1', applicant_income_000s='1000',
                purchaser_type='1', rate_spread='0123', hoepa_status='1', lien_status='1',
                sequence_number='1', population='1', minority_population='1',
                ffieic_median_family_income='1000', tract_to_msamd_income='1000',
                number_of_owner_occupied_units='1', number_of_1_to_4_family_units='1',
                application_date_indicator=1)
            record.geo = geo
            record.institution = respondent
            record.save()
        mkrecord("91000000001", 1, '222', '1122233300')
        mkrecord("91000000001", 1, '222', '1122233400')
        mkrecord("91000000001", 1, '222', '1122333300')



    def tearDown(self):
        Census2010RaceStats.objects.all().delete()


    def test_race_summary(self):
        resp = self.client.get(reverse('censusdata:race_summary'),
                               {'neLat':'1',
                                    'neLon':'1',
                                    'swLat':'0',
                                    'swLon':'0',
                                    'year':'2013',
                                    'action_taken':'1,2,3,4,5',
                                    'lender':'736-4045996'})
        resp = json.loads(resp.content)
        self.assertEqual(len(resp), 4)
        self.assertTrue('1122233300' in resp)
        self.assertEqual(resp['1122233300']['total_pop'], 10)
        self.assertEqual(resp['1122233300']['hispanic'], 1)
        self.assertEqual(resp['1122233300']['non_hisp_white_only'], 2)
        self.assertEqual(resp['1122233300']['non_hisp_black_only'], 4)
        self.assertEqual(resp['1122233300']['non_hisp_asian_only'], 5)
        self.assertEqual(resp['1122233300']['hispanic_perc'], .1)
        self.assertEqual(resp['1122233300']['non_hisp_white_only_perc'], .2)
        self.assertEqual(resp['1122233300']['non_hisp_black_only_perc'], .4)
        self.assertEqual(resp['1122233300']['non_hisp_asian_only_perc'], .5)
        self.assertTrue('1122233400' in resp)
        self.assertEqual(resp['1122233400']['total_pop'], 20)
        self.assertEqual(resp['1122233400']['hispanic'], 2)
        self.assertEqual(resp['1122233400']['non_hisp_white_only'], 1)
        self.assertEqual(resp['1122233400']['non_hisp_black_only'], 5)
        self.assertEqual(resp['1122233400']['non_hisp_asian_only'], 4)
        self.assertEqual(resp['1122233400']['hispanic_perc'], .1)
        self.assertEqual(resp['1122233400']['non_hisp_white_only_perc'], .05)
        self.assertEqual(resp['1122233400']['non_hisp_black_only_perc'], .25)
        self.assertEqual(resp['1122233400']['non_hisp_asian_only_perc'], .2)

    def test_race_summary_csv(self):
        resp = self.client.get(reverse('censusdata:race_summary_csv'),
            {'metro':'10000', 'lender':'91000000001', 'action_taken':'1,2,3,4'})
        resp = resp.content
        self.assertTrue('1122233300' in resp)
        self.assertTrue('1122233400' in resp)
        self.assertTrue('1122333300' in resp)





{'fraction_non_alphanumeric': 0.129179670084708, 'fraction_numerical': 0.10644226482389657, 'mean_word_length': 2.784479122733024, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1446815', 'n_tokens_mistral': 3552, 'n_tokens_neox': 2892, 'n_words': 377}