Example #1
0
def create_news():
    if current_user:
        form = NewsForm()
        if form.validate_on_submit():
            article = Articles()
            article.title = form.title.data
            article.heading = form.heading.data
            article.content = form.content.data
            article.category = form.category.data[0]
            article.likes = 0
            article.dislikes = 0

            if request.files["file"]:
                file = request.files["file"]
                article.image = current_user.username + secure_filename(
                    file.filename)
                f = open(
                    current_app.config['UPLOAD_FOLDER'] +
                    current_user.username + file.filename, 'wb')
                f.write(file.read())
                f.close()
            else:
                article.image = "nophoto.jpg"

            current_user.article.append(article)
            db.session.merge(current_user)
            db.session.commit()
            return redirect('/')
        return render_template('news_create.html',
                               title='Добавление новости',
                               form=form)
Example #2
0
class TestArticle(unittest.TestCase):
    def setUp(self):
        self.new_articles = Articles("title",
                                     "https://image.tmdb.org/t/ptfukyy",
                                     "article", '2020', 'news', 'date')

    def tearDown(self):
        '''
        tearDown method that does clean up after each test case has run.
        '''
        Articles.all_articles = []

    def test_instance(self):
        self.assertTrue(isinstance(self.new_articles, Articles))

    def test_check_instance_variables(self):
        self.assertEquals(self.new_articles.title, 'title')
        self.assertEquals(self.new_articles.image, "2020")
        self.assertEquals(self.new_articles.description, 'article')
        self.assertEquals(self.new_articles.date, 'date')
        self.assertEquals(self.new_articles.articles, 'news')

    def test_save_articles(self):
        '''
        test_save_article test case to test if the article object is saved into
         the article list
        '''
        self.new_articles.save_articles()  # saving the new article
        self.assertEqual(len(Articles.all_articles), 1)
 def setUp(self):
     '''
     Set up method to run before each test case
     '''
     self.new_article = Articles(
         'BBC News', 'EU acts against Poland judiciary reforms',
         'Unprecedented disciplinary measures are taken as the EU says the reforms threaten the rule of law.',
         'https://ichef.bbci.co.uk/news/1024/cpsprodpb/F046/production/_98901516_2efffed4-d4a6-486a-8a78-112232b92faa.jpg',
         'http://www.bbc.co.uk/news/world-europe-42420150',
         '2017-12-20T13:36:14Z')
Example #4
0
 def setUp(self):
     '''
     Set up method that will run before every Test
     '''
     self.new_article = Articles(
         'Harry Domanski',
         'Samsung`s next smartphone could have a pop-up selfie camera - TechRadar India',
         'Leaked renders show every angle of potential new handset',
         'https://cdn.mos.cms.futurecdn.net/9W2JuazWDRjWaRMUi2dCPc-1200-80.jpg',
         'https://www.techradar.com/news/samsungs-next-smartphone-could-have-a-pop-up-selfie-camera',
         '2020-04-27T03:16:00Z')
Example #5
0
    def test_creating_a_new_article(self):
        article = Articles(title="This is title", body="This is body", slug="this is slug", created=datetime.now())
        article.save()

        articles_in_database = Articles.objects.all()
        self.assertEqual(len(articles_in_database), 1)
        only_article_in_database = articles_in_database[0]
        self.assertEqual(only_article_in_database, article)

        self.assertEqual(only_article_in_database.title, "This is title")
        self.assertEqual(only_article_in_database.body, "This is body")
Example #6
0
    def test_creating_a_new_article(self):
        article = Articles()
        article.title = "This is title"
        article.body = "This is body"
        article.save()

        articles_in_database = Articles.objects.all()
        self.assertEquals(len(articles_in_database), 1)
        only_article_in_database = articles_in_database[0]
        self.assertEquals(only_article_in_database, article)

        self.assertEquals(only_article_in_database.title, "This is title")
        self.assertEquals(only_article_in_database.body, "This is body")
Example #7
0
def post_articles():
    data, _ = create_article_serializer.loads(request.data)
    article = Articles(**data['attributes'])
    relationships = data['relationships']
    if current_user.is_admin:
        article.authorId = relationships['author']['id']
    else:
        article.authorId = current_user.id
    article.categoryId = data['relationships']['category']['id']
    db.session.add(article)
    db.session.commit()

    response = jsonify(data=create_article_serializer.dump(article).data)
    response.status_code = 201
    return response
Example #8
0
 def setUp(self):
     '''
     '''
     self.new_article = Articles(
         'Trump blasts left-wing cultural revolution', 'linda',
         'this is a description', 'https://www.google.com',
         'https://www.google.com/image', '2020-07-04T12:34:51Z')
Example #9
0
def addpost():
		title = request.form['title']
		description = request.form['description']
		post = Articles(title=title, description=description, author_id=current_user.get_id())
		db.session.add(post)
		db.session.commit()
		return render_template('detail.html', article=post)
 def test_article(self):
     '''
     test_source checks that new news source objects are created and instantiated
     '''
     self.new_article = Articles('me', 'bbc-news', 'Jesus', 'is alive',
                                 'eng', 'kenya', 'no', 'who')
     self.assertTrue(isinstance(self.new_article, Articles))
Example #11
0
 def setUp(self):
     '''
     will run before every test 
     '''
     self.new_articles = Articles('id', 'name', 'author', 'title',
                                  'description', 'url', 'urlToImage',
                                  'publishedAt')
Example #12
0
 def setUp(self):
     self.new_article = Articles(
         "bluebird", "The Bluebird",
         "The Eastern Bluebird is a small thrush with a big, rounded head, large eye, plump body, and alert posture",
         "https://techcrunch.com/2017/10/21/antisocial-media/",
         "https://tctechcrunch2011.files.wordpress.com/2017/10/img_6450.jpg",
         "2017-10-21T11:00:53Z")
 def setUp(self):
     self.new_article = Articles(
         "Skip the holiday rush this year — for the planet’s sake",
         "Spend some time making a sumptuous, low-carbon chili instead.",
         "http://grist.org/article/skip-the-holiday-rush-this-year-for-the-planets-sake/",
         "Chip Giller",
         "https://grist.files.wordpress.com/2019/11/balloon-package.jpg?w=1200&h=675&crop=1",
         "2019-11-16T12:02:05Z")
 def setUp(self):
     '''
     Test class to run before other tests
     '''
     self.new_article = Articles('Title goes here', 'Title is great ...',
                                 'https://google.com/images',
                                 '2018-05-12T13:31:03Z', 'liz',
                                 'buzzfeed.com')
Example #15
0
 def setUp(self):
     '''method that will run before each test case'''
     self.new_articles = Articles(
         "Samsung's Galaxy S10 may come with a cryptocurrency wallet",
         "Mashable",
         "https://mashable.com/article/samsung-galaxy-s10-cryptocurrency-wallet/",
         "https://mondrian.mashable.com/2019%252F01%252F24%252F07%252Fd88ec3acacbf4ece9690976e46226739.929b8.jpg%252F1200x630.jpg?signature=vZHMmpaeesKIQJm_5crpQH-GlIQ=,'https://cnet4.cbsistatic.com/img/ZBhDBbHH44bcXii1YC6Vkqf4p_U=/724x407/2018/12/11/e850b2b2-2ffc-4984-af8a-09a59cbffcb2/iphone-se-1.jpg",
         "2019-01-24T08:49:14Z")
Example #16
0
 def setUp(self):
     '''
     Set up method that will run before every Test
     '''
     self.new_article = Articles('mark', "bitcoin review",
                                 'bitcoin news from relevant authorities',
                                 "en", "2018-09-01T06:27:00Z",
                                 "http://foxnews.com/img345.jpg")
 def setUp(self):
     """
     Set up method that will run before every Test
     """
     self.new_article = Articles(
         "CNN",
         "Teen sensation Mason Greenwood boosts Manchester United's Champions League hopes"
     )
Example #18
0
 def setUp(self):
     '''
     Set up method that will run before every Test
     '''
     self.new_article = Articles(
         'CNN', 'lg', 'The tech scene in Africa-Is it the next big thing?',
         'A look at various tech hubs in Africa and the impact they have on the worlds economy',
         'techie.com', 'techie.com/lg.jpg', '2019-04-14')
Example #19
0
 def setUp(self):
     '''
 method that runs before each test case
 '''
     self.new_article = Articles(
         "Beth", "New Quiz",
         "Some Americans can resume going to restaurants", "24/2/2020",
         "bbc-news.com", "we cant wait")
Example #20
0
 def setUp(self):
     '''
     Set up method that will run before every Test
     '''
     self.new_article = Articles(
         'CNN', 'joe', 'Big five',
         'The wilds biggest creatures you dont want to encounter at night',
         'kws.com', 'kws.com/wild1.png', '2020-11-11T13:57:16Z')
Example #21
0
 def setUp(self):
     '''
     Set up method that will run before every Test
     '''
     self.new_articles = Articles(1234, 'Python Must Be Crazy',
                                  'A thrilling new Python Series',
                                  '/khsjha27hbs', 8.5, 129993,
                                  'ffffffffffff', 'date')
Example #22
0
 def setUp(self):
     '''
     Test class to run before other tests
     '''
     self.new_article = Articles('evelyne', 'news', 'technology',
                                 'https://google.com',
                                 'https://google.com/images',
                                 '2018-05-12T13:31:03Z')
Example #23
0
 def setUp(self):
     '''
     Test class to run before other tests
     '''
     self.new_article = Articles('Alex', 'Tech is great',
                                 'Advanced technology improving life',
                                 'https://twiter.com',
                                 'https://google.com/images')
Example #24
0
 def setUp(self):
     '''
     Set up method that will run before every Test
     '''
     self.new_articles = Articles(
         'bbc-news', 'lorrrrrm', 'musseum.', 'https://abcnews.go.com',
         'https://ichef.bbci.co.uk/news/1024/branded_news/C9B3/production/_113253615_tv062312827.jpg',
         '2020')
Example #25
0
 def setUp(self):
     '''
     Test Class to test the behaviour of the Article class
     '''
     self.new_articles = Articles("Samuel Aronda", "Flask",
                                  "Great to begin Flask",
                                  "https://www.url.com",
                                  "https://url/sa.jpg", "2020-01-27")
 def setUp(self):
     '''
     Set up method that will run before every Test
     '''
     self.new_source = Articles(
         134, "abc", "trump visita japan", "abc.com",
         "https://www.abc.net.au/news/image/11232934-16x9-700x394.jpg",
         "japan to welcome trump", "2019-06-23T08:31:32Z")
Example #27
0
    def setUp(self):
        """
    Set up method that will run before every class
    """

        self.new_source = Articles('John Terry', 'ABC News',
                                   'https://www.abc.com', 'https://image.com',
                                   'April 12 2001', 'Good work')
Example #28
0
 def setUp(self):
     '''
     Set up method that will run before every Test
     '''
     self.new_article = Articles(
         'wired', 'Peter Polle', 'Hackers exploiting druplageddon',
         'Hackers exploiting druplageddon to set up DDOS botnets like mirai',
         'wired.com', 'wired.com/7643t94.jpg', '2018-03-11T07:48:16Z')
Example #29
0
 def setUp(self):
     '''
     Set up method that will run before every Test
     '''
     self.new_article = Articles(
         'CNN', 'Amira Mugure', 'Centonomy should help Africa grow',
         'A look at how centonomy can grow Africas blue economy',
         'centonomy.com', 'centonomy.com/1245.jpeg', '2018-11-14T10:57:16Z')
Example #30
0
 def setUp(self):
     '''
     Test class to run before other tests
     '''
     self.new_article = Articles('Claudine', 'News', 'Science',
                                 'https://google.com',
                                 'https://google.com/images',
                                 '2020-11-24 T13:31:03Z')
Example #31
0
 def setUp(self):
     '''
     Set up method that will run before every test
     '''
     self.new_article = Articles(
         "Title of the article", 'description of the article',
         'https://abcnews.go.com/theview/video/andrea-kelly-details-allegations-abuse-husband-kelly-58286731',
         'https://s.abcnews.com/images/theview/181004_view_andrea_1134_hpMain_16x9_992.jpg'
     )
Example #32
0
 def setUp(self):
     '''
     Test class to run before other tests
     '''
     self.new_article = Articles(
         1, 'kyle', 'Kenyan Man breaks world record',
         'Kipchoge breaks the world record on 2 hour marathon',
         'https://techtoday.com', 'https://marathons.com/images',
         '2019-010-21T14:50:05Z')
 def setUp(self):
     '''
     Set up method that will run before every Test
     '''
     self.new_article = Articles(
         'CNN', 'James Gathuru',
         'The tech scene in Africa-Is it the next big thing?',
         'A look at various tech hubs in Africa and the impact they have on the worlds economy',
         'techie.com', 'techie.com/7643t94.jpg', '2019-05-18T23:47:16Z')
Example #34
0
 def test_creating_a_new_article(self):
     article = Articles(title="This is title", body="This is body", slug="this is slug", created=timezone.now())
     article.save()
Example #35
0
    dateCreated = fields.DateTime()
    lastModified = fields.DateTime()

    class Meta:
        fields = Articles.all_columns


article_serializer = ArticleSchema()


class ArticleResourceSchema(ResourceSchema):
    class Meta:
        type = 'articles'


create_article_serializer = ArticleResourceSchema(
    ArticleSchema, param={'only': Articles.get_columns(Method.CREATE, Role.USER)}
)

read_article_serializer = ArticleResourceSchema(
    ArticleSchema, param={'only': Articles.get_columns(Method.READ, Role.GUEST)}
)

update_article_serializer = ArticleResourceSchema(
    ArticleSchema, param={'only': Articles.get_columns(Method.UPDATE, Role.USER)}
)

delete_article_serializer = ArticleResourceSchema(
    ArticleSchema, param={'only': Articles.get_columns(Method.DELETE, Role.USER)}
)