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
def test_get_client_industry(session, fake_lorem):
    """Test querying for a client industry."""

    # Arrange
    fake_model = create_client_industry(name=fake_lorem.word())

    # Act
    result = get_client_industry(fake_model.id)

    # Assert
    assert result is not None
    assert isinstance(result, ClientIndustry)
    assert result == fake_model
def test_update_raises_value_error_exception(session, fake_lorem):
    """Test update raises ValueError exception when invalid
    data is supplied"""

    # Arrange
    test_model = create_client_industry(name=fake_lorem.word())
    updates = {
        'name': 'Existing name',
    }

    # Assert
    with pytest.raises(ValueError):
        update_client_industry(test_model.id, **updates)
def test_update(session, fake_lorem):
    """Test updating a client industry"""
    # Arrange
    test_model = create_client_industry(name=fake_lorem.word())
    updates = {
        'name': 'Changed name',
    }

    # Act
    result = update_client_industry(test_model.id, **updates)

    # Assert
    assert isinstance(result, ClientIndustry)
    assert test_model.id == result.id
示例#5
0
 def post(self):
     """HTTP POST method handler."""
     payload = request.json
     valid_input = ClientIndustrySchema(strict=True)\
         .load(payload).data
     try:
         new_client_industry = create_client_industry(**valid_input)
     except ValueError as error:
         output = json.dumps({'message': str(error)})
         self.status_code = 400
     else:
         output = ClientIndustrySchema(strict=True)\
             .dump(new_client_industry).data
         self.status_code = 201
     return output, self.status_code
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