def test_list_client_industries(session, fake_lorem):
    """Test list_client_industries"""

    # Arrange
    fake_model = ClientIndustry(name=fake_lorem.word(),
                                name_slug=fake_lorem.word())
    ClientIndustryRepository.create(fake_model)

    # Act
    result = ClientIndustryRepository.list_client_industries()

    # Assert
    assert isinstance(result, list)
def test_get_one_by_id(session, fake_lorem):
    """Test get_one_by_id"""

    # Arrange
    fake_model = ClientIndustryRepository.add(
        ClientIndustry(name=fake_lorem.word()))

    # Act
    result = ClientIndustryRepository.get_one_by_id(model_id=fake_model.id)

    # Assert
    assert result is not None
    assert isinstance(result, ClientIndustry)
    assert result == fake_model
Exemplo n.º 3
0
def create_client_industry(name: str) -> ClientIndustry:
    """
    Creates client industry.

    Args:
        name (str): Name of client industry to be added.

    Returns:
        ClientIndustry: Client industry that has been added.

    Raises:
        ValueError if client industry name already exists.
    """
    new_client_industry = ClientIndustry(name=name)
    return ClientIndustryRepository.add(new_client_industry)
def test_create(session, fake_lorem, fake_profile):
    """Test creating a client industry."""

    # Arrange
    fake_org = create_organization(organization_name=fake_lorem.word(),
                                   address=fake_profile.profile()['address'])
    test_model = ClientIndustry(name=fake_lorem.word(),
                                organization_id=fake_org.id)

    # Act
    result = ClientIndustryRepository.add(model=test_model)

    # Assert
    assert isinstance(result, ClientIndustry)
    assert isinstance(UUID(result.id), UUID)
def test_update_raises_value_error_exception(session, fake_lorem):
    """Test update raises ValueError exception when invalid
    data is supplied"""

    # Arrange
    test_model = ClientIndustryRepository.add(
        ClientIndustry(name=fake_lorem.word()))
    updates = {'name': 'Existing name', 'name_slug': 'existing-name'}
    update_fields = (
        'name',
        'name_slug',
    )

    # Assert
    with pytest.raises(ValueError):
        ClientIndustryRepository\
            .update(test_model.id, update_fields, **updates)
def test_update(session, fake_lorem):
    """Test updating a client industry"""
    # Arrange
    test_model = ClientIndustryRepository.add(
        ClientIndustry(name=fake_lorem.word()))
    updates = {'name': 'Changed name', 'name_slug': 'changed-name'}
    update_fields = (
        'name',
        'name_slug',
    )

    # Act
    result = ClientIndustryRepository\
        .update(test_model.id, update_fields, **updates)

    # Assert
    assert isinstance(result, ClientIndustry)
    assert test_model.id == result.id
Exemplo n.º 7
0
def session(db, request, seed_data):
    """Create a new database session for the tests"""
    connection = db.engine.connect()
    transaction = connection.begin()

    options = dict(bind=connection, binds={})
    session = db.create_scoped_session(options=options)

    db.session = session

    client_industry_seed = seed_data['client_industry']
    client_industry_1 = ClientIndustry(**client_industry_seed)

    organization_seed = seed_data['organization']
    organization_1 = Organization(**organization_seed)

    user_account_seed = seed_data['user_account']
    user_account_seed['organization_id'] = organization_1.id
    user_1 = UserAccount(**user_account_seed)

    client_seed = seed_data['client']
    client_seed['organization_id'] = organization_1.id
    client_seed['client_industry_id'] = client_industry_1.id
    client_1 = Client(**client_seed)

    line_of_service_seed = seed_data['line_of_service']
    line_of_service_seed['organization_id'] = organization_1.id
    line_of_service_1 = LineOfService(**line_of_service_seed)

    engagement_seed = seed_data['engagement']
    engagement_seed['client_id'] = client_1.id
    engagement_seed['line_of_service_id'] = line_of_service_1.id
    engagement_seed['organization_id'] = organization_1.id
    engagement_1 = Engagement(**engagement_seed)

    employee_seed = seed_data['employee']
    employee_seed['user_account_id'] = user_1.id
    employee_seed['organization_id'] = organization_1.id
    employee_1 = Employee(**employee_seed)

    administrator_role = RoleRepository.get_by_name('administrator')
    if not administrator_role:
        role_1 = Role(name='Administrator', normalized_name='administrator')
        db.session.add(role_1)

    db.session.add(organization_1)
    db.session.add(user_1)
    db.session.add(client_industry_1)
    db.session.add(client_1)
    db.session.add(line_of_service_1)
    db.session.add(engagement_1)
    db.session.add(employee_1)
    db.session.commit()

    def teardown():
        """Clean up test suite."""
        transaction.rollback()
        connection.close()
        session.remove()

    request.addfinalizer(teardown)
    return session