Example #1
0
def test_staff_model_does_not_find_row_if_it_does_not_exist(initialize_db):
    """
    Tests that model does not find row correctly if it does not exist in
    the db.

    Args:
        initialize_db (None): initializes the database and drops tables when
            test function finishes.
    """
    with raises(ClientError) as err:
        Staff.find_by_id(1)

    assert err.value.message == 'cannot find specified staff'
    assert err.value.status_code == 404
Example #2
0
def test_staff_model_finds_row_if_it_exists(valid_staff_model):
    """
    Tests that model finds row correctly if it exists in the db.

    Args:
        valid_staff_model (Model): a valid model created by a fixture.
    """
    staff = Staff.find_by_id(1)

    assert staff.username == 'Leroy Jenkins'
    assert staff.avatar_url == ''
Example #3
0
def test_staff_model_updates_correctly_if_it_exists(valid_staff_model):
    """
    Tests that model __repr__ row correctly.

    Args:
        valid_staff_model (Model): a valid model created by a fixture.
    """
    valid_staff_model.update(username="******")

    updated_staff = Staff.find_by_id(1)

    assert updated_staff.username == 'Leroy Jenkins'
Example #4
0
    def get(self, staff_id):
        """
        Gets the staff with the specified id.

        Args:
            staff_id (int): staff id to fetch.
        """
        # Get the requested staff
        staff = Staff.find_by_id(staff_id)

        # Create a serialization schema
        staff_schema = StaffSchema(exclude=('created_at', 'updated_at'))

        return {
            'success': True,
            'message': messages['fetched']('staff'),
            'data': staff_schema.serialize(staff)
        }