示例#1
0
	def test_fellow_load_state(self):
		path = "db/"
		file_name = "mydb"
		file_ = file_name+".db"
		#clean up to avoid conflict between tests
		os.remove(path+file_)
		#clear memory stores
		self.clear_stores()
		#memory
		fellow1 = Fellow("osdflkjsd", "eksdlkfjk", "774881228", "Y")
		fellow1.register()
		Person.save_state(file_name)
		#clear memory stores
		self.clear_stores()
		#memory
		Person.load_state(file_name)
		fellow = Fellow.from_phone("774881228")
		#db
		engine = create_engine("sqlite:///"+path+file_, echo=False)
		Session = sessionmaker(bind=engine)
		session = Session()
		db_fellow = session.query(Person).filter_by(phonenumber="774881228").first()
		session.close()
		#compare
		full_fellow = [fellow.first_name, fellow.last_name, fellow.phone, fellow.type_, fellow.opt_in]
		full_db_fellow = [db_fellow.firstname, db_fellow.lastname, db_fellow.phonenumber, db_fellow.role, db_fellow.optin]
		self.assertEqual(full_db_fellow, full_fellow)
示例#2
0
	def test_staff_load_state(self):
		path = "db/"
		file_name = "mydb"
		file_ = file_name+".db"
		#clean up to avoid conflict between tests
		os.remove(path+file_)
		self.clear_stores()
		#memory
		staff1 = Staff("kdjsn", "ejsjssk", "40000412")
		staff1.register()
		Person.save_state(file_name)
		#db
		engine = create_engine("sqlite:///"+path+file_, echo=False)
		Session = sessionmaker(bind=engine)
		session = Session()
		db_staff = session.query(Person).filter_by(phonenumber="40000412").first()
		#clear memory stores
		self.clear_stores()
		#memory
		Person.load_state(file_name)
		staff = Staff.from_phone("40000412")
		#compare
		full_staff = [staff.first_name, staff.last_name, staff.phone, staff.type_, staff.opt_in]
		full_db_staff = [db_staff.firstname, db_staff.lastname, db_staff.phonenumber, db_staff.role, db_staff.optin]
		session.close()
		self.assertEqual(full_db_staff, full_staff)
示例#3
0
    def post(self):
        ''' Create a employee '''
        arguments = request.get_json(force=True)
        first_name = arguments.get('firstName').strip()
        last_name = arguments.get('lastName').strip()
        department = arguments.get('department').strip() or None
        tel_one = arguments.get('telOne').strip() or None
        tel_two = arguments.get('telTwo').strip() or None
        email = arguments.get('email').strip() or None
        role = arguments.get('role').strip() or None

        if not last_name:
            return abort(400, 'Name cannot be empty!')
        try:
            person = Person(first_name, last_name)
            contact = Contact(email=email, tel_one=tel_one, tel_two=tel_two)
            department = Department.query.filter_by(id=int(department)).first()

            if not person.save_person():
                person = Person.query.filter_by(full_name=(first_name + ' ' +
                                                           last_name)).first()
            if not contact.save_contact():
                contact = Contact.query.filter_by(email=email).first()
            contact_person = ContactPerson(person=person, contact=contact)
            if not contact_person.save_contact_person():
                contact_person = ContactPerson.query.filter_by(
                    person=person, contact=contact).first()

            employee = Employee(contact_person=contact_person,
                                department=department)
            if employee.save_employee():
                return {'message': 'Employee created successfully!'}, 201
            return abort(409, message='Employee already exists!')
        except Exception as e:
            abort(400, message='Failed to create new employee -> {}'.format(e))
def test_person():
    mock_extracted_hash = {u'gender': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Male', u'id': u'/m/05zppz', u'timestamp': u'2007-05-03T07:21:20Z', u'creator': u'/user/seqcmd'}]}, u'spouse_s': {u'count': 1.0, u'valuetype': u'compound', u'values': [{u'lang': u'en', u'creator': u'/user/mwcl_infobox', u'text': u'Lanai - Melinda Gates - 1994-01-01 - Marriage - Freebase Data Team - Marriage', u'timestamp': u'2007-06-08T02:35:47.008Z', u'property': {u'/type/object/type': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Marriage', u'id': u'/people/marriage', u'timestamp': u'2007-06-08T02:35:00.011Z', u'creator': u'/user/mwcl_infobox'}]}, u'/type/object/attribution': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Freebase Data Team', u'id': u'/m/0jsg18', u'timestamp': u'2007-06-08T02:35:00.011Z', u'creator': u'/user/mwcl_infobox'}]}, u'/people/marriage/type_of_union': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Marriage', u'id': u'/m/04ztj', u'timestamp': u'2008-07-24T23:54:58Z', u'creator': u'/user/anne8'}]}, u'/people/marriage/spouse': {u'count': 2.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Melinda Gates', u'id': u'/m/0dmp4', u'timestamp': u'2007-06-08T02:35:11.006Z', u'creator': u'/user/mwcl_infobox'}]}, u'/people/marriage/location_of_ceremony': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Lanai', u'id': u'/m/0133gw', u'timestamp': u'2013-09-10T14:12:09Z', u'creator': u'/user/ellennor'}]}, u'/people/marriage/to': {u'count': 0.0, u'status': u'has_no_value', u'values': []}, u'/people/marriage/from': {u'count': 1.0, u'valuetype': u'datetime', u'values': [{u'lang': '', u'text': u'1994-01-01', u'timestamp': u'2008-07-31T05:23:12Z', u'value': u'1994-01-01', u'creator': u'/user/anne8'}]}}, u'id': u'/m/02kkxn3'}]}, u'profession': {u'count': 5.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Entrepreneur', u'id': u'/m/09x_r', u'timestamp': u'2007-07-28T07:35:48Z', u'creator': u'/user/bolyardtrey'}, {u'lang': u'en', u'text': u'Programmer', u'id': u'/m/05xls', u'timestamp': u'2007-10-06T07:10:48.003Z', u'creator': u'/user/mw_prop_bot'}, {u'lang': u'en', u'text': u'Businessperson', u'id': u'/m/012t_z', u'timestamp': u'2008-03-03T10:21:16Z', u'creator': u'/user/mw_prop_bot'}, {u'lang': u'en', u'text': u'Investor', u'id': u'/m/025sppp', u'timestamp': u'2012-01-18T05:24:35Z', u'creator': u'/user/googlebot'}, {u'lang': u'en', u'text': u'Software Architect', u'id': u'/m/07h_62', u'timestamp': u'2012-01-18T05:27:56Z', u'creator': u'/user/googlebot'}]}, u'weight_kg': {u'count': 1.0, u'valuetype': u'float', u'values': [{u'lang': u'en', u'text': u'61.37', u'timestamp': u'2012-11-25T16:51:16Z', u'value': 61.37, u'creator': u'/user/yananekula'}]}, '/people/person': {}, u'sibling_s': {u'count': 2.0, u'valuetype': u'compound', u'values': [{u'lang': u'en', u'creator': u'/user/igupta', u'text': u'igupta - Libby Gates - Sibling Relationship', u'timestamp': u'2012-04-20T02:56:29Z', u'property': {u'/people/sibling_relationship/sibling': {u'count': 2.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Libby Gates', u'id': u'/m/0j8ryqf', u'timestamp': u'2012-04-20T02:56:29Z', u'creator': u'/user/igupta'}]}, u'/type/object/type': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Sibling Relationship', u'id': u'/people/sibling_relationship', u'timestamp': u'2012-04-20T02:56:29Z', u'creator': u'/user/igupta'}]}, u'/type/object/attribution': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'igupta', u'id': u'/m/0j67w4s', u'timestamp': u'2012-04-20T02:56:29Z', u'creator': u'/user/igupta'}]}}, u'id': u'/m/0j8ryqd'}, {u'lang': u'en', u'creator': u'/user/igupta', u'text': u'igupta - Kristi Gates - Sibling Relationship', u'timestamp': u'2012-04-20T02:56:29.001Z', u'property': {u'/people/sibling_relationship/sibling': {u'count': 2.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Kristi Gates', u'id': u'/m/0j8ryqr', u'timestamp': u'2012-04-20T02:56:29.001Z', u'creator': u'/user/igupta'}]}, u'/type/object/type': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Sibling Relationship', u'id': u'/people/sibling_relationship', u'timestamp': u'2012-04-20T02:56:29.001Z', u'creator': u'/user/igupta'}]}, u'/type/object/attribution': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'igupta', u'id': u'/m/0j67w4s', u'timestamp': u'2012-04-20T02:56:29.001Z', u'creator': u'/user/igupta'}]}}, u'id': u'/m/0j8ryqq'}]}, u'employment_history': {u'count': 5.0, u'valuetype': u'compound', u'values': [{u'lang': u'en', u'creator': u'/user/mwcl_infobox', u'text': u'2006 - Freebase Data Team - Microsoft Corporation - Chief Software Architect - Employment tenure', u'timestamp': u'2007-08-09T04:35:57Z', u'property': {u'/type/object/type': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Employment tenure', u'id': u'/business/employment_tenure', u'timestamp': u'2007-08-09T04:27:13.003Z', u'creator': u'/user/mwcl_infobox'}]}, u'/business/employment_tenure/title': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Chief Software Architect', u'id': u'/m/030nz1x', u'timestamp': u'2008-07-13T18:44:11Z', u'creator': u'/user/earlye'}]}, u'/business/employment_tenure/company': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Microsoft Corporation', u'id': u'/m/04sv4', u'timestamp': u'2007-08-09T04:30:13.006Z', u'creator': u'/user/mwcl_infobox'}]}, u'/type/object/attribution': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Freebase Data Team', u'id': u'/m/0jsg18', u'timestamp': u'2007-08-09T04:27:13.003Z', u'creator': u'/user/mwcl_infobox'}]}, u'/business/employment_tenure/from': {u'count': 1.0, u'valuetype': u'datetime', u'values': [{u'lang': '', u'text': u'2006', u'timestamp': u'2008-08-31T02:35:04.001Z', u'value': u'2006', u'creator': u'/user/earlye'}]}}, u'id': u'/m/02t7k19'}, {u'lang': u'en', u'creator': u'/user/earlye', u'text': u'1975 - earlye - Microsoft Corporation - Employment tenure', u'timestamp': u'2008-07-13T19:04:54Z', u'property': {u'/type/object/type': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Employment tenure', u'id': u'/business/employment_tenure', u'timestamp': u'2008-07-13T19:04:54Z', u'creator': u'/user/earlye'}]}, u'/business/employment_tenure/company': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Microsoft Corporation', u'id': u'/m/04sv4', u'timestamp': u'2008-07-13T19:04:54Z', u'creator': u'/user/earlye'}]}, u'/type/object/attribution': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'earlye', u'id': u'/m/02_5dlr', u'timestamp': u'2008-07-13T19:04:54Z', u'creator': u'/user/earlye'}]}, u'/business/employment_tenure/from': {u'count': 1.0, u'valuetype': u'datetime', u'values': [{u'lang': '', u'text': u'1975', u'timestamp': u'2008-07-13T19:04:54Z', u'value': u'1975', u'creator': u'/user/earlye'}]}}, u'id': u'/m/04c_wns'}, {u'lang': u'en', u'creator': u'/user/mw_template_bot', u'text': u'Freebase Data Team - Cascade Investment - Employment tenure', u'timestamp': u'2008-07-18T22:53:51Z', u'property': {u'/type/object/type': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Employment tenure', u'id': u'/business/employment_tenure', u'timestamp': u'2008-07-18T22:53:51Z', u'creator': u'/user/mw_template_bot'}]}, u'/type/object/attribution': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Freebase Data Team', u'id': u'/m/03jtjff', u'timestamp': u'2008-07-18T22:53:51Z', u'creator': u'/user/mw_template_bot'}]}, u'/business/employment_tenure/company': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Cascade Investment', u'id': u'/m/03cs4bl', u'timestamp': u'2008-07-18T22:53:51Z', u'creator': u'/user/mw_template_bot'}]}}, u'id': u'/m/04dd7md'}, {u'lang': u'en', u'creator': u'/user/earlye', u'text': u'2006 - earlye - Microsoft Corporation - Chief Executive Officer - Employment tenure', u'timestamp': u'2008-08-31T02:35:04Z', u'property': {u'/business/employment_tenure/to': {u'count': 1.0, u'valuetype': u'datetime', u'values': [{u'lang': '', u'text': u'2006', u'timestamp': u'2008-08-31T02:35:04Z', u'value': u'2006', u'creator': u'/user/earlye'}]}, u'/type/object/type': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Employment tenure', u'id': u'/business/employment_tenure', u'timestamp': u'2008-08-31T02:35:04Z', u'creator': u'/user/earlye'}]}, u'/business/employment_tenure/title': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Chief Executive Officer', u'id': u'/m/0dq_5', u'timestamp': u'2008-08-31T02:35:04Z', u'creator': u'/user/earlye'}]}, u'/type/object/attribution': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'earlye', u'id': u'/m/02_5dlr', u'timestamp': u'2008-08-31T02:35:04Z', u'creator': u'/user/earlye'}]}, u'/business/employment_tenure/company': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Microsoft Corporation', u'id': u'/m/04sv4', u'timestamp': u'2008-08-31T02:35:04Z', u'creator': u'/user/earlye'}]}}, u'id': u'/m/04j6nwk'}, {u'lang': u'en', u'creator': u'/user/mgutierrezt', u'text': u'1981 - mgutierrezt - Microsoft Corporation - President - Employment tenure', u'timestamp': u'2009-03-31T15:18:49Z', u'property': {u'/type/object/type': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Employment tenure', u'id': u'/business/employment_tenure', u'timestamp': u'2009-03-31T15:18:49Z', u'creator': u'/user/mgutierrezt'}]}, u'/business/employment_tenure/title': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'President', u'id': u'/m/060c4', u'timestamp': u'2009-03-31T15:18:49Z', u'creator': u'/user/mgutierrezt'}]}, u'/business/employment_tenure/company': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Microsoft Corporation', u'id': u'/m/04sv4', u'timestamp': u'2009-03-31T15:18:49Z', u'creator': u'/user/mgutierrezt'}]}, u'/type/object/attribution': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'mgutierrezt', u'id': u'/m/02yxl2_', u'timestamp': u'2009-03-31T15:18:49Z', u'creator': u'/user/mgutierrezt'}]}, u'/business/employment_tenure/from': {u'count': 1.0, u'valuetype': u'datetime', u'values': [{u'lang': '', u'text': u'1981', u'timestamp': u'2009-03-31T15:18:49Z', u'value': u'1981', u'creator': u'/user/mgutierrezt'}]}}, u'id': u'/m/05ndtqb'}]}, u'date_of_birth': {u'count': 1.0, u'valuetype': u'datetime', u'values': [{u'lang': '', u'text': u'1955-10-28', u'timestamp': u'2006-12-10T16:31:50.016Z', u'value': u'1955-10-28', u'creator': u'/user/mwcl_musicbrainz'}]}, u'parents': {u'count': 2.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Mary Maxwell Gates', u'id': u'/m/0cnwp4', u'timestamp': u'2007-07-27T16:41:33Z', u'creator': u'/user/smyjpmu'}, {u'lang': u'en', u'text': u'William H. Gates, Sr.', u'id': u'/m/027z0k', u'timestamp': u'2007-07-27T16:40:22Z', u'creator': u'/user/smyjpmu'}]}, u'education': {u'count': 2.0, u'valuetype': u'compound', u'values': [{u'lang': u'en', u'creator': u'/user/mgutierrezt', u'text': u'1975 - Harvard College - mgutierrezt - 1973 - Education', u'timestamp': u'2009-03-31T15:17:01Z', u'property': {u'/type/object/type': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Education', u'id': u'/education/education', u'timestamp': u'2009-03-31T15:17:01Z', u'creator': u'/user/mgutierrezt'}]}, u'/education/education/degree': {u'count': 0.0, u'status': u'has_no_value', u'values': []}, u'/type/object/attribution': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'mgutierrezt', u'id': u'/m/02yxl2_', u'timestamp': u'2009-03-31T15:17:01Z', u'creator': u'/user/mgutierrezt'}]}, u'/education/education/major_field_of_study': {u'count': 0.0, u'status': u'has_value', u'values': []}, u'/education/education/end_date': {u'count': 1.0, u'valuetype': u'datetime', u'values': [{u'lang': '', u'text': u'1975', u'timestamp': u'2013-07-02T04:49:06Z', u'value': u'1975', u'creator': u'/user/alsasuncion'}]}, u'/education/education/institution': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Harvard College', u'id': u'/m/01mpwj', u'timestamp': u'2009-03-31T15:17:01Z', u'creator': u'/user/mgutierrezt'}]}, u'/education/education/start_date': {u'count': 1.0, u'valuetype': u'datetime', u'values': [{u'lang': '', u'text': u'1973', u'timestamp': u'2009-03-31T15:17:01Z', u'value': u'1973', u'creator': u'/user/mgutierrezt'}]}}, u'id': u'/m/05ndtmv'}, {u'lang': u'en', u'creator': u'/user/earlye', u'text': u'1973 - Lakeside School - earlye - 1968 - Education', u'timestamp': u'2009-03-31T23:41:57Z', u'property': {u'/type/object/type': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Education', u'id': u'/education/education', u'timestamp': u'2009-03-31T23:41:57Z', u'creator': u'/user/earlye'}]}, u'/education/education/degree': {u'count': 0.0, u'status': u'has_value', u'values': []}, u'/type/object/attribution': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'earlye', u'id': u'/m/02_5dlr', u'timestamp': u'2009-03-31T23:41:57Z', u'creator': u'/user/earlye'}]}, u'/education/education/major_field_of_study': {u'count': 0.0, u'status': u'has_value', u'values': []}, u'/education/education/end_date': {u'count': 1.0, u'valuetype': u'datetime', u'values': [{u'lang': '', u'text': u'1973', u'timestamp': u'2012-06-15T13:51:19Z', u'value': u'1973', u'creator': u'/user/hgfm27'}]}, u'/education/education/institution': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Lakeside School', u'id': u'/m/01jv5g', u'timestamp': u'2009-03-31T23:41:57Z', u'creator': u'/user/earlye'}]}, u'/education/education/start_date': {u'count': 1.0, u'valuetype': u'datetime', u'values': [{u'lang': '', u'text': u'1968', u'timestamp': u'2013-10-09T10:10:00Z', u'value': u'1968', u'creator': u'/user/mathiaswolter'}]}}, u'id': u'/m/05nkrh3'}]}, u'place_of_birth': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Seattle', u'id': u'/m/0d9jr', u'timestamp': u'2007-05-28T19:37:39Z', u'creator': u'/user/mwcl_infobox'}]}, u'nationality': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'United States of America', u'id': u'/m/09c7w0', u'timestamp': u'2007-07-10T21:51:18Z', u'creator': u'/user/subtext'}]}, u'quotations': {u'count': 4.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u"Microsoft looks at new ideas, they don't evaluate whether the idea will move the industry forward, they ask, 'how will it help us sell more copies of Windows?'", u'id': u'/m/051t7f6', u'timestamp': u'2008-12-20T06:27:17Z', u'creator': u'/user/davidar'}, {u'lang': u'en', u'text': u"It's fine to celebrate success but it is more important to heed the lessons of failure", u'id': u'/m/0gdjk9y', u'timestamp': u'2011-02-27T15:56:00Z', u'creator': u'/user/gr8gatsby'}, {u'lang': u'en', u'text': u'I believe that if you show people the problems and you show them the solutions they will be moved to act.', u'id': u'/m/0gdjkc_', u'timestamp': u'2011-02-27T15:58:11Z', u'creator': u'/user/gr8gatsby'}, {u'lang': u'en', u'text': u'Your most unhappy customers are your greatest source of learning.', u'id': u'/m/0jvfqd1', u'timestamp': u'2012-05-20T15:34:43Z', u'creator': u'/user/avishekb'}]}, u'height_meters': {u'count': 1.0, u'valuetype': u'float', u'values': [{u'lang': u'en', u'text': u'1.78', u'timestamp': u'2013-09-24T12:56:48Z', u'value': 1.78, u'creator': u'/user/goddess888'}]}, u'children': {u'count': 3.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Jennifer Katharine Gates', u'id': u'/m/02s5z69', u'timestamp': u'2007-07-28T07:38:36.001Z', u'creator': u'/user/bolyardtrey'}, {u'lang': u'en', u'text': u'Phoebe Adele Gates', u'id': u'/m/02n_gxg', u'timestamp': u'2007-07-28T07:37:01Z', u'creator': u'/user/bolyardtrey'}, {u'lang': u'en', u'text': u'Rory John Gates', u'id': u'/m/02n_gx7', u'timestamp': u'2007-07-28T07:36:49Z', u'creator': u'/user/bolyardtrey'}]}, u'ethnicity': {u'count': 1.0, u'valuetype': u'object', u'values': [{u'lang': u'en', u'text': u'Scottish American', u'id': u'/m/07bch9', u'timestamp': u'2009-11-16T17:59:25.005Z', u'creator': u'/user/deleted_2011_06_06'}]}}
    person = Person()
    person.extract(mock_extracted_hash)

    assert_equal(person.birthday, '1955-10-28')
    assert_equal(person.place_of_birth, 'Seattle')
    assert_equal(person.siblings, ['Libby Gates', 'Kristi Gates'])
    assert_equal(person.spouses, [u'Melinda Gates @ Lanai  1994-01-01'])
示例#5
0
    def post(self):
        ''' Create a person '''
        arguments = request.get_json(force=True)
        first_name = arguments.get('firstName').strip()
        last_name = arguments.get('lastName').strip()

        if not last_name:
            return abort(400, 'Last Name cannot be empty!')
        try:
            person = Person(first_name=first_name, last_name=last_name)
            if person.save_person():
                return {'message': 'Person created successfully!'}, 201
            return abort(409, message='Person already exists!')
        except Exception as e:
            abort(400, message='Failed to create new person -> {}'.format(e))
示例#6
0
def create_person(request):
    ret_json = {}
    status_code = 400
    data = request.get_json()

    if data != None:
        status_code = 201
        f_name = data.get("first_name", "")
        l_name = data.get("last_name", "")
        e_address = data.get("email_address", "")

        new_person = Person(f_name, l_name, e_address)

        global ID
        ID = ID + 1
        persons[str(ID)] = new_person

        ret_json["first_name"] = new_person.first_name
        ret_json["last_name"] = new_person.last_name
        ret_json["email_address"] = new_person.email_address

    else:
        ret_json[
            "message"] = "first_name, last_name, and email_address should be given."

    return jsonify(ret_json), status_code
示例#7
0
def save_state(file_name="default"):
    file_name = str(file_name)
    path = "db/"
    file_ = file_name + ".db"
    try:
        if os.path.isfile(path + file_):
            os.remove(path + file_)
        Person.save_state(file_name)
        LivingSpace.save_state(file_name)
        Office.save_state(file_name)
        Allocation.save_state(file_name)
        print_pretty(
            "The current state of the application has successfully been saved in the db directory under the file: %s."
            % file_)
    except exc.DBAPIError:
        print_pretty(
            str("There is currently a problem with the specified file please try a different one."
                ))
    except Exception as e:
        print_pretty(str(e))
示例#8
0
def confirmation():
    reps = session.get('reps', None)
    person_dict = session.get('person', None)

    if not person_dict:
        return redirect(url_for('index'))

    if request.method == 'POST':
        make_calls_job.delay(
            Person(**person_dict),
            reps
        )

    return render_template('confirmation.html', reps=reps)
示例#9
0
def load_state(file_name="default"):
    file_name = str(file_name)
    path = "db/"
    file_ = file_name + ".db"
    try:
        if os.path.isfile(path + file_):
            Person.load_state(file_name)
            LivingSpace.load_state(file_name)
            Office.load_state(file_name)
            Allocation.load_state(file_name)
            print_pretty(
                "The current state of the application has successfully been loaded from the file: %s under the directory db."
                % file_)
        else:
            raise Exception(
                "The specified db file (%s) does not exist under the db directory."
                % file_)
    except exc.DBAPIError:
        print_pretty(
            str("There is currently a problem with the specified file please try a different one."
                ))
    except Exception as e:
        print_pretty(str(e))
示例#10
0
def index():
    form = MakeCallForm()
    if request.method == 'POST' and form.validate_on_submit():
        person = Person()
        form.populate_obj(person)
        reps = get_reps_by_postal_code(form.postal_code.data)

        session['reps'] = reps
        session['person'] = asdict(person)
        persist_person_job.delay(
            person
        )

        make_calls_job.delay(
            person,
            reps
        )

        return redirect(url_for('confirmation', _anchor="share"))

    return render_template('index.html', form=form)
'Py Boxes: Packages'

'''
A package is another way to organize your code. 

Packages let you import directories on your computer into your programs using the 'import' or 'from import' statements. 

A directory on your system can become a package if it contains an empty __init__.py

Use these when you want to have separate features in your app/software
'''

from app.models.person import Person

alice = Person("Alice", "Martin", 30)
print(alice.first_name)



from run import app
from app.db import db
from app.models.person import Person

with app.app_context():
    name = 'Paulo'
    person = Person(name)
    db.session.add(person)
    db.session.commit()
示例#13
0
 def clear_stores(self):
     #Clean data stores to run print tests
     Dojo.clear()
     Room.clear()
     Person.clear()
示例#14
0
from run import app
from app.db import db
from app.models.address import Address
from app.models.person import Person

with app.app_context():
    email1 = 'teste3@teste'
    owner = Person.find_by_name('Paulo')
    address = Address(email=email1, owner=owner)
    db.session.add(address)
    db.session.commit()
示例#15
0
    def post(self):
        ''' Create a company '''
        arguments = request.get_json(force=True)
        name = arguments.get('name').strip()
        district = arguments.get('district').strip() or None
        postal = arguments.get('postal').strip() or None
        country = arguments.get('country').strip() or None
        tech_person_name_string = arguments.get(
            'techPersonName').strip() or None
        tech_person_email = arguments.get('techPersonEmail').strip() or None
        address_line_1 = arguments.get('address1').strip() or None
        address_line_2 = arguments.get('address2').strip() or None
        legal_person_name_str = arguments.get(
            'legalPersonName').strip() or None
        legal_person_email = arguments.get('legalPersonEmail').strip() or None
        tech_person_name = tech_person_name_string.split()
        legal_person_name = legal_person_name_str.split()

        if not name:
            return abort(400, 'Name cannot be empty!')
        try:
            address = Address(
                district=district,
                postal_code=postal,
                country=country,
                address_line_1=address_line_1,
                address_line_2=address_line_2
                )
            tech_person = Person(tech_person_name[0], tech_person_name[-1])
            legal_person = Person(legal_person_name[0], legal_person_name[-1])
            tech_contact = Contact(email=tech_person_email)
            legal_contact = Contact(email=legal_person_email)

            if not address.save_address():
                address = Address.query.filter_by(
                    address_line_1=address.address_line_1,
                    active=True).first()
            if not tech_person.save_person():
                tech_person = Person.query.filter_by(
                    full_name=tech_person_name_string).first()
            if not legal_person.save_person():
                legal_person = Person.query.filter_by(
                    full_name=legal_person_name_str).first()
            if not tech_contact.save_contact():
                tech_contact = Contact.query.filter_by(
                    email=tech_person_email).first()
            if not legal_contact.save_contact():
                legal_contact = Contact.query.filter_by(
                    email=legal_person_email).first()
            tech_contact_person = ContactPerson(
                person=tech_person,
                contact=tech_contact)
            legal_contact_person = ContactPerson(
                person=legal_person,
                contact=legal_contact)
            if not tech_contact_person.save_contact_person():
                tech_contact_person = ContactPerson.query.filter_by(
                    person=tech_person,
                    contact=tech_contact).first()
            if not legal_contact_person.save_contact_person():
                legal_contact_person = ContactPerson.query.filter_by(
                    person=legal_person,
                    contact=legal_contact).first()

            company = Company(
                name=name,
                address=address,
                legal_person=legal_contact_person,
                tech_person=tech_contact_person
                )
            if company.save_company():
                return {'message': 'Company created successfully!'}, 201
            return abort(409, message='Company already exists!')
        except Exception as e:
            abort(400, message='Failed to create new company -> {}'.format(e))