def test_submit_request_to_office(self):
        requester_email = "*****@*****.**"
        self.assertEqual(0,
                         len(Requester.objects.filter(email=requester_email)))

        response = self.client.post("/api/request/",
                                    content_type='application/json',
                                    data=json.dumps({
                                        'agency':
                                        self.office.agency.slug,
                                        'office':
                                        self.office.office_slug,
                                        'email':
                                        requester_email,
                                        'first_name':
                                        "FOIA",
                                        'last_name':
                                        "Requester",
                                        'body':
                                        "A new request",
                                    }))

        self.assertEqual(201, response.status_code, response.content)
        data = helpers.json_from(response)
        self.assertTrue(data.get('tracking_id') is not None)
        self.assertEqual('O', data.get('status'))

        request_id = data['tracking_id']
        foia_request = FOIARequest.objects.get(pk=request_id)
        self.assertTrue(foia_request is not None)
        self.assertEqual(foia_request.office, self.office)
        self.assertEqual(1,
                         len(Requester.objects.filter(email=requester_email)))
        self.assertEqual(requester_email, foia_request.requester.email)
Esempio n. 2
0
 def test_list_query(self):
     c = Client()
     response = c.get('/api/agency/?query=industry')
     self.assertEqual(200, response.status_code)
     content = helpers.json_from(response)
     self.assertEqual(len(content['objects']), 1)
     self.assertEqual(content['objects'][0]['slug'],
                      'department-of-commerce')
Esempio n. 3
0
 def test_reading_rooms(self):
     c = Client()
     response = c.get('/api/agency/department-of-commerce/')
     self.assertEqual(200, response.status_code)
     content = helpers.json_from(response)
     self.assertEqual([{
         'link_text': 'The Electronic Reading Room',
         'url': 'http://www.doc.gov/err/'
     }], content['foia_libraries'])
Esempio n. 4
0
 def test_reading_rooms(self):
     c = Client()
     response = c.get('/api/agency/department-of-commerce/')
     self.assertEqual(200, response.status_code)
     content = helpers.json_from(response)
     self.assertEqual([{
         'link_text': 'The Electronic Reading Room',
         'url': 'http://www.doc.gov/err/'}],
         content['foia_libraries'])
Esempio n. 5
0
    def test_list_query_and_or(self):
        """
        Test that or and and work correctly
        """

        # Using `AND` returns objects that contain both words
        c = Client()
        response = c.get('/api/agency/?query=vital+AND+homeland')
        content = helpers.json_from(response)
        self.assertEqual(len(content['objects']), 1)
        self.assertEqual(content['objects'][0]['slug'],
                         'department-of-homeland-security')

        # Using `OR` returns objects that contain at least one of the words
        c = Client()
        response = c.get('/api/agency/?query=patents+OR+technological')
        content = helpers.json_from(response)
        self.assertEqual(len(content['objects']), 2)
Esempio n. 6
0
    def test_list_query_postgres(self):
        """ Test that search works when backend is postgresql_psycopg2 """

        c = Client()
        response = c.get('/api/agency/?query=emergency')
        self.assertEqual(200, response.status_code)
        content = helpers.json_from(response)
        self.assertEqual(len(content['objects']), 1)
        self.assertEqual(content['objects'][0]['slug'],
                         'department-of-homeland-security')
Esempio n. 7
0
    def test_list_query_order_and_fields(self):
        """
        Test that non-exact queries work and with multiple fields.
        """

        c = Client()
        # Test that search works with words not in order in title
        response = c.get('/api/agency/?query=cybersecurity+chemical')
        content = helpers.json_from(response)
        self.assertEqual(len(content['objects']), 1)
        self.assertEqual(content['objects'][0]['slug'],
                         'department-of-homeland-security')

        # Test that search works with words not in order in description
        response = c.get('/api/agency/?query=Security+Homeland')
        content = helpers.json_from(response)
        self.assertEqual(len(content['objects']), 1)
        self.assertEqual(content['objects'][0]['slug'],
                         'department-of-homeland-security')

        # Test that search works with abbeviations
        response = c.get('/api/agency/?query=dhs')
        content = helpers.json_from(response)
        self.assertEqual(len(content['objects']), 1)
        self.assertEqual(content['objects'][0]['slug'],
                         'department-of-homeland-security')

        # Test that search works with slugs
        response = c.get('/api/agency/?query=department-of-homeland-security')
        content = helpers.json_from(response)
        self.assertEqual(len(content['objects']), 1)
        self.assertEqual(content['objects'][0]['slug'],
                         'department-of-homeland-security')

        # Test that search works with keywords
        response = c.get('/api/agency/?query=forests')
        content = helpers.json_from(response)
        self.assertEqual(len(content['objects']), 1)
        self.assertEqual(content['objects'][0]['slug'],
                         'department-of-commerce')
Esempio n. 8
0
 def test_reading_room(self):
     """ Check that the detail view for an agency has the reading room
     links"""
     c = Client()
     slug = 'department-of-homeland-security'
     slug += '--federal-emergency-management-agency/'
     response = c.get('/api/office/%s' % slug)
     self.assertEqual(200, response.status_code)
     content = helpers.json_from(response)
     self.assertEqual([{
         'link_text': 'The Electronic Reading Room',
         'url': 'http://www.usmint.gov/FOIA/?action=room'
     }], content['foia_libraries'])
Esempio n. 9
0
    def test_detail_components(self):
        """ Ensure the detail view for an agency includes the components. """

        c = Client()
        response = c.get('/api/agency/department-of-commerce/')
        self.assertEqual(200, response.status_code)
        content = helpers.json_from(response)
        self.assertEqual(content['name'], 'Department of Commerce')
        self.assertEqual(2, len(content['offices']))
        self.assertEqual(content['offices'][0]['slug'],
                         'department-of-commerce--census-bureau')
        self.assertEqual(content['offices'][1]['slug'],
                         'us-patent-and-trademark-office')
Esempio n. 10
0
 def test_reading_room(self):
     """ Check that the detail view for an agency has the reading room
     links"""
     c = Client()
     slug = 'department-of-homeland-security'
     slug += '--federal-emergency-management-agency/'
     response = c.get('/api/office/%s' % slug)
     self.assertEqual(200, response.status_code)
     content = helpers.json_from(response)
     self.assertEqual([{
         'link_text': 'The Electronic Reading Room',
         'url': 'http://www.usmint.gov/FOIA/?action=room'}],
         content['foia_libraries'])
Esempio n. 11
0
    def test_detail_components(self):
        """ Ensure the detail view for an agency includes the components. """

        c = Client()
        response = c.get('/api/agency/department-of-commerce/')
        self.assertEqual(200, response.status_code)
        content = helpers.json_from(response)
        self.assertEqual(content['name'], 'Department of Commerce')
        self.assertEqual(2, len(content['offices']))
        self.assertEqual(
            content['offices'][0]['slug'],
            'department-of-commerce--census-bureau')
        self.assertEqual(
            content['offices'][1]['slug'],
            'us-patent-and-trademark-office')
Esempio n. 12
0
    def test_list_query_weighting(self):
        """
        Test that search returns results with query in title first rather
        than alphabetically
        """
        c = Client()
        response = c.get('/api/agency/?query=trademark')
        content = helpers.json_from(response)

        # Any results with `trademark` are returned
        self.assertEqual(len(content['objects']), 3)
        # But results with `trademark` in name are first
        self.assertEqual(content['objects'][0]['slug'],
                         'us-patent-and-trademark-office')
        # And results with `trademark` in the keywords returned last
        self.assertEqual(content['objects'][2]['slug'],
                         'department-of-homeland-security')