def test_read_person_fields(auth_client): # GIVEN an empty data base # WHEN read_person_fields is called by the api resp = auth_client.get(url_for('people.read_person_fields')) assert resp.status_code == 200 # THEN the person field structure is returned assert resp.json['person'][0]['id'] == 'INTEGER' assert resp.json['person'][1]['first_name'] == 'VARCHAR(64)' assert resp.json['person'][2]['last_name'] == 'VARCHAR(64)' assert resp.json['person'][3]['second_last_name'] == 'VARCHAR(64)' assert resp.json['person'][4]['gender'] == 'VARCHAR(1)' assert resp.json['person'][5]['birthday'] == 'DATE' assert resp.json['person'][6]['phone'] == 'VARCHAR(64)' assert resp.json['person'][7]['email'] == 'VARCHAR(64)' assert resp.json['person'][8]['active'] == 'BOOLEAN' assert resp.json['person'][9]['location_id'] == 'INTEGER' assert resp.json['person_attributes'] == [] # GIVEN a DB with actual attributes create_multiple_people(auth_client.sqla, 15) create_multiple_people_attributes(auth_client.sqla, 15) # WHEN we use the api to call the read person fields resp = auth_client.get(url_for('people.read_person_fields')) # THEN we get the correct attributes assert resp.json['person_attributes'] != []
def fake_courses(): create_multiple_people(db.session, 17) create_multiple_courses(db.session, 12) create_multiple_course_offerings(db.session, 25) create_multiple_prerequisites(db.session) create_multiple_diplomas(db.session, 30) create_multiple_students(db.session, 60) create_class_meetings(db.session, 30) create_diploma_awards(db.session, 30) create_class_attendance(db.session, 30) create_course_completion(db.session, 30)
def test_create_person_with_attributes_string(auth_client): # GIVEN an empty database create_multiple_people(auth_client.sqla, 17) count = random.randint(5, 15) # WHEN we create a random number of new people attributes for i in range(count): resp = auth_client.post( url_for('people.create_person'), json={ 'person': person_object_factory(), 'attributesInfo': [person_attribute_string_factory(auth_client.sqla)] }) assert resp.status_code == 201 # THEN we end up with the proper number of people attributes of the string type in the database assert auth_client.sqla.query(PersonAttribute).count() == count
def person_attribute_string_factory(sqla): """Create a fake person attribute that is enumerated.""" create_multiple_attributes(sqla, 5, 1) people = sqla.query(Person).all() if not people: create_multiple_people(sqla, random.randint(3, 6)) people = sqla.query(Person).all() current_person = random.choice(people) nonenumerated_values = sqla.query(Attribute).all() if not nonenumerated_values: create_multiple_nonenumerated_values(sqla, random.randint(3, 6)) nonenumerated_values = sqla.query(Attribute).all() current_nonenumerated_value = random.choice(nonenumerated_values) person_attribute = { 'personId': current_person.id, 'attributeId': current_nonenumerated_value.id, 'stringValue': rl_fake().first_name() } return person_attribute
def person_attribute_enumerated_factory(sqla): """Create a fake person attribute that is enumerated.""" create_multiple_attributes(sqla, 5, 1) create_multiple_enumerated_values(sqla, 10) people = sqla.query(Person).all() if not people: create_multiple_people(sqla, random.randint(3, 6)) people = sqla.query(Person).all() current_person = random.choice(people) enumerated_values = sqla.query(EnumeratedValue).all() if not enumerated_values: create_multiple_enumerated_values(sqla, random.randint(3, 6)) enumerated_values = sqla.query(EnumeratedValue).all() current_enumerated_value = random.choice(enumerated_values) person_attribute = { 'personId': current_person.id, 'attributeId': current_enumerated_value.attribute_id, 'enumValueId': current_enumerated_value.id } return person_attribute
def load_all(): access_token = create_access_token(identity='test-user') _load_locales() Country.load_from_file() Language.load_from_file() Role.load_from_file() Attribute.load_types_from_file() create_multiple_people(db.session, 17) create_multiple_accounts(db.session, 0.25) create_accounts_roles(db.session, 0.75) access_token = create_access_token(identity='test-user') create_multiple_areas(db.session, 5) create_multiple_addresses(db.session, 10) create_multiple_locations(db.session, 20) create_multiple_people(db.session, 17) create_multiple_accounts(db.session, 0.25) create_multiple_courses(db.session, 12) create_multiple_course_offerings(db.session, 25) create_multiple_prerequisites(db.session) create_multiple_diplomas(db.session, 30) create_multiple_students(db.session, 60) create_class_meetings(db.session, 30) create_events_test_data(db.session) # create_diploma_awards(db.session, 30) # create_class_attendance(db.session, 30) create_diploma_awards(db.session, 30) create_class_attendance(db.session, 30) create_course_completion(db.session, 30) create_multiple_people_attributes(db.session, 5) create_multiple_managers(db.session, 2, 'Group Overseer') create_multiple_managers(db.session, 5, 'Group Leader') create_group_test_data(db.session) # Always put this close to last (since it has dependancies in all of the major modules) create_images_test_data(db.session)
def test_update_person_add_attribute(auth_client): # GIVEN a set of attributes and people count = random.randint(3, 6) create_multiple_attributes(auth_client.sqla, count) create_multiple_people(auth_client.sqla, count) people = auth_client.sqla.query(Person).all() # GIVEN modification data for person in people: new_person = person_object_factory() mod = {} flips = (flip(), flip(), flip(), flip(), flip(), flip(), flip(), flip()) if flips[0]: mod['firstName'] = new_person['firstName'] if flips[1]: mod['lastName'] = new_person['lastName'] if flips[2]: mod['secondLastName'] = new_person['secondLastName'] if flips[3]: mod['gender'] = new_person['gender'] if flips[4]: mod['active'] = new_person['active'] if flips[5] and 'birthday' in new_person.keys(): mod['birthday'] = new_person['birthday'] if flips[6] and 'phone' in new_person.keys(): mod['phone'] = new_person['phone'] if flips[7] and 'email' in new_person.keys(): mod['email'] = new_person['email'] # WHEN a people are updated with data and an attribute resp = auth_client.put( url_for('people.update_person', person_id=person.id), json={ 'person': mod, 'attributesInfo': [person_attribute_string_factory(auth_client.sqla)] }) # THEN expect the update to run OK assert resp.status_code == 200 # THEN expect the person to be updated and have an attribute assert resp.json['id'] == person.id if 'firstName' in mod.keys() and mod['firstName'] != person.first_name: resp.json['firstName'] != person.first_name else: resp.json['firstName'] == person.first_name if 'lastName' in mod.keys() and mod['lastName'] != person.last_name: resp.json['lastName'] != person.last_name else: resp.json['lastName'] == person.last_name if 'secondLastName' in mod.keys( ) and mod['secondLastName'] != person.second_last_name: resp.json['secondLastName'] != person.second_last_name else: resp.json['secondLastName'] == person.second_last_name if 'gender' in mod.keys() and mod['gender'] != person.gender: resp.json['gender'] != person.gender else: resp.json['gender'] == person.gender if 'active' in mod.keys() and mod['active'] != person.active: resp.json['active'] != person.active else: resp.json['active'] == person.active if 'birthday' in mod.keys() and mod['birthday'] != person.birthday: resp.json['birthday'] != person.birthday else: resp.json['birthday'] == person.birthday if 'phone' in mod.keys() and mod['phone'] != person.phone: resp.json['phone'] != person.phone else: resp.json['phone'] == person.phone if 'email' in mod.keys() and mod['email'] != person.email: resp.json['email'] != person.email else: resp.json['email'] == person.email assert len(resp.json['attributesInfo']) == 1
def create_multiple_people_attributes(sqla, n): """Commit `n` new people with attributes to the database.""" person_schema = PersonSchema() attribute_schema = AttributeSchema() person_attribute_schema = PersonAttributeSchema() enumerated_value_schema = EnumeratedValueSchema() new_people = [] for i in range(n): valid_person = person_schema.load(person_object_factory()) new_people.append(Person(**valid_person)) sqla.add_all(new_people) new_attributes = [{ 'nameI18n': add_i18n_code('Marital Status', sqla, 'en-US', f'attribute.married'), 'typeI18n': add_i18n_code('attribute.radio', sqla, 'en-US', f'attribute.radio'), 'seq': 2, 'active': 1 }, { 'nameI18n': add_i18n_code('Home Group Name', sqla, 'en-US', f'attribute.HomeGroupName'), 'typeI18n': add_i18n_code('attribute.string', sqla, 'en-US', f'attribute.string'), 'seq': 1, 'active': 1 }, { 'nameI18n': add_i18n_code('Baptism Date', sqla, 'en-US', f'attribute.BaptismDate'), 'typeI18n': add_i18n_code('attribute.date', sqla, 'en-US', f'attribute.date'), 'seq': 3, 'active': 1 }] new_enumerated_values = [{ 'id': 1, 'attributeId': 1, 'valueI18n': add_i18n_code('married', sqla, 'en-US', f'personAttribute.married'), 'active': 1 }, { 'id': 2, 'attributeId': 1, 'valueI18n': add_i18n_code('single', sqla, 'en-US', f'personAttribute.single'), 'active': 1 }] add_i18n_code('Estado Civil', sqla, 'es-EC', f'attribute.married') add_i18n_code('Nombre del grupo de origen', sqla, 'es-EC', f'attribute.HomeGroupName') add_i18n_code('Fecha de bautismo', sqla, 'es-EC', f'attribute.BaptismDate') add_i18n_code('casado', sqla, 'es-EC', f'personAttribute.married') add_i18n_code('soltero', sqla, 'es-EC', f'personAttribute.single') valid_attributes = [] for attribute in new_attributes: valid_attribute = attribute_schema.load(attribute) valid_attributes.append(Attribute(**valid_attribute)) sqla.add_all(valid_attributes) sqla.commit() valid_enumerated_values = [] for enumerated_value in new_enumerated_values: valid_enumerated_value = enumerated_value_schema.load(enumerated_value) valid_enumerated_values.append( EnumeratedValue(**valid_enumerated_value)) sqla.add_all(valid_enumerated_values) sqla.commit() all_people = sqla.query(Person).all() if not all_people: create_multiple_people(sqla, random.randint(3, 6)) all_people = sqla.query(Person).all() count = 1 for i in range(n): # current_person = random.choice(all_people) # person_id = current_person.id new_person_attributes = [{ 'personId': count, 'attributeId': 1, 'enumValueId': 1 }, { 'personId': count, 'attributeId': 2, 'stringValue': "Home Group 1" }, { 'personId': count, 'attributeId': 3, 'stringValue': '1-15-2019' }] valid_person_attributes = [] count = count + 1 for person_attribute in new_person_attributes: valid_person_attribute = person_attribute_schema.load( person_attribute) valid_person_attributes.append( PersonAttribute(**valid_person_attribute)) sqla.add_all(valid_person_attributes) sqla.commit()
def fake_people(): create_multiple_people(db.session, 17) create_accounts_roles(db.session, 0.75)
def load_languages(): _load_locales() Country.load_from_file() Language.load_from_file() create_multiple_people(db.session, 17) create_multiple_accounts(db.session, 0.25)