def test_update_client(session, fake_lorem):
    """Test update_client function."""

    # Arrange
    first_fake_industry = create_client_industry(name=fake_lorem.word())
    sec_fake_industry = create_client_industry(name=fake_lorem.word())
    fake_org = create_organization(
        address=fake_lorem.word(),
        organization_name=fake_lorem.word())
    fake_client = create_client(
        name=fake_lorem.word(),
        organization_id=fake_org.id,
        client_industry_id=first_fake_industry.id)
    fake_client_name = fake_client.name
    fake_client_slug = fake_client.name_slug

    # Act
    result = update_client(
        client_id=fake_client.id,
        name=fake_lorem.word(),
        client_industry_id=sec_fake_industry.id)

    # Assert
    assert isinstance(result, Client)
    assert result.name != fake_client_name
    assert result.name_slug != fake_client_slug
    assert result.client_industry_id != first_fake_industry.id
    assert result.id == fake_client.id
Beispiel #2
0
 def post(self):
     payload = request.json
     validated_input = OrganizationInputSchema(strict=True)\
         .load(payload).data
     new_company = create_organization(**validated_input)
     output = OrganizationCreatedSchema(strict=True).dump({
         'status': 'OK',
         'code': 201,
         'data': new_company
     }).data
     return output, 201
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_create_client(session, fake_lorem):
    """Test create_client function"""

    # Arrange
    fake_industry = create_client_industry(name=fake_lorem.word())
    fake_org = create_organization(address=fake_lorem.word(),
                                   organization_name=fake_lorem.word())
    fake_client = Client(name=fake_lorem.word(),
                         organization_id=fake_org.id,
                         client_industry_id=fake_industry.id)

    # Act
    result = ClientRepository.create_client(fake_client)

    # Assert
    assert isinstance(result, Client)
def test_get_client(session, fake_lorem):
    """Test get_client function."""

    # Arrange
    fake_industry = create_client_industry(name=fake_lorem.word())
    fake_org = create_organization(
        address=fake_lorem.word(),
        organization_name=fake_lorem.word())
    test_client = create_client(
        name=fake_lorem.word(),
        organization_id=fake_org.id,
        client_industry_id=fake_industry.id)

    # Act
    result = get_client(test_client.id)

    # Assert
    assert result is not None
    assert isinstance(result, Client)
    assert result.id == test_client.id
Beispiel #6
0
def signup(**kwargs):
    """
    Signup new subscription.
    """
    if organization_name_exists(kwargs['name']):
        raise ValueError('Organization name already exists')

    if email_exists(kwargs['email']):
        raise ValueError('Email already exists')

    if 'phone_number' in kwargs\
            and phone_number_exists(kwargs['phone_number']):
        raise ValueError('Phone number already exists')

    if username_exists(kwargs['username']):
        raise ValueError('Username is already taken')

    file_number = kwargs.get('file_number', generate_file_number())
    if file_number_exists(file_number):
        raise ValueError('File number already exists')

    new_organization = create_organization(
        organization_name=kwargs['name'],
        address=kwargs.get('address', None))

    new_user = create_user(
        organization_id=new_organization.id,
        username=kwargs['username'],
        password=kwargs['password'],
        email=kwargs['email'],
        phone_number=kwargs.get('phone_number', None))

    administrator_role = RoleRepository.get_by_name('administrator')

    UserRoleRepository.create(
        UserRole(user_account_id=new_user.id, role_id=administrator_role.id))

    new_employee = Employee(
        file_number=file_number,
        first_name=kwargs['first_name'],
        last_name=kwargs['last_name'],
        user_account_id=new_user.id,
        organization_id=new_organization.id,
        other_names=kwargs.get('other_names', None))
    EmployeeRepository.create(new_employee)

    recipients = [kwargs['email'], ]
    subject = f'Welcome to ResourceIdea'
    token = generate_token(user_id=new_user.id, email=new_user.email)
    body_html = render_template(
        'email/welcome.html',
        confirmation_token=token,
        first_name=kwargs['first_name'],
        last_name=kwargs['last_name'])
    body_text = render_template(
        'email/welcome.txt',
        confirmation_token=token,
        first_name=kwargs['first_name'],
        last_name=kwargs['last_name'])

    send_email(recipients, subject, body_text, body_html)

    return new_organization, new_user