Пример #1
0
 def test_get_data(self):
     """
     Test get data from a list given by top_n_in_order()(top_n_in_order() should be test before this test). Expect output to match correct data.
     """
     e1 = Experience(rid=1, uid=3, experience=1000)
     e2 = Experience(rid=1, uid=1, experience=5000)
     u1 = User(uid=3, name="Joe", password="******", email="*****@*****.**", type=-1)
     u2 = User(uid=1, name="Bob", password="******", email="*****@*****.**", type=-1)
     db.session.add(e1)
     db.session.add(e2)
     db.session.add(u1)
     db.session.add(u2)
     db.session.commit()
     list = top_n_in_order(1, 5)
     data = get_data(list)
     self.assertEqual([{"username": "******",
                        "exp": 5000,
                        "level": 9,
                        "rank": 1,
                        "uid": 1},
                       {"username": "******",
                        "exp": 1000,
                        "level": 4,
                        "rank": 2,
                        "uid": 3}], data)
Пример #2
0
 def test_sort_fewer_than_n(self):
     """
     Test get a list of top N user in order with actual number of user is less than N, which is valid. Expect output to match correct data without any issues.
     """
     e1 = Experience(rid=1, uid=3, experience=100)
     e2 = Experience(rid=1, uid=1, experience=89)
     e3 = Experience(rid=1, uid=12, experience=1343)
     db.session.add(e1)
     db.session.add(e2)
     db.session.add(e3)
     db.session.commit()
     list = top_n_in_order(1, 5)
     self.assertEqual([(12, 1343), (3, 100), (1, 89)], list)
def insert_experience(uid, rid):
    """
    Inserts a 0 experience entry into experience table for a given user and restaurant.

    Args:
        uid: A user ID that corresponds to a user in the User
          table. A integer.
        rid: A restaurant ID that corresponds to a restaurant in the Restaurant
          table. A integer.

    Returns:
        experience if entry was successfully added to the experience table, a list of
        error messages otherwise.
    """
    errmsg = []

    experience = Experience.query.filter(Experience.uid == uid).filter(
        Experience.rid == rid).first()
    if experience:
        errmsg.append(
            "Experience entry already exists for given user at this restaurant."
        )

    if not errmsg:
        experience = Experience(uid=uid, rid=rid, experience=0)
        db.session.add(experience)
        db.session.commit()
        return None
    return errmsg
Пример #4
0
def workexperiences(nuid, **kwargs):
    student = studentsData[nuid -
                           1]  # Search by index instead of search by prime key
    experiences = find_experiences_by_student(student)

    if request.method == 'GET':
        response = jsonify(
            [experience.serialize() for experience in experiences])
        response.status_code = 200

    else:
        params = request.get_json()
        experience = Experience(
            3,  # It should be auto-generated by database, just take an example here
            params['companyname'],
            params['title'],
            params['startdate'],
            params['enddate'],
            params['description'])
        experiences.append(experience)  # Add a new row in Experience table

        response = jsonify({"Message": "Success"})
        response.status_code = 200
        # Print new data in console
        print(experience)
    return response
Пример #5
0
    def test_insert_duplicate_uid_and_rid_experience_entry(self):
        '''
        Tests inserting an entry into the experience table while an entry with
        the same uid and same rid already exists in the table. Expect an error message and data in database remains the same.
        '''
        experience = Experience(uid=1, rid=12, experience=10)
        db.session.add(experience)
        errmsg = experiencehelper.insert_experience(1, 12)
        self.assertEqual(errmsg, [
            "Experience entry already exists for given user at this restaurant."
        ])

        experience = Experience.query.filter_by(uid=1, rid=12)
        self.assertEqual(experience.count(), 1)
        self.assertEqual(experience.first().uid, 1)
        self.assertEqual(experience.first().rid, 12)
        self.assertEqual(experience.first().experience, 10)
Пример #6
0
def replace_experience_with_json(cv: User, json_data: dict) -> None:
    cv.experience = [
        Experience(
            company=json_exp['company'],
            project=json_exp['project'],
            duration=json_exp['duration']
        ) for json_exp in json_data.get('experience', [])
    ]
Пример #7
0
def create_new_table(current_user):
    create_table = Experience(author=current_user,
                              level=1,
                              xp=0.0,
                              username=current_user.username,
                              total_xp=0.0)
    db.session.add(create_table)
    db.session.commit()
Пример #8
0
 def committee_experience_leave(self, *args):
     committee_key = args[0]
     committee = db.get(committee_key)
     member = self.current_member()
     experience = Experience.get_experience(member, committee)
     if experience:
         experience.delete()
         time.sleep(2)
     return self.committee_experience_part(*args)
Пример #9
0
 def committee_experience_join(self, *args):
     committee_key = args[0]
     committee = db.get(committee_key)
     role_key = args[1]
     role = db.get(role_key)
     department = args[2]
     member = self.current_member()
     experience = Experience.get_experience(
         member, committee) or Experience(
             key_name="{0} {1}".format(committee.name(), member.id))
     experience.committee = committee.key()
     experience.role = role.key()
     experience.approved = False
     experience.department = department
     experience.member = member.key()
     experience.put()
     time.sleep(2)
     return self.committee_experience_part(*args)
 def test_get_nonexistent_experience_entry(self):
     '''
     Tests trying to select an entry that does not exist from the experience table. Expect return none.
     '''
     newEntry = Experience(uid=1, rid=13, experience=10)
     db.session.add(newEntry)
     db.session.commit()
     experience = experiencehelper.get_experience(2, 12)
     self.assertEqual(experience, None)
 def test_get_nonexistent_experience_entry_duplicate_rid(self):
     '''
     Tests trying to select an entry that does not exist from the experience table,
     while an entry with the same rid and different uid does exist in the table. Expect return none.
     '''
     newEntry = Experience(uid=1, rid=13, experience=10)
     db.session.add(newEntry)
     db.session.commit()
     experience = experiencehelper.get_experience(2, 13)
     self.assertEqual(experience, None)
Пример #12
0
def dash():
    if request.method == 'POST':
        #take data from form and put into database
        #TODO(rushiagr): do session expire check here
        user_personal_info = UserPersonalInfo(
            email=session.get('userEmail'),
            name=request.form.get('name'),
            title=request.form.get('position'),
            location=request.form.get('location'),
            summary=request.form.get('summary'),
        )
        user_personal_info.put()
        experience = Experience(
            email=session.get('userEmail'),
            position=request.form.get('experience_role'),
            description=request.form.get('experience_description'),
        )
        experience.put()
        projects = Projects(
            email=session.get('userEmail'),
            project_name=request.form.get('project_name'),
            description=request.form.get('project_description'),
        )
        projects.put()
        education = Education(
            email=session.get('userEmail'),
            duration=request.form.get('education_duration'),
            program=request.form.get('education_program'),
            institution=request.form.get('education_institution'),
            score_achieved=request.form.get('education_score'),
            score_out_of='10',
        )
        education.put()
        return render_template('profile.html',
                               session_user=session.get('userEmail'),
                               user_personal_info=user_personal_info,
                               experience=experience,
                               projects=projects,
                               education=education)
        
    elif request.method == 'GET':
        return render_template('edit_profile.html', session_user=session.get('userEmail'))
 def test_update_nonexistent_experience_entry(self):
     '''
     Tests trying to update an entry that does not exist in the experience table. Expect an error message.
     '''
     experience = Experience(uid=1, rid=13, experience=10)
     db.session.add(experience)
     db.session.commit()
     errmsg = experiencehelper.update_experience(1, 12, 10)
     self.assertEqual(errmsg, [
         "Experience entry does not exist for the given user ID and restaurant ID."
     ])
Пример #14
0
    def get(self):
        args = request.args

        if 'id' in args:
            return me_obj_to_serializable(
                Experience.objects.get(id=args['id']))
        elif 'user' in args:
            return me_obj_to_serializable(
                Experience.objects(user=args['user']))
        else:
            return me_obj_to_serializable(Experience.objects)
Пример #15
0
 def committee_experience_part(self, *args):
     committee_key = args[0]
     committee = db.get(committee_key)
     member = self.current_member()
     experience = Experience.get_experience(member, committee)
     param = self.render_parameters()
     param["committee"] = committee
     param["role_list"] = Role.all()
     param["experience"] = experience
     if experience and experience.approved:
         param["pending_list"] = experience.pending_list()
     return self.render("committee_experience_part", param)
 def test_get_existing_experience_entry(self):
     '''
     Tests selecting a normal entry with no issues from the the experience table. Expect output to match correct data.
     '''
     newEntry = Experience(uid=1, rid=12, experience=10)
     db.session.add(newEntry)
     db.session.commit()
     experience = experiencehelper.get_experience(1, 12)
     self.assertNotEqual(experience, None)
     self.assertEqual(experience.uid, 1)
     self.assertEqual(experience.rid, 12)
     self.assertEqual(experience.experience, 10)
Пример #17
0
 def post(self):
     if self.request.get('committee_key'):
         committee = db.get(self.request.get('committee_key'))
         if self.request.get('action') == "join":
             xp = Experience()
             xp.member = self.current_member()
             xp.committee = committee
             xp.put()
         else:
             if self.request.get('action') == "leave":
                 member = self.current_member()
                 xp = Experience.gql(
                     "where member = :member_key and committee = :committee_key",
                     member_key=member.key(),
                     committee_key=committee.key()).get()
                 xp.delete()
         #self.show_entity(committee.entity)
     self.show_page("start_over")
Пример #18
0
def handle_exp():
    """
    Create person and retrieve all persons
    """
    # POST request
   
    body = request.get_json()
    if body is None:
        raise APIException("You need to specify the request body as a json object", status_code=400)    
    exp1 = Experience(company=body['company'], position=body['position'], description=body['description'] , user_id=body['user_id'])
    db.session.add(exp1)
    db.session.commit()
    return "ok", 200
Пример #19
0
    def test_insert_duplicate_rid_experience_entry(self):
        '''
        Tests inserting an entry into the experience table while an entry with
        the same rid and a different uid already exists in the table. Expect output to match correct data.
        '''
        experience = Experience(uid=1, rid=12, experience=10)
        db.session.add(experience)
        errmsg = experiencehelper.insert_experience(2, 12)
        self.assertEqual(errmsg, None)

        experience = Experience.query.filter_by(rid=12)
        self.assertEqual(experience.count(), 2)

        experience = Experience.query.filter_by(uid=1, rid=12).first()
        self.assertNotEqual(experience, None)
        self.assertEqual(experience.uid, 1)
        self.assertEqual(experience.rid, 12)
        self.assertEqual(experience.experience, 10)

        experience = Experience.query.filter_by(uid=2, rid=12).first()
        self.assertNotEqual(experience, None)
        self.assertEqual(experience.uid, 2)
        self.assertEqual(experience.rid, 12)
        self.assertEqual(experience.experience, 0)
    def test_update_experience_entry_zero_increment(self):
        '''
        Tests trying to update an entry in the experience table by incrementing
        experience by zero. Expect output to match correct data.
        '''
        experience = Experience(uid=1, rid=12, experience=10)
        db.session.add(experience)
        db.session.commit()
        errmsg = experiencehelper.update_experience(1, 12, 0)
        self.assertEqual(errmsg, None)

        experience = Experience.query.filter_by(uid=1, rid=12).first()
        self.assertNotEqual(experience, None)
        self.assertEqual(experience.uid, 1)
        self.assertEqual(experience.rid, 12)
        self.assertEqual(experience.experience, 10)
    def test_update_experience_entry_negative_increment(self):
        '''
        Tests trying to update an entry in the experience table by incrementing
        experience by a negative amount. Expect an error message and data in database remains the same.
        '''
        experience = Experience(uid=1, rid=12, experience=10)
        db.session.add(experience)
        db.session.commit()
        errmsg = experiencehelper.update_experience(1, 12, -5)
        self.assertEqual(
            errmsg, ["Experience cannot be incremented by a negative number."])

        experience = Experience.query.filter_by(uid=1, rid=12).first()
        self.assertNotEqual(experience, None)
        self.assertEqual(experience.uid, 1)
        self.assertEqual(experience.rid, 12)
        self.assertEqual(experience.experience, 10)
Пример #22
0
def add_experience():
    experience_query = Experience.query.filter_by(general_id=current_user.id)
    form = ExperienceForm()
    if request.method == "POST" and form.validate_on_submit():
        exp_query_count = 1
        if experience_query:
            exp_query_count = experience_query.count() + 1
        new_experience = Experience(
            name=form.name.data,
            position=form.position.data,
            time=form.time.data,
            link=form.link.data,
            description=form.description.data,
            general=current_user,
            order_exp=exp_query_count,
        )
        db.session.add(new_experience)
        db.session.commit()
        return redirect(url_for("main_page.home") + "#Experience")

    return render_template("form_page.html", form=form, title="Experience")
Пример #23
0
def handle_experience():
    """
    Create experience and retrieve it all
    """

    # POST request
    if request.method == 'POST':
        body = request.get_json()

        if body is None:
            raise APIException(
                "You need to specify the request body as a json object",
                status_code=400)
        if 'title' not in body:
            raise APIException('You need to specify the title',
                               status_code=400)
        if 'company' not in body:
            raise APIException('You need to specify the company',
                               status_code=400)

        experience1 = Experience(title=body['title'],
                                 company=body['company'],
                                 description=body['description'],
                                 fromDate=body['fromDate'],
                                 toDate=body['toDate'],
                                 resume=body['resume'],
                                 page=body["page"],
                                 user_id=body["user_id"])

        db.session.add(experience1)
        db.session.commit()
        return "ok", 200

    # GET request
    if request.method == 'GET':
        all_experience = Experience.query.all()
        all_experience = list(map(lambda x: x.serialize(), all_experience))
        return jsonify(all_experience), 200

    return "Invalid Method", 404
Пример #24
0
          "Distributed revision control and source " \
          "code management systems: Git (GitLab), Svn",
          "CI/CD tools: Jenkins (Groovy pipeplines), Rundeck",
          "Storage/FS: LVM, hardware/software RAID, NFS, GlusterFS, ZFS"]

for skill in skills:
    db.session.add(Knowledge(skill))


db.session.add(
    Experience(
        "Devops at Kaaiot",
        "February 2017 - Present",
        "https://kaaiot.io",
        "Installation/configuration/support of Kubernetes Clusters " \
        "(AWS/Bare-metal); AWS network designing with Terraform;" \
        "Containerization of services with Docker; Writing Ansible " \
        "code for automatic deployment of OpenLDAP/Jenkins/GitLab " \
        "servers; CI/CD work with Jenkins (Groovy pipelines);" \
        "Backup automatization with Python (boto + AWS Lambda)"
    )
)

db.session.add(
    Experience(
        "SRE / DevOps at Playtech",
        "February 2017 - February 2018",
        "https://playtech.com",
        "Working on migration of company's clients from Cloud Foundry " \
        "DEA to Diego; Writing Ansible code for automatic deployment of " \
        "Cloud Foundry; Configuring monitoring for already working instances;" \
Пример #25
0
from flask import Flask, jsonify, Response, request, abort
from models import Student, Experience

app = Flask(__name__)

# Test data
# Use List instead of database, index of list instead of prime key of table
student1 = Student(1, 'Minghao', '', 'Hu', 'Male', '*****@*****.**',
                   'http://pic.qqtn.com/up/2016-10/14762726301049405.jpg',
                   'Seattle', 'Full-time', 'Fall 2016', 'Aug 2018', False)
student2 = Student(2, 'Jay', '', 'Chou', 'Male', '*****@*****.**',
                   'http://pic.qqtn.com/up/2016-10/14762726301049405.jpg',
                   'Boston', 'Part-time', 'Spring 2017', 'Dec 2018', True)
studentsData = [student1, student2]

experience1 = Experience(1, 'Amazon', 'Software Engineer Intern', 'Sep 2017',
                         'Dec 2017', 'I worked as Software Engineer Intern.')
experience2 = Experience(2, 'Zillow', 'Data Engineer Intern', 'May 2017',
                         'Aug 2017', 'I worked as Data Engineer Intern.')
experiencesData = [experience1, experience2]

coursesData = [
    'Advanced Software Development', 'Algorithm', 'Computer System',
    'Machine Learning'
]


def find_experiences_by_student(
        student):  # Simulate the process of database query
    return experiencesData

Пример #26
0
    def post(self):

        json = request.json
        abort_if_invalid_request_params(json, [
            'user', 'position', 'organization', 'job_category', 'date_start',
            'date_end', 'country'
        ])

        experience = Experience()
        experience.user = ObjectId(json['user'])
        experience.position = json['position']
        experience.organization = json['organization']
        experience.job_category = json['job_category']
        experience.date_start = json['date_start']
        experience.date_end = json['date_end']
        experience.country = json['country']

        experience.save()
        return me_obj_to_serializable(experience)