コード例 #1
0
 def test_put_banner(self):
     self.bs.put_banner(
         Banner('http://banners.com/banner3.jpg', 5, ['new category']))
     assert len(self.bs.store) == 8
     self.bs.put_banner(
         Banner('http://banners.com/banner4.jpg', 5, ['new category']))
     assert len(self.bs.store) == 8
コード例 #2
0
 def test_remove_empty_categories(self):
     banner = Banner('http://banners.com/banner3.jpg', 5, ['new category'])
     self.bs.put_banner(banner)
     self.bs.remove_banner(banner)
     assert len(self.bs.store) == 8
     self.bs.remove_empty_categories(banner.categories)
     assert len(self.bs.store) == 7
コード例 #3
0
class TestBanner:
    url = 'localhost/banner1.jpg'
    shows = 10
    category1 = 'category1'
    category2 = 'category2'
    categories = [category1, category2]

    def setup(self):
        self.banner = Banner(TestBanner.url, TestBanner.shows,
                             TestBanner.categories)

    def test_init(self):
        assert self.banner.url == TestBanner.url
        assert self.banner.shows == TestBanner.shows
        assert self.banner.categories == TestBanner.categories

    def test_str(self):
        assert f'{self.banner.url}: {self.banner.shows}' == str(self.banner)

    def test_show(self):
        assert self.banner.show() == TestBanner.shows - 1
        assert self.banner.show() == TestBanner.shows - 2
コード例 #4
0
from main import Team, Banner

for team in Team.all():
    team.delete()

for banner in Banner.all():
    banner.delete()

teams = [
    'Arsenal',
    'Aston Villa',
    'Birmingham City',
    'Blackburn Rovers',
    'Blackpool',
    'Bolton Wanderers',
    'Chelsea',
    'Everton',
    'Fulham',
    'Liverpool',
    'Manchester City',
    'Manchester United',
    'Newcastle United',
    'Stoke City',
    'Sunderland',
    'Tottenham Hotspur',
    'West Bromwich Albion',
    'West Ham United',
    'Wigan Athletic',
    'Wolverhampton Wanderers',
]
コード例 #5
0
ファイル: populate.py プロジェクト: MagicPwn/Banter-Banners
    def get(self):
        
        resultlog = []
        
        for team in Team.all():
            team.delete()

        for banner in Banner.all():
            banner.delete()

        teams = [
            'Arsenal',
            'Aston Villa',
            'Birmingham City',
            'Blackburn Rovers',
            'Blackpool',
            'Bolton Wanderers',
            'Chelsea',
            'Everton',
            'Fulham',
            'Liverpool',
            'Manchester City',
            'Manchester United',
            'Newcastle United',
            'Stoke City',
            'Sunderland',
            'Tottenham Hotspur',
            'West Bromwich Albion',
            'West Ham United',
            'Wigan Athletic',
            'Wolverhampton Wanderers',
        ]

        for team in teams:
            t = Team(name=team, key_name=team, enabled=True)
            t.put()
            resultlog.append('Team with name \"%s\" created.' %t.name)


        random_banter = [
            '%s fans should better find a new team.',
            'I can\'t understand how %s call themselves a team.',
            'A footbal team? I thought you said %s.',
        ]

        resultlog.append('')
        
        impressions = int(self.request.get('impressions', default_value=2000))
        
        for team in teams:
            for banter in random_banter:
                b = Banner(
                    copy = banter %team,
                    team = Team.get_by_key_name(team),
                    author_id = 'leoncoto',
                    impressions = impressions
                )
                b.put()
                resultlog.append('New banter banner')
                resultlog.append('Banter: %s' %b.copy)
                resultlog.append('Sent to: %s' %b.team.name)
                resultlog.append('Impressions left: %i' %b.impressions)
                resultlog.append('')
            resultlog.append('')   

        template_values = {'resultlog' : resultlog }
        path = os.path.join(os.path.dirname(__file__), 'templates/pupulate.html')
        template_render = template.render(path, template_values)
        self.response.out.write(template_render)        
コード例 #6
0
    def get(self):

        resultlog = []

        for team in Team.all():
            team.delete()

        for banner in Banner.all():
            banner.delete()

        teams = [
            'Arsenal',
            'Aston Villa',
            'Birmingham City',
            'Blackburn Rovers',
            'Blackpool',
            'Bolton Wanderers',
            'Chelsea',
            'Everton',
            'Fulham',
            'Liverpool',
            'Manchester City',
            'Manchester United',
            'Newcastle United',
            'Stoke City',
            'Sunderland',
            'Tottenham Hotspur',
            'West Bromwich Albion',
            'West Ham United',
            'Wigan Athletic',
            'Wolverhampton Wanderers',
        ]

        for team in teams:
            t = Team(name=team, key_name=team, enabled=True)
            t.put()
            resultlog.append('Team with name \"%s\" created.' % t.name)

        random_banter = [
            '%s fans should better find a new team.',
            'I can\'t understand how %s call themselves a team.',
            'A footbal team? I thought you said %s.',
        ]

        resultlog.append('')

        impressions = int(self.request.get('impressions', default_value=2000))

        for team in teams:
            for banter in random_banter:
                b = Banner(copy=banter % team,
                           team=Team.get_by_key_name(team),
                           author_id='leoncoto',
                           impressions=impressions)
                b.put()
                resultlog.append('New banter banner')
                resultlog.append('Banter: %s' % b.copy)
                resultlog.append('Sent to: %s' % b.team.name)
                resultlog.append('Impressions left: %i' % b.impressions)
                resultlog.append('')
            resultlog.append('')

        template_values = {'resultlog': resultlog}
        path = os.path.join(os.path.dirname(__file__),
                            'templates/pupulate.html')
        template_render = template.render(path, template_values)
        self.response.out.write(template_render)
コード例 #7
0
 def test_get_banner_by_category(self):
     banner = Banner('http://banners.com/banner3.jpg', 5, ['new category'])
     self.bs.put_banner(banner)
     assert self.bs.get_banner_by_category(banner.categories[0]) is banner
コード例 #8
0
 def test_is_category_empty(self):
     banner = Banner('http://banners.com/banner3.jpg', 5, ['new category'])
     self.bs.put_banner(banner)
     assert not self.bs.is_category_empty(banner.categories[0])
     self.bs.remove_banner(banner)
     assert self.bs.is_category_empty(banner.categories[0])
コード例 #9
0
 def test_remove_banner(self):
     banner = Banner('http://banners.com/banner3.jpg', 5, ['new category'])
     self.bs.put_banner(banner)
     self.bs.remove_banner(banner)
     assert self.bs.store['new category'] == []
コード例 #10
0
 def setup(self):
     self.banner = Banner(TestBanner.url, TestBanner.shows,
                          TestBanner.categories)