def test_auth(self):
    client = RequestsClient()
    response = client.get('http://testserver/auth/')
    assert (response.status_code == 200)
    assert (response.headers['Content-Type'] == 'application/json')
    expected = {'username': None}
    assert (response.json() == expected)
    assert ('csrftoken' in response.cookies)
    csrftoken = response.cookies['csrftoken']
    user = User.objects.create(username='tom')
    user.set_password('password')
    user.save()
    response = client.post('http://testserver/auth/', json={'username': 'tom', 'password': 'password'}, headers={'X-CSRFToken': csrftoken})
    assert (response.status_code == 200)
    assert (response.headers['Content-Type'] == 'application/json')
    expected = {'username': 'tom'}
    assert (response.json() == expected)
    response = client.get('http://testserver/auth/')
    assert (response.status_code == 200)
    assert (response.headers['Content-Type'] == 'application/json')
    expected = {'username': 'tom'}
    assert (response.json() == expected)
def test_auth(self):
    client = RequestsClient()
    response = client.get('http://testserver/auth/')
    assert (response.status_code == 200)
    assert (response.headers['Content-Type'] == 'application/json')
    expected = {'username': None}
    assert (response.json() == expected)
    assert ('csrftoken' in response.cookies)
    csrftoken = response.cookies['csrftoken']
    user = User.objects.create(username='tom')
    user.set_password('password')
    user.save()
    response = client.post('http://testserver/auth/', json={'username': 'tom', 'password': 'password'}, headers={'X-CSRFToken': csrftoken})
    assert (response.status_code == 200)
    assert (response.headers['Content-Type'] == 'application/json')
    expected = {'username': 'tom'}
    assert (response.json() == expected)
    response = client.get('http://testserver/auth/')
    assert (response.status_code == 200)
    assert (response.headers['Content-Type'] == 'application/json')
    expected = {'username': 'tom'}
    assert (response.json() == expected)