示例#1
0
class ArticleTest(TestCase):
    def setUp(self):
        # create the objects needed
        self.client = Client()
        self.article = Article()

        self.user = User(username='******')
        self.user.set_password('google')
        self.user.is_active = True
        self.user.save()


    def tearDown(self):
        self.client = None
        self.article = None
        self.user = None

    def test_save(self):
        self.article.headline = 'Unit Testing'
        self.article.summary = 'Unit Testing'

        # required fields
        self.article.creator = self.user
        self.article.creator_username = self.user.username
        self.article.owner = self.user
        self.article.owner_username = self.user.username
        self.article.status = True
        self.article.status_detail = 'active'
        self.article.enclosure_length = 0
        self.article.timezone = 'America/Chicago'

        self.article.save()

        self.assertEquals(type(self.article.id), long)
示例#2
0
    def setUp(self):
        # create the objects needed
        self.client = Client()
        self.article = Article()

        self.user = User(username='******')
        self.user.set_password('google')
        self.user.is_active = True
        self.user.save()
示例#3
0
def get_posts(item, uri_parser, user):
    """
    If the given Article has already been created, skip it.
    If not, create Article object and Redirect object.
    """
    alreadyThere = False
    link = unicode(item.find('link').contents[0])
    slug = uri_parser.parse(link).path.strip('/')
    if not slug:
        # if no slug, grab the post id
        slug = unicode(item.find('wp:post_id').contents[0])

    for article in Article.objects.all():
        if article.slug == slug[:100]:
            alreadyThere = True
            break

    if not alreadyThere:
        title = unicode(item.find('title').contents[0])
        post_id = item.find('wp:post_id').string
        post_id = int(post_id)
        body = unicode(item.find('content:encoded').contents[0])
        body = replace_short_code(body)
        try:
            # There may not be a file associated with a post.
            # If so, catch that error.
            fgroup = AssociatedFile.objects.filter(post_id=post_id)
            for f in fgroup:
                body = correct_media_file_path(body, f.file)

        except:
            pass

        post_date = unicode(item.find('wp:post_date').contents[0])
        post_dt = datetime.strptime(post_date, '%Y-%m-%d %H:%M:%S')

        tags_raw = item.findAll('category', domain="post_tag")
        tags_list = []

        if tags_raw:
            for tag in tags_raw:
                if len(','.join(tags_list)) + len(tag.string) <= 255:
                    tags_list.append(tag.string[:50])

        article = {
            'headline': title,
            'guid': str(uuid.uuid1()),
            'slug': slug[:100],
            'body': body,
            'tags': ','.join(tags_list),
            'timezone': 'US/Central',
            'syndicate': True,
            'featured': False,
            'release_dt': post_dt,
            'creator': user,
            'creator_username': user.username,
            'allow_anonymous_view': True,
            'allow_user_view': False,
            'allow_member_view': False,
            'allow_anonymous_edit': False,
            'allow_user_edit': False,
            'allow_member_edit': False,
            'owner': user,
            'owner_username': user.username,
            'status': True,
            'status_detail': 'active'
        }

        redirect = {
            'from_url': slug[:100],
            'to_url': os.path.join('articles', slug[:100])
        }

        a = Article(**article)
        a.save()

        r = Redirect(**redirect)
        r.save()
示例#4
0
def get_posts(item, uri_parser, user):
    """
    If the given Article has already been created, skip it.
    If not, create Article object and Redirect object.
    """
    alreadyThere = False
    link = unicode(item.find('link').contents[0])
    slug = uri_parser.parse(link).path.strip('/')
    if not slug:
        # if no slug, grab the post id
        slug = unicode(item.find('wp:post_id').contents[0])

    for article in Article.objects.all():
        if article.slug == slug[:100]:
            alreadyThere = True
            break
    
    if not alreadyThere:
        title = unicode(item.find('title').contents[0])
        post_id = item.find('wp:post_id').string
        post_id = int(post_id)
        body = unicode(item.find('content:encoded').contents[0])
        body = replace_short_code(body)
        try:
            # There may not be a file associated with a post.
            # If so, catch that error.
            fgroup = AssociatedFile.objects.filter(post_id=post_id)
            for f in fgroup:
                body = correct_media_file_path(body, f.file)

        except:
            pass

        post_date = unicode(item.find('wp:post_date').contents[0])
        post_dt = datetime.strptime(post_date, '%Y-%m-%d %H:%M:%S')
        
        tags_raw = item.findAll('category', domain="post_tag")
        tags_list = []
    
        if tags_raw:
            for tag in tags_raw:
                if len(','.join(tags_list)) + len(tag.string) <= 255:
                    tags_list.append(tag.string[:50])
    
        article = {
            'headline': title,
            'guid': str(uuid.uuid1()),
            'slug': slug[:100],
            'body': body,
            'tags': ','.join(tags_list),
            'timezone': 'US/Central',
            'syndicate': True,
            'featured': False,
            'release_dt': post_dt,
            'creator': user,
            'creator_username': user.username,
            'allow_anonymous_view': True,
            'allow_user_view': False,
            'allow_member_view': False,
            'allow_anonymous_edit': False,
            'allow_user_edit': False,
            'allow_member_edit': False,
            'owner': user,
            'owner_username': user.username,
            'status': True,
            'status_detail': 'active'
        }

        redirect = {
            'from_url': slug[:100],
            'to_url': os.path.join('articles', slug[:100])
        }

        a = Article(**article)
        a.save()

        r = Redirect(**redirect)
        r.save()