当前位置: 首页>>代码示例>>Python>>正文


Python Film.get_or_create_film_localized方法代码示例

本文整理汇总了Python中film20.core.models.Film.get_or_create_film_localized方法的典型用法代码示例。如果您正苦于以下问题:Python Film.get_or_create_film_localized方法的具体用法?Python Film.get_or_create_film_localized怎么用?Python Film.get_or_create_film_localized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在film20.core.models.Film的用法示例。


在下文中一共展示了Film.get_or_create_film_localized方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: BotHelperTestCase

# 需要导入模块: from film20.core.models import Film [as 别名]
# 或者: from film20.core.models.Film import get_or_create_film_localized [as 别名]
class BotHelperTestCase(TestCase):

    def initialize(self):
        self.clean_data()
        self.create_films()


    def clean_data(self):
        Film.objects.all().delete()
        ObjectLocalized.objects.all().delete()
        FilmLocalized.objects.all().delete()


    def create_films(self):
        self.film1 = Film()
        self.film1.title = "The Terminator"
        self.film1.type = Object.TYPE_FILM
        self.film1.permalink = "the-terminator"
        self.film1.release_year = 1984
        self.film1.save()

        self.film2 = Film()
        self.film2.title = "Rambo"
        self.film2.type = Object.TYPE_FILM
        self.film2.permalink = "rambo"
        self.film2.release_year = 1982
        self.film2.save()


    def test_fetch_synopses_for_films_no_localized_film_nosynopsisindb(self):
        """
            There are two films in db both without synopsis
        """

        self.initialize()

        # there are no LocalizedFilms
        self.assertEquals(FilmLocalized.objects.all().count(), 0)

        fetch_synopses_for_films_no_localized_film(0,50)

        # there are two localized films
        loc_films = FilmLocalized.objects.all()
        self.assertEquals(loc_films.count(), 2)

        # both localized films should have fetched_description
        # and shouldn't have description
        loc_film1 = loc_films[0]
        self.assertEquals(loc_film1.description is None, True)
        self.assertEquals(loc_film1.fetched_description is None, False)

        loc_film2 = loc_films[1]
        self.assertEquals(loc_film2.description is None, True)
        self.assertEquals(loc_film2.fetched_description is None, False)


    def test_fetch_synopses_for_films_no_localized_film_onesynopsisindb(self):
        """
            There are two films in db but only one with localized object
        """
        self.initialize()

        # creating localized film and setting description by user
        loc_film = self.film1.get_or_create_film_localized(LANG=LANGUAGE_CODE)
        loc_film.description = "film description added by user"
        loc_film.save()

        # there is one LocalizedFilm
        self.assertEquals(FilmLocalized.objects.all().count(), 1)

        fetch_synopses_for_films_no_localized_film(0,50)

        # there are two localized films now
        loc_films = FilmLocalized.objects.all()
        self.assertEquals(loc_films.count(), 2)

        # First localized film was created by user and should be
        # touched by synopsis_fetcher
        loc_film1 = loc_films[0]
        self.assertEquals(loc_film1.description is None, False)
        self.assertEquals(loc_film1.description, "film description added by user")
        self.assertEquals(loc_film1.fetched_description is None, True)

        # Second localized film was created by fetcher
        loc_film2 = loc_films[1]
        self.assertEquals(loc_film2.description is None, True)
        self.assertEquals(loc_film2.fetched_description is None, False)


    def test_fetch_synopses_for_films_no_localized_film_twosynopsisindb(self):
        """
            There are two films in db both with localized objects
        """
        self.initialize()

        # Creating localized films first by user, second one by fetcher
        loc_film = self.film1.get_or_create_film_localized(LANG=LANGUAGE_CODE)
        loc_film.description = "film1 description added by user"
        loc_film.save()

#.........这里部分代码省略.........
开发者ID:thuvh,项目名称:filmmaster,代码行数:103,代码来源:test_synopsis.py


注:本文中的film20.core.models.Film.get_or_create_film_localized方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。