def test_recruiter(self): res = User.createUser(self.user_structure) self.assertEqual(res, USER_ADDED_SUCCESS) user_object = User(1, self.user_structure["type"]) self.user_structure["cv"] = 'abc' self.user_structure["user_id"] = 1 del self.user_structure["password"] res = user_object.update_details(self.user_structure) self.assertEqual(res, USER_UPDATE_SUCCESS)
def profile(request): if request.method == 'GET': try: token = Token(request) user_id = token.get_user_id() user_type = token.get_user_type() user = User(user_id=user_id, user_type=user_type) response = user.get_details() return HttpResponse(json.dumps({"data": response}), content_type='application/json') except Exception as e: return HttpResponseServerError(json.dumps({'message': str(e)}), content_type='application/json') elif request.method == 'PUT': try: token = Token(request) user_id = token.get_user_id() user_type = token.get_user_type() res = json.loads(request.body.decode()) user = User(user_id=user_id, user_type=user_type) data = User.update_details(res) if data == USER_UPDATE_SUCCESS: return HttpResponse(json.dumps({'message': data}), content_type='application/json') else: return HttpResponseBadRequest(json.dumps({'message': data}), content_type='application/json') except Exception as e: return HttpResponseServerError(json.dumps({'message': str(e)}), content_type='application/json') else: return HttpResponseBadRequest(json.dumps( {"message": "invalid request type"}), content_type='application/json')