If you look at the documentation you will see that you need to manually add a user to the request. It doesn't do this for you automatically.
def change_item_test(self):
request = self.factory.get('main/views')
request.user = User.objects.create_user(username="bobalong")
Adding a user like this simulates making a logged in request. If this is NOT what you want then you should create an AnonymousUser
instead. In general the error you were getting should provide you with everything you need to know. It is explicitly telling you that the test is failing because the request doesn't have a user
. Adding a real user or adding a mock user object to the request is the answer.
Also, you seem to be testing a view that will only work with a POST request. It's going to fail because request.POST does not have the correct dictionary keys. You can create a POST request by doing
factory.post('main/views', {'name_change': 'some name'})`