Пример #1
0
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
Пример #2
0
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
Пример #3
0
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()