Exemple #1
0
def test_flask_seed_model_cli_seeds_to_db_with_all_option(cli_app):
    """
    Tests that db tables are populated `flask seed model` when passed an `all`
    option.

    Args:
        cli_app (function): a flask app factory function that also manages its
            context.
    """
    # Create a script for running application.
    obj = ScriptInfo(create_app=cli_app)

    # Call command, apply arguments and create app.
    result = CliRunner().invoke(seed_model, ['all'], obj=obj)

    clients = Client.get_all()
    staff = Staff.get_all()
    requests = Request.get_all()
    comments = Comment.get_all()

    assert len(clients) == 3
    assert len(staff) == 3
    assert len(comments) == 14
    assert len(requests) == 12
    assert result.exit_code == 0
def test_staff_model_gets_all_rows_correctly_after_saving(valid_staff_model):
    """
    Tests that model gets correct number of rows when there is data in the
    table.

    Args:
        valid_staff_model (Model): a valid model created by a fixture.
    """
    staffs = Staff.get_all()

    assert staffs[0].username == 'Leroy Jenkins'
    assert staffs[0].avatar_url == ''
    assert len(staffs) == 1
Exemple #3
0
def test_seed_staff_saves_staffs_to_db(initialize_db):
    """
    Tests that `seed_staff` function stores staffs in the db.

    Args:
        initialize_db (None): initializes the database and drops tables when
            test function finishes.
    """
    seed_staff()

    staff = Staff.get_all()

    assert staff[0].username == 'Steve Akinyemi'
    assert staff[1].username == 'Anu Johnson'
    assert staff[2].username == 'James Waldo'
    assert len(staff) == 3
Exemple #4
0
def test_flask_seed_model_cli_seeds_to_db_with_staff_option(cli_app):
    """
    Tests that staff table is populated `flask seed model` when passed a
    `staff` option.

    Args:
        cli_app (function): a flask app factory function that also manages its
            context.
    """
    # Create a script for running application.
    obj = ScriptInfo(create_app=cli_app)

    # Call command, apply arguments and create app.
    result = CliRunner().invoke(seed_model, ['staff'], obj=obj)

    staffs = Staff.get_all()

    assert len(staffs) == 3
    assert result.exit_code == 0