コード例 #1
0
ファイル: tests.py プロジェクト: l-dfa/django-rstblog
    def test_article_creation_1(self):
        '''test article model creation missing mandatory field'''

        # test mandatory field, missing slug
        with self.assertRaises(Exception) as raised:
            t = Article(title=None, file='file', category=category)
            t.save()
        self.assertEqual("NOT NULL constraint failed: rstblog_article.title",
                         str(raised.exception))
コード例 #2
0
ファイル: tests.py プロジェクト: l-dfa/django-rstblog
    def test_article_creation_4(self):
        ''' test article creation '''

        a = Article(title='articolo',
                    file='file',
                    category=category,
                    slug='articolo')
        a.save()  # WARN: save before add ManyToMany rels
        self.assertIsInstance(a, Article)

        a_s = Article.objects.all()
        self.assertEqual(len(a_s), 2)
コード例 #3
0
ファイル: mkinitdb.py プロジェクト: l-dfa/base_rstblog
def add_articles():
    '''starting with one article '''

    #pdb.set_trace()
    for ad in ARTICLES:
        c = None
        if ad.get('category'):
            c = Category.objects.get(name=ad.get('category'))
        a = Article(
            title=ad.get('title'),
            file=ad.get('file'),
            slug=ad.get('slug'),
            summary=ad.get('summary'),
            category=c,
        )
        a.save()
        if ad.get('markup'):
            a.markup = ad.get('markup')
        if ad.get('language'):
            a.language = ad.get('language')
        if ad.get('created'):
            t = datetime.strptime(ad.get('created'), '%Y-%m-%d %H:%M:%S')
            t = pytz.timezone(settings.TIME_ZONE).localize(t)
            a.created = t
        if ad.get('authors'):
            for auth in ad.get('authors'):
                author = None
                try:
                    author = Author.objects.get(name=auth)
                except:
                    pass
                if author:
                    a.authors.add(author)  # WARN: ManyToMany uses id
        if ad.get('author'):
            author = None
            try:
                author = Author.objects.get(name=ad.get('author'))
            except:
                pass
            if author:
                a.authors.add(author)  # WARN: ManyToMany uses id
        if ad.get('translation_of'):
            original = None
            try:
                original = Article.objects.get(title=ad.get('translation_of'))
            except:
                pass
            if original:
                a.translation_of = original
        a.save()
コード例 #4
0
ファイル: tests.py プロジェクト: l-dfa/django-rstblog
def setUpModule():
    '''test environment
    
    global _ENV describes it '''

    global author
    global article
    global category

    # redirect configuration directories to testcontents/...
    settings.MEDIA_ROOT = MEDIA_ROOT
    settings.RSTBLOG = RSTBLOG
    settings.RSTSITE = RSTSITE

    #pdb.set_trace()
    with P_ARTICLE.open(mode='wb') as article:
        article.write(ARTICLE_IT.encode('utf-8'))
    with P_ARTICLE1.open(mode='wb') as article:
        article.write(ARTICLE_IT.encode('utf-8'))
    with P_ARTICLE2.open(mode='wb') as article:
        article.write(ARTICLE_EN.encode('utf-8'))

    User.objects.create_superuser(username='******',
                                  password='******',
                                  email='*****@*****.**')

    author = Author(
        username='******',
        name='Antonio Biagi',
    )
    author.save()

    category = Category(name='uncategorized', )
    category.save()

    article = Article(
        title='un saggio di a.biagi',
        file='saggio_biagi.txt',
        category=category,
        slug='saggio_biagi',
    )
    article.save()
    article.authors.add(author)