Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In chapter_purist_unit_tests.asciidoc: AssertionError: <MagicMock name='List().owner' id='4522868128'> != <User: User object ([email protected])> #107

Open
hj24 opened this issue Apr 18, 2019 · 0 comments

Comments

@hj24
Copy link

hj24 commented Apr 18, 2019

My code:

def new_list(request):
	"""
	item.objects.create 是创建Item对象的简化方式无需再掉用.save()方法
	"""
	form = ItemForm(data=request.POST)
	if form.is_valid():
		list_ = List()
		print(request)
		list_.owner = request.user
		list_.save()
		form.save(for_list=list_)
		return redirect(list_)
	else:
		return render(request, 'home.html', {"form": form})
        @patch('lists.models.List')
	@patch('lists.forms.ItemForm')
	def test_list_owner_is_saved_if_user_is_authenticated(self, mockItemFormClass, mockListClass):
		user = User.objects.create(email='[email protected]')
		self.client.force_login(user)
		#print(settings.AUTHENTICATION_BACKENDS[0])
		self.client.post('/lists/new', data={'text': 'new item'})
		
		mock_list = mockListClass.return_value
		self.assertEqual(mock_list.owner, user)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant