Beispiel #1
0
def do_import_reco(file_path) -> Recommendation:
    reco_dataframe = pd.read_csv(file_path)
    total_reco = new_reco = 0

    for row in reco_dataframe.itertuples():
        if str(row.benefit) == 'nan':
            continue
        reco = Recommendation.query.get(row.id)
        if not reco:
            reco = Recommendation()
            reco.id = row.id
            new_reco += 1

        reco.title = row.title
        if str(row.content) != 'nan':
            reco.content = row.content
        # TODO: temporary with set a default value
        else:
            reco.content = "Contenu non défini"
        if str(row.benefit) != 'nan':
            reco.benefit = row.benefit
        else:
            reco.benefit = 0.0
        if str(row.benefit_description) != 'nan':
            reco.benefit_description = row.benefit_description
        if str(row.how_to) != 'nan':
            reco.how_to = row.how_to
        reco.type = FootprintType({'label': row.category})
        total_reco += 1
        BaseObject.check_and_save(reco)

    print('Recommendations updated : %s' % str(total_reco - new_reco))
    print('Recommendations created : %s' % new_reco)
    def test_recommend_add_remove(self):

        new_user = User(
            username='******',
            first_name='rec',
            last_name='user',
            password='******',
            email='*****@*****.**',
        )
        new_user.id = 11114
        db.session.add(new_user)

        new_rec = Recommendation(recommender_id=11114,
                                 recommend_to_user_id=11111,
                                 drink_id=1)
        new_rec.id = 10000
        db.session.add(new_rec)

        rec = Recommendation.query.get(10000)

        self.assertEqual(rec.id, 10000)
        self.assertEqual(rec.recommender_id, 11114)
        self.assertEqual(rec.recommend_to_user_id, 11111)
        self.assertEqual(rec.drink_id, 1)

        db.session.delete(rec)
        db.session.commit()

        check_rec = Recommendation.query.get(10000)

        self.assertEqual(check_rec, None)
    def test_delete_recommend_post(self):
        with self.client as client:
            with client.session_transaction() as sess:
                sess[KEY]=999

            new_user = User(
                id=1002,
                username='******',
                first_name='test',
                last_name='user3',
                password='******',
                email='*****@*****.**',
            )

            db.session.add(new_user)

            new_recommend = Recommendation(recommender_id=1002, recommend_to_user_id=999, drink_id='1')
            rec_id = 9999
            new_recommend.id = rec_id
            db.session.add(new_recommend)

            resp = client.post('/user/recommendations', json={'recId': 9999}, follow_redirects=True)

            self.assertIn("You don\\\'t have any recommendations yet", str(resp.data))
            
            del_new_user = User.query.get(1002)
            db.session.delete(del_new_user)
Beispiel #4
0
def create_recommendation(offer=None, user=None, mediation=None, idx=None, date_read=None,
                          valid_until_date=datetime.utcnow() + timedelta(days=7), search=None,
                          is_clicked=False):
    recommendation = Recommendation()
    recommendation.id = idx
    recommendation.offer = offer
    recommendation.user = user
    recommendation.mediation = mediation
    recommendation.dateRead = date_read
    recommendation.validUntilDate = valid_until_date
    recommendation.search = search
    recommendation.isClicked = is_clicked
    return recommendation