예제 #1
0
파일: test_views.py 프로젝트: vfulco/MyJobs
    def test_filter_by_state(self):
        """Tests that filtering by state works."""

        indiana = LocationFactory(state="IN")
        ContactFactory.create_batch(10, name="Jen Doe", partner=self.partner, locations=[indiana])

        self.client.path += "/contact"
        response = self.client.get(data={"state": "IN"})
        output = json.loads(response.content)

        self.assertEqual(len(output), 10)
예제 #2
0
파일: test_views.py 프로젝트: vfulco/MyJobs
    def test_filter_by_city(self):
        """Tests that filtering by city works."""

        indianapolis = LocationFactory(city="Indianapolis")
        ContactFactory.create_batch(10, name="Jen Doe", partner=self.partner, locations=[indianapolis])

        self.client.path += "/contact"
        response = self.client.get(data={"city": "indianapolis"})
        output = json.loads(response.content)

        self.assertEqual(len(output), 10)
예제 #3
0
파일: test_views.py 프로젝트: vfulco/MyJobs
    def test_filtering_on_contact(self):
        """Test the ability to filter by contact."""

        ContactFactory.create_batch(10, name="Jen Doe", partner=self.partner)

        # contacts with the wrong name
        ContactFactory.create_batch(10, name="Jen Smith", partner=self.partner)

        self.client.path += "/contact"
        response = self.client.get(data={"name": "Jen Doe"})
        output = json.loads(response.content)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(output), 10)
예제 #4
0
    def test_contact_record_counts_vs_list(self):
        """
        ContactRecord counts for Communication Records and Referals
        should match summed counts from contacts.
        """
        contacts = ContactFactory.create_batch(4)
        contacts[0].name = 'Other name'
        contacts[1].email = '*****@*****.**'
        contacts[2].partner = PartnerFactory(name='Other Partner')
        for contact in contacts:
            ContactRecordFactory.create(contact_type="job",
                                        contact=contact,
                                        partner=contact.partner)
            ContactRecordFactory.create(contact_type='email',
                                        contact=contact,
                                        partner=contact.partner)

        contacts[0].email = '*****@*****.**'
        ContactRecordFactory.create(contact_type='email',
                                    contact=contacts[0],
                                    partner=contact.partner)

        queryset = ContactRecord.objects.all()
        self.assertEqual(queryset.count(), 9)

        contacts = list(queryset.contacts)
        sum_referrals = sum([contact['referrals'] for contact in contacts])
        sum_records = sum([contact['records'] for contact in contacts])
        self.assertEqual(sum_referrals, queryset.referrals)
        self.assertEqual(sum_records, queryset.communication_activity.count())
예제 #5
0
    def test_contact_record_counts_vs_list(self):
        """
        ContactRecord counts for Communication Records and Referals
        should match summed counts from contacts.
        """
        contacts = ContactFactory.create_batch(4)
        contacts[0].name = 'Other name'
        contacts[1].email = '*****@*****.**'
        contacts[2].partner = PartnerFactory(name='Other Partner')
        for contact in contacts:
            ContactRecordFactory.create(contact_type="job",
                                        contact=contact,
                                        partner=contact.partner)
            ContactRecordFactory.create(contact_type = 'email',
                                        contact=contact,
                                        partner=contact.partner)

        contacts[0].email = '*****@*****.**'
        ContactRecordFactory.create(contact_type = 'email',
                                    contact=contacts[0],
                                    partner=contact.partner)


        queryset = ContactRecord.objects.all()
        self.assertEqual(queryset.count(), 9)

        contacts = list(queryset.contacts)
        sum_referrals = sum([contact['referrals'] for contact in contacts])
        sum_records = sum([contact['records'] for contact in contacts])
        self.assertEqual(sum_referrals, queryset.referrals)
        self.assertEqual(sum_records, queryset.communication_activity.count())
예제 #6
0
파일: test_views.py 프로젝트: vfulco/MyJobs
    def test_list_query_params(self):
        """Test that query parameters that are lists are parsed correctly."""

        contacts = ContactFactory.create_batch(10, partner__owner=self.company)
        pks = [contact.pk for contact in contacts[:5]]

        self.client.path += "/partner"
        response = self.client.get(data={"contact": pks})
        output = json.loads(response.content)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(output), 5)
예제 #7
0
    def test_list_query_params(self):
        """Test that query parameters that are lists are parsed correctly."""

        contacts = ContactFactory.create_batch(10, partner__owner=self.company)
        pks = [contact.pk for contact in contacts[:5]]

        self.client.path += '/partner'
        filters = json.dumps({'contact': {'in': pks}})
        response = self.client.post(data={'filters': filters})
        output = json.loads(response.content)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(output), 5)
예제 #8
0
    def test_contact_locations(self):
        """
        Test that `get_contact_locations` returns a properly formatted string.
        """
        ny = LocationFactory.create_batch(2, city="Albany", state="NY")
        il = LocationFactory.create(city="Chicago", state="IL")
        mo = LocationFactory.create(city="St. Louis", state="MO")

        contacts = ContactFactory.create_batch(4, partner=self.partner)
        for contact, location in zip(contacts, ny + [il, mo]):
            contact.locations.add(location)

        self.assertEqual("Chicago, IL; St. Louis, MO; Albany, NY",
                         "; ".join(self.partner.get_contact_locations()))
예제 #9
0
    def test_contact_locations(self):
        """
        Test that `get_contact_locations` returns a properly formatted string.
        """
        ny = LocationFactory.create_batch(2, city="Albany", state="NY")
        il = LocationFactory.create(city="Chicago", state="IL")
        mo = LocationFactory.create(city="St. Louis", state="MO")

        contacts = ContactFactory.create_batch(4, partner=self.partner)
        for contact, location in zip(contacts, ny + [il, mo]):
            contact.locations.add(location)

        self.assertEqual("Chicago, IL; St. Louis, MO; Albany, NY", 
                         "; ".join(self.partner.get_contact_locations()))