def test_model_featured_community(app, db, communities): """Test the featured community model and actions.""" (comm1, comm2, comm3) = communities t1 = datetime.now() # Create two community featurings starting at different times fc1 = FeaturedCommunity(id_community=comm1.id, start_date=t1 + timedelta(days=1)) fc2 = FeaturedCommunity(id_community=comm2.id, start_date=t1 + timedelta(days=3)) db.session.add(fc1) db.session.add(fc2) # Check the featured community at three different points in time assert FeaturedCommunity.get_featured_or_none(start_date=t1) is None assert FeaturedCommunity.get_featured_or_none(start_date=t1 + timedelta(days=2)) is comm1 assert FeaturedCommunity.get_featured_or_none(start_date=t1 + timedelta(days=4)) is comm2
def load_featured(data): """Load community featuring from data dump. :param data: Dictionary containing community featuring data. :type data: dict """ obj = FeaturedCommunity(id=data['id'], id_community=data['id_community'], start_date=iso2dt(data['start_date'])) db.session.add(obj) db.session.commit()