Esempio n. 1
0
    def test_get_single_user(self, mock_model, mock_resp):
        """
        Test single user retrieval.
        """
        request = mock.MagicMock()
        user = UserResourceView()
        response = user.get(request, 'test-user')

        mock_model.objects.get_or_404.assert_called_once_with(login='******')
        mock_resp.assert_called_once_with(mock_model.SERIALIZER.return_value.data)
        self.assertTrue(response is mock_resp.return_value)
Esempio n. 2
0
    def test_get_single_user(self, mock_model, mock_resp):
        """
        Test single user retrieval.
        """
        request = mock.MagicMock()
        user = UserResourceView()
        response = user.get(request, 'test-user')

        mock_model.objects.get_or_404.assert_called_once_with(login='******')
        mock_resp.assert_called_once_with(mock_model.serializer.return_value.data)
        self.assertTrue(response is mock_resp.return_value)
Esempio n. 3
0
    def test_get_invalid_user(self, mock_factory):
        """
        Test nonexistent user retrieval.
        """
        mock_factory.user_query_manager.return_value.find_by_login.return_value = None

        request = mock.MagicMock()
        user = UserResourceView()
        try:
            response = user.get(request, 'nonexistent_login')
        except MissingResource, response:
            pass
Esempio n. 4
0
    def test_get_invalid_user(self, mock_factory):
        """
        Test nonexistent user retrieval.
        """
        mock_factory.user_query_manager.return_value.find_by_login.return_value = None

        request = mock.MagicMock()
        user = UserResourceView()
        try:
            response = user.get(request, 'nonexistent_login')
        except MissingResource, response:
            pass
Esempio n. 5
0
    def test_get_single_user(self, mock_f, mock_resp):
        """
        Test single user retrieval.
        """
        user = {'login': '******', 'name': 'test-user', 'id': '12345'}
        mock_f.user_query_manager.return_value.find_by_login.return_value = user

        request = mock.MagicMock()
        user = UserResourceView()
        response = user.get(request, 'test-user')

        expected_cont = {'login': '******', 'name': 'test-user', '_href': '/v2/users/test-user/'}
        mock_resp.assert_called_once_with(expected_cont)
        mock_f.user_query_manager.return_value.find_by_login.assert_called_once_with('test-user')
        self.assertTrue(response is mock_resp.return_value)
Esempio n. 6
0
    def test_get_single_user(self, mock_f, mock_resp):
        """
        Test single user retrieval.
        """
        user = {'login': '******', 'name': 'test-user', 'id': '12345'}
        mock_f.user_query_manager.return_value.find_by_login.return_value = user

        request = mock.MagicMock()
        user = UserResourceView()
        response = user.get(request, 'test-user')

        expected_cont = {
            'login': '******',
            'name': 'test-user',
            '_href': '/v2/users/test-user/'
        }
        mock_resp.assert_called_once_with(expected_cont)
        mock_f.user_query_manager.return_value.find_by_login.assert_called_once_with(
            'test-user')
        self.assertTrue(response is mock_resp.return_value)