예제 #1
0
    def test_query_update_DATA(self):
        """
        :Summary: Test QueryRetrieveUpdateDeleteView View (i.e Update Query View) by providing JSON data.
        """
        hash = create_hash()
        query = Query.objects.create(hash_code=hash, file=False)
        for i in create_data['users']:
            i['query'] = query
            QueryUser.objects.create(**i)

        # Update the Query
        client = APIClient()
        url = update_url.replace('<hash>', query.hash_code)
        response = client.patch(url, update_data, format='json')

        # Check the response code
        self.assertEqual(response.status_code, 303)

        # Check the redirect location
        self.assertEqual(response.has_header('location'), True)

        # Check the value of redirect location
        headers = response.serialize_headers().decode().split(
            'location: ')[1].split('\r\n')[0]
        self.assertEqual(headers, '/result/' + query.hash_code + '/')
예제 #2
0
    def test_query_update_CSV(self):
        """
        :Summary: Test QueryRetrieveUpdateDeleteView View (i.e Update Query View) by providing data through CSV file.
        """
        hash = create_hash()
        query = Query.objects.create(hash_code=hash, file=False)
        for i in create_data['users']:
            i['query'] = query
            QueryUser.objects.create(**i)

        # Update the Query with csv file
        client = APIClient()
        url = update_url.replace('<hash>', query.hash_code)
        update_data = create_csv
        with open('test_data/test_csv_update.csv') as fp:
            update_data['csv_file'] = fp
            response = client.patch(url, update_data)

        # Check the response code
        self.assertEqual(response.status_code, 303)

        # Check the redirect location
        self.assertEqual(response.has_header('location'), True)

        # Check the value of redirect location
        headers = response.serialize_headers().decode().split(
            'location: ')[1].split('\r\n')[0]
        self.assertEqual(headers, '/result/' + query.hash_code + '/')

        path = 'uploads/' + query.hash_code + ".csv"
        remove(path)