def create_advertiser_ad(advertiser: Advertiser, init_clicks: int,
                          init_views: int):
     ad = Ad()
     ad.set_advertiser(advertiser)
     TestAd.add_clicks(ad, init_clicks)
     TestAd.add_views(ad, init_views)
     return ad
 def test_delete_fk(self):
     advertiser = Advertiser(name='hello')
     my_ad = Ad(advertiser=advertiser)
     Advertiser.get_objects().clear()
     try:
         my_ad.inc_clicks()
     except Exception:
         self.fail('failed to increase because of loss of fk')
Beispiel #3
0
from models import Advertiser
from models.ad import Ad

if __name__ == '__main__':
    advertiser1 = Advertiser('name1')
    advertiser2 = Advertiser('name2')
    ad1 = Ad(title='title1',
             image_url='image-url1',
             link='link1',
             advertiser=advertiser1)
    ad2 = Ad(title='title2',
             image_url='image-url2',
             link='link2',
             advertiser=advertiser2)
    ad2.describe_me()
    advertiser1.describe_me()
    ad1.inc_views()
    ad1.inc_views()
    ad1.inc_views()
    ad1.inc_views()
    ad2.inc_views()
    ad1.inc_clicks()
    ad1.inc_clicks()
    ad2.inc_clicks()
    print(advertiser2.get_name())
    advertiser2.set_name('new name')
    print(advertiser2.get_name())
    print(ad1.get_clicks())
    print(advertiser2.get_clicks())
    print(Advertiser.get_total_clicks())
    print(Advertiser.help())
Beispiel #4
0
from models.ad import Ad
from models.advertiser import Advertiser
from models.base_model import BaseAdvertising

if __name__ == '__main__':
    base_advertising = BaseAdvertising()

    advertiser_1 = Advertiser(1, 'name1')
    advertiser_2 = Advertiser(2, 'name2')

    ad_1 = Ad(1, 'title1', 'img_url1', 'link', advertiser_1)
    ad_2 = Ad(2, 'title1', 'img_url1', 'link', advertiser_2)

    print(base_advertising.describe_me(),
          ad_2.describe_me(),
          advertiser_1.describe_me(),
          sep='\n')

    ad_1.inc_views()
    ad_1.inc_views()
    ad_1.inc_views()
    ad_1.inc_views()
    ad_2.inc_views()
    ad_1.inc_clicks()
    ad_1.inc_clicks()
    ad_2.inc_clicks()

    print(advertiser_2.get_name())
    advertiser_2.set_name('new name')
    print(advertiser_2.get_name(),
          ad_1.get_clicks(),
 def re_init_models():
     Advertiser.get_objects().clear()
     Ad.get_objects().clear()
 def add_views(ad: Ad, views: int):
     for i in range(views):
         ad.inc_views()
 def add_clicks(ad: Ad, clicks: int):
     for i in range(clicks):
         ad.inc_clicks()