Ejemplo n.º 1
0
    def test_add_user_calls_create_user_and_returns_username(self, mock_user_class):
        mock_user_class.objects.create_user.return_value = MagicMock(username='******')

        actual = add_user(username='******', password='******')
        expected = 'joe'

        mock_user_class.objects.create_user.assert_called_with(username='******', password='******')
        self.assertEquals(actual, expected)
Ejemplo n.º 2
0
def users(request):
    if request.method == 'GET':
        username = request.GET.get('username', None)
        if username:
            response = get_users(username=username)
        else:
            response = []
        return HttpResponse(dumps(response))
    elif request.method == 'POST':
        username = _get_post_param(param='username', request=request)
        password = _get_post_param(param='password', request=request)
        response = add_user(username=username, password=password)
        return HttpResponse(dumps(response))