def test__get_request_user_no_reviewer(self, mock_req): user = factories.UserFactory(username='******', reviewer=None) mock_req.user = user s = ReviewSerializer(context={'request': mock_req}) with self.assertRaises(ValidationError): s._get_request_user()
def test__get_request_user_anon_user(self, mock_req): # set the property, then reset when done user = factories.UserFactory(username='******', reviewer=None) type(user).is_anonymous = mock.PropertyMock(return_value=True) mock_req.user = user s = ReviewSerializer(context={'request': mock_req}) with self.assertRaises(ValidationError): s._get_request_user() type(user).is_anonymous = mock.PropertyMock(return_value=False)
def test__get_request_user_known_user(self, mock_req): user = factories.UserFactory(username='******') reviewer = user.reviewer mock_req.user = user s = ReviewSerializer(context={'request': mock_req}) expected_ret = reviewer ret = s._get_request_user() self.assertEqual(ret, expected_ret)