コード例 #1
0
 def setUp(self):
     CompanyModel.objects.create(name="test1",
                                 sector="abc",
                                 website="abc",
                                 about="abc")
     self.job_structure = {
         "recruiter": 1,
         "company": "1",
         "job_title": "SR Manager",
         "job_type": "FT",
         "job_qualification": "MBA Passout",
         "job_location": "Mumbai",
         "salary_range_min": None,
         "salary_range_max": None,
         "work_experience_min": None,
         "work_experience_max": None,
         "no_of_opening": None,
         "job_description": "Manager"
     }
     self.user_structure = {
         "first_name": "Aayush",
         "last_name": "Sinha",
         "email_id": "*****@*****.**",
         "phone_number": "9876543210",
         "password": "******",
         "type": "recruiter",
         "company": "1",  # Company ID
         "pan": "123"
     }
     User.createUser(self.user_structure)
     Job.add_job(self.job_structure)
コード例 #2
0
 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)
コード例 #3
0
def start_process(request):
    try:

        token = Token(request)
        username = token.get_username()

        _user = User(username)

        _data = json.loads(request.body.decode())
        _data = _data["vm_id"]

        _tracking = Tracking(_user, _data)

        _res = _tracking.check_system()
        if _res != SUCCESS:
            return HttpResponseBadRequest(json.dumps({"message": _res}),
                                          content_type='application/json')

        t1 = threading.Thread(target=_tracking.start)
        t1.start()
        _tracking.create_vm_pool()
        return HttpResponse(json.dumps({
            "message": "started",
            "pool_id": _tracking.pool_id
        }),
                            content_type='application/json')

    except Exception as e:
        return HttpResponseServerError(json.dumps({"message": str(e)}),
                                       content_type='application/json')
コード例 #4
0
ファイル: register.py プロジェクト: aayushsinha44/JobBuddy
def register(request):

    if request.method == 'POST':
        try:
            print(request.body.decode())
            user_structure = json.loads(request.body.decode())

            res = User.createUser(user_structure)

            if res == USER_ADDED_SUCCESS:

                token = create_token(user_structure["email_id"],
                                     user_structure["type"])

                return HttpResponse(json.dumps({
                    "message": "user successfully added",
                    "token": token
                }),
                                    content_type='application/json')

            else:
                print(res)
                return HttpResponseBadRequest(json.dumps({"message": res}),
                                              content_type='application/json')

        except Exception as e:
            print(str(e))
            return HttpResponseServerError(json.dumps({'message': str(e)}),
                                           content_type='application/json')

    else:
        return HttpResponseBadRequest(json.dumps(
            {"message": "only post method"}),
                                      content_type='application/json')
コード例 #5
0
ファイル: views.py プロジェクト: aayushsinha44/a2c
def agent_ip(request):

    try:

        if request.method == 'GET':
            token = Token(request)
            username = token.get_username()

            _user = User(username)
            _agent = Agent(_user)

            res = _agent.get_agent_cred()

            if res == DOESNOT_EXISTS:
                return HttpResponseBadRequest(json.dumps({"message": res}),
                                              content_type='application/json')

            return HttpResponse(json.dumps({"message": res}),
                                content_type='application/json')

        elif request.method == 'POST' or request.method == 'PUT':
            token = Token(request)
            username = token.get_username()

            _user = User(username)
            _agent = Agent(_user)

            data_structure = json.loads(request.body.decode())

            if "agent_ip" not in data_structure:
                return HttpResponseBadRequest(json.dumps(
                    {"message": "vm_ip not in json body"}),
                                              content_type='application/json')

            res = _agent.add_agent_cred(data_structure["agent_ip"])

            return HttpResponse(json.dumps({"message": res}),
                                content_type='application/json')

        else:
            return HttpResponseBadRequest(json.dumps(
                {"message": "invalid request method"}),
                                          content_type='application/json')

    except Exception as e:
        return HttpResponseServerError(json.dumps({"message": str(e)}),
                                       content_type='application/json')
コード例 #6
0
ファイル: Token.py プロジェクト: aayushsinha44/JobBuddy
def create_token(data, user_type):
    if not User.check_user(user_type):
        return INVALID_USER_TYPE
    token = jwt.encode(
        {
            'data': data,
            'date': str(date.today()),
            'type': user_type
        },
        'asfjoew@23r8wjfosdfn',
        algorithm='HS256')
    token = token.decode()
    return token
コード例 #7
0
ファイル: login.py プロジェクト: aayushsinha44/JobBuddy
def login(request):

    if request.method == 'POST':

        try:

            res = json.loads(request.body.decode())

            data = User.check_user(res)

            if data == USER_EXISTS:

                if "phone_number" in res:
                    data = User.get_id_from_phone_number(
                        res["phone_number"], res["type"])
                else:
                    data = User.get_id_from_email(res["email_id"], res["type"])

                token = create_token(data, res["type"])

                return HttpResponse(json.dumps({
                    "status": "success",
                    "token": token
                }),
                                    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": "only post method"}),
                                      content_type='application/json')
コード例 #8
0
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')
コード例 #9
0
def track(request, pool_id=None):
    try:

        if pool_id is None:
            return HttpResponseBadRequest(json.dumps({"message":
                                                      "id not set"}),
                                          content_type='application/json')

        token = Token(request)
        username = token.get_username()

        _user = User(username)

        _track = Track(_user, pool_id)

        return HttpResponse(json.dumps({"data": _track.get_info()}),
                            content_type='application/json')

    except Exception as e:
        return HttpResponseServerError(json.dumps({"message": str(e)}),
                                       content_type='application/json')
コード例 #10
0
def get_services(request):
    try:

        token = Token(request)
        username = token.get_username()

        _user = User(username)

        _tracking = Tracking(_user, [])

        _res = _tracking.check_system()
        if _res != SUCCESS:
            return HttpResponseBadRequest(json.dumps({"message": _res}),
                                          content_type='application/json')

        return HttpResponse(json.dumps({
            "message": _tracking.get_services(),
        }),
                            content_type='application/json')

    except Exception as e:
        return HttpResponseServerError(json.dumps({"message": str(e)}),
                                       content_type='application/json')
コード例 #11
0
ファイル: auth.py プロジェクト: aayushsinha44/a2c
def login(request):
    try:
        
        if request.method=='POST':
            
            user_structure = json.loads(request.body.decode())

            if "username" not in user_structure or "password" not in user_structure:
                return HttpResponseBadRequest(json.dumps({
                    "message": "invalid data format"
                }), content_type='application/json')

            res = User.check_user(user_structure["username"],
                                user_structure["password"])

            if res==True:
                token = create_token(user_structure["username"])

                return HttpResponse(json.dumps({
                    "token": token
                }), content_type='application/json')

            else:
                return HttpResponseBadRequest(json.dumps({
                    "message": "user doesnot exists"
                }), content_type='application/json')
        else:
            return HttpResponseBadRequest(json.dumps({
                "message": "only post method"
            }), content_type='application/json')
        

    except Exception as e:
        print(e)
        return HttpResponseServerError(json.dumps({
                'message': str(e)
            }), content_type='application/json')
コード例 #12
0
ファイル: cred.py プロジェクト: aayushsinha44/a2c
def kube_cred(request):

    try:

        if request.method == 'GET':
            token = Token(request)
            username = token.get_username()

            _user = User(username)

            res = _user.get_kubernetes_cred()

            if res == DOESNOT_EXISTS:
                return HttpResponseBadRequest(json.dumps({"message": res}),
                                              content_type='application/json')

            else:
                return HttpResponse(json.dumps({"message": res}),
                                    content_type='application/json')

        else:

            token = Token(request)
            username = token.get_username()

            _user = User(username)

            _structure = json.loads(request.body.decode())

            res = _user.add_kubernetes_cred(_structure)

            if res == ADDED_SUCCESS or res == UPDATE_SUCESS:
                return HttpResponse(json.dumps({"message": res}),
                                    content_type='application/json')

            else:
                return HttpResponseBadRequest(json.dumps({"message": res}),
                                              content_type='application/json')

    except Exception as e:
        return HttpResponseServerError(json.dumps({'message': str(e)}),
                                       content_type='application/json')
コード例 #13
0
ファイル: views.py プロジェクト: aayushsinha44/a2c
def vm_cred(request, id=None):

    try:

        token = Token(request)
        username = token.get_username()

        _user = User(username)
        _vm = VM(_user)

        if id == "":
            id = None

        if request.method == 'GET':

            if id is None:
                res = _vm.get_all_vm_cred()

                return HttpResponse(json.dumps({"data": res}),
                                    content_type='application/json')

            res = _vm.get_vm_cred(id)

            return HttpResponse(json.dumps({"data": res}),
                                content_type='application/json')

        elif request.method == 'POST':

            data_structure = json.loads(request.body.decode())
            res = _vm.add_vm_cred(data_structure)

            if res == INVALID_ACCESS or res == INVALID_PARAMETER_STRUCTURE:
                return HttpResponseBadRequest(json.dumps({"message": res}),
                                              content_type='application/json')

            return HttpResponse(json.dumps({"message": res}),
                                content_type='application/json')

        elif request.method == 'PUT':

            if id is None:
                return HttpResponseBadRequest(json.dumps(
                    {"message": "invalid method"}),
                                              content_type='application/json')

            data_structure = json.loads(request.body.decode())
            res = _vm.update_vm_cred(id, data_structure)
            if res == INVALID_ACCESS or res == INVALID_PARAMETER_STRUCTURE:
                return HttpResponseBadRequest(json.dumps({"message": res}),
                                              content_type='application/json')

            return HttpResponse(json.dumps({"message": res}),
                                content_type='application/json')

        elif request.method == 'DELETE':

            if id is None:
                return HttpResponseBadRequest(json.dumps(
                    {"message": "invalid method"}),
                                              content_type='application/json')
            res = _vm.delete_vm(id)
            return HttpResponse(json.dumps({"message": res}),
                                content_type='application/json')

        else:
            return HttpResponseBadRequest(json.dumps(
                {"message": "invalid request method"}),
                                          content_type='application/json')

    except Exception as e:

        return HttpResponseServerError(json.dumps({"message": str(e)}),
                                       content_type='application/json')
コード例 #14
0
 def test_recruiter(self):
     res = User.createUser(self.user_structure)
     self.assertEqual(res, USER_ADDED_SUCCESS)
コード例 #15
0
 def test_candidate(self):
     res = User.createUser(self.user_structure_candidate)
     self.assertEqual(res, USER_ADDED_SUCCESS)