lundi 28 décembre 2015

Unit-tests for module on Python

can somebody help with writing unit-test for this module? I just started learning unit tests and I can not deal with this module

def login(request): try: creds = simplejson.loads(request.body) username = creds.get('username', '') password = creds.get('password', '')

       user = auth.authenticate(username=username, password=password)
        if user:
            if user.is_active:
                response = make_user_logged_response(user)

                auth.login(request, user)
                LoginAttempt.handle_successful_login(user, get_ip(request))

                return response
            else:
                return response_json({
                    'success': False,
                    'reason': 'disabled',
                }, cls=HttpResponseForbidden )
        else:
            try:
                user = User.objects.get(username=username)
                LoginAttempt.handle_unsuccessful_login(user, get_ip(request))
            except User.DoesNotExist:
                pass

            return response_json({
                'success': False,
                'reason': 'incorrect',
            }, status_code=401)

    except Exception, e:
        logger.exception(e)
        return error_json("ERROR")

Aucun commentaire:

Enregistrer un commentaire