import base64
from django.test import TestCase


class TestMyStuff(TestCase):

    def setUp(self):
        credentials = base64.b64encode('username:password')
self.client.defaults['HTTP_AUTHORIZATION'] = 'Basic ' + credentials
Using Basic HTTP access authentication in Django testing framework