예제 #1
0
    def test_save_sort_algo(self):
        client = self.create_dummy_client()

        dummy_form_data = {
            'title': 'Add Navbar',
            'description': 'We need to add a navbar',
            'target_date': datetime.date(datetime.today()),
            'client_priority': 1,
            'client': client,
            'product_areas': []
        }

        # create a feature with priority 1
        feature_1 = self.create_dummy_feature(client, priority=1)

        # create another feature with priority 1 using the algorithm

        Feature.save_sort_algo(dummy_form_data, db)

        # retrieve the feature created
        feature_2 = Feature.query.filter_by(title='Add Navbar').first()
        # confirm that the priority of the first feature is different from the the priority of the second feature
        assert (feature_1.client_priority != feature_2.client_priority)
        # confirm that the new feature takes the topmost priority
        assert (feature_2.client_priority == 1)
        # confirm that the old feature has it's priority increased by one
        assert (feature_1.client_priority == 2)
예제 #2
0
def index():
    """ The main view function, serves the home page of the dashboard and handles 3 forms for
    adding Features, adding Clients and adding Product Areas"""
    clients = Client.query.limit(3).all()
    products = ProductArea.query.order_by('id').limit(5).all()
    features = Feature.query.order_by('client_priority').limit(5).all()
    feature_form = FeatureForm()
    feature_form.populate_choices()
    client_form = ClientForm()
    product_form = ProductAreaForm()

    if feature_form.submit_feature.data and feature_form.validate():
        # Get the form data
        form_data = feature_form.get_data()
        # process the form data and check for existing client priority and reorder the priorities of older features if there is a clash of priorities
        Feature.save_sort_algo(form_data, db)

        return redirect(url_for('main.index'))

    if client_form.submit_client.data and client_form.validate():
        data = dict()
        data["name"] = client_form.name.data
        data["email"] = client_form.email.data
        c = Client(**data)
        db.session.add(c)
        db.session.commit()
        return redirect(url_for('main.index'))

    if product_form.submit_product.data and product_form.validate():
        data = dict()
        data["name"] = product_form.name.data
        p = ProductArea(**data)
        db.session.add(p)
        db.session.commit()
        return redirect(url_for('main.index'))

    return render_template('index.html',
                           product_list=products,
                           clients=clients,
                           features=features,
                           feature_form=feature_form,
                           client_form=client_form,
                           product_form=product_form)