def test_subscribed_users_relationship(self):
        news = self.blend_news(author=self.user_1)
        news_subscription = self.blend_news_subscription(news=news)

        NewsPayload(_url_collection="/v1/news/{}/relationships/subscriptions".format(news.id))\
            .get_collection()\
            .assertHasDatas('news-subscription', [news_subscription.id])
示例#2
0
    def test_news_collection_can_be_accessed_as(self, username, expected):
        news = self.blend_news(author=self.user_1, count=3)
        user = getattr(self, username) if username else None

        response = NewsPayload()\
            .get_collection(user=user, code=expected)\
            .assertCount(3)

        response.data[0].assertHasPublicAttributes(news[0])
        response.data[1].assertHasPublicAttributes(news[1])
        response.data[2].assertHasPublicAttributes(news[2])
示例#3
0
    def test_news_comments_must_be_cleaned(self):
        news = self.blend_news()
        self.blend_news_comment(count=3)
        self.blend_news_comment(news=news, count=5)

        news_comment = db.session \
            .query(NewsComment) \
            .filter(NewsComment.news_id == news.id)
        self.assertEqual(news_comment.count(), 5)

        NewsPayload().delete(news.id, user=self.admin)
        self.assertEqual(news_comment.count(), 0)
示例#4
0
    def test_news_subscription_must_be_cleaned(self):
        news = self.blend_news()
        self.blend_news_subscription(count=2)
        self.blend_news_subscription(news=news, count=4)

        news_subscription = db.session \
            .query(NewsSubscription) \
            .filter(NewsSubscription.news_id == news.id)
        self.assertEqual(news_subscription.count(), 4)

        NewsPayload().delete(news.id, user=self.admin)
        self.assertEqual(news_subscription.count(), 0)
示例#5
0
 def test_geokret_patch_field_are_readonly(self):
     news = self.blend_news(
         comments_count=12,
         last_comment_datetime="2018-09-23T23:15:13",
         created_on_datetime="2018-09-23T23:15:14",
     )
     NewsPayload()\
         ._set_attribute('comments_count', 1000)\
         ._set_attribute('last_comment_datetime', "2018-09-23T23:13:36")\
         ._set_attribute('created_on_datetime', "2018-09-23T23:13:37")\
         .patch(news.id, user=self.admin)\
         .assertHasAttribute('comments-count', news.comments_count)\
         .assertHasAttributeDateTime('last-comment-datetime', news.last_comment_datetime)\
         .assertHasAttributeDateTime('created-on-datetime', news.created_on_datetime)
示例#6
0
 def test_field_content_cannot_be_blank(self, content):
     news = self.blend_news()
     NewsPayload()\
         .set_content(content)\
         .patch(news.id, user=self.admin, code=422)\
         .assertRaiseJsonApiError('/data/attributes/content')
示例#7
0
 def test_field_username_defaults_to_connected_username(self):
     news = self.blend_news()
     NewsPayload()\
         .set_username('')\
         .patch(news.id, user=self.admin)\
         .assertHasAttribute('username', self.admin.name)
示例#8
0
 def test_field_author_can_be_edited(self):
     news = self.blend_news()
     NewsPayload()\
         .set_author(self.user_1.id)\
         .patch(news.id, user=self.admin)\
         .assertHasRelationshipAuthorData(self.user_1.id)
示例#9
0
 def test_field_title_cannot_be_blank(self, title):
     news = self.blend_news()
     NewsPayload()\
         .set_title(title)\
         .patch(news.id, user=self.admin, code=422)\
         .assertRaiseJsonApiError('/data/attributes/title')
 def test_news_comments_relationship(self):
     news = self.blend_news(author=self.user_1)
     news_comment = self.blend_news_comment(news=news)
     NewsPayload(_url_collection="/v1/news/{}/relationships/comments".format(news.id))\
         .get_collection()\
         .assertHasDatas('news-comment', [news_comment.id])
示例#11
0
 def test_field_creation_datetime_set_automatically(self):
     NewsPayload().blend()\
         ._del_attribute('created-on-datetime')\
         .post(user=self.admin)\
         .assertCreationDateTime()
示例#12
0
 def test_field_username_doesnt_accept_html(self, username, expected):
     news = self.blend_news()
     NewsPayload()\
         .set_username(username)\
         .patch(news.id, user=self.admin)\
         .assertHasAttribute('username', expected)
 def test_author_relationship(self):
     news = self.blend_news(author=self.user_1)
     NewsPayload(_url="/v1/news/{}/relationships/author")\
         .get(news.id)\
         .assertHasData('user', news.author.id)
示例#14
0
 def test_news_details_via_news_subscriptions(self):
     news_subscription = self.blend_news_subscription()
     NewsPayload(_url="/v1/news-subscriptions/{}/news")\
         .get(news_subscription.id, user=self.user_2)\
         .assertHasPublicAttributes(news_subscription.news)
示例#15
0
 def test_news_details_via_news_subscriptions_unexistent(self):
     self.blend_news_subscription()
     NewsPayload(_url="/v1/news-subscriptions/{}/news")\
         .get(666, user=self.user_2, code=404)\
         .assertRaiseJsonApiError('news_subscription_id')
示例#16
0
 def test_news_details_via_news_comment_unexistent(self):
     self.blend_news_comment()
     NewsPayload(_url="/v1/news-comments/{}/news")\
         .get(666, user=self.user_2, code=404)\
         .assertRaiseJsonApiError('news_comment_id')
示例#17
0
 def test_news_details_via_news_comment(self):
     news_comment = self.blend_news_comment()
     NewsPayload(_url="/v1/news-comments/{}/news")\
         .get(news_comment.id, user=self.user_2)\
         .assertHasPublicAttributes(news_comment.news)
示例#18
0
 def test_field_title_accept_unicode(self, title, expected):
     NewsPayload().blend()\
         .set_title(title)\
         .post(user=self.admin)\
         .assertHasAttribute('title', expected)
示例#19
0
 def test_field_name_accept_unicode(self, title, expected):
     news = self.blend_news()
     NewsPayload()\
         .set_title(title)\
         .patch(news.id, user=self.admin)\
         .assertHasAttribute('title', expected)
示例#20
0
 def test_field_title_cannot_be_blank(self, title):
     NewsPayload().blend()\
         .set_title(title)\
         .post(user=self.admin, code=422)\
         .assertRaiseJsonApiError('/data/attributes/title')
示例#21
0
 def test_field_content_accept_unicode(self, content, expected):
     news = self.blend_news()
     NewsPayload()\
         .set_content(content)\
         .patch(news.id, user=self.admin)\
         .assertHasAttribute('content', expected)
示例#22
0
 def test_field_content_is_mandatory(self):
     NewsPayload().blend()\
         ._del_attribute('content')\
         .post(user=self.admin, code=422)\
         .assertRaiseJsonApiError('/data/attributes/content')
示例#23
0
 def test_field_username_enforced_to_current_user_if_undefined(self):
     NewsPayload().blend()\
         ._del_attribute('username')\
         .post(user=self.admin)\
         .assertHasAttribute('username', self.admin.name)
示例#24
0
 def test_field_username_can_be_overrided(self):
     NewsPayload().blend()\
         .set_username(self.user_1.name)\
         .post(user=self.admin)\
         .assertHasAttribute('username', self.user_1.name)
示例#25
0
 def test_as(self, username, expected):
     user = getattr(self, username) if username else None
     news = self.blend_news()
     NewsPayload().delete(news.id, user=user, code=expected)
示例#26
0
 def test_field_content_cannot_be_blank(self, content):
     NewsPayload().blend()\
         .set_content(content)\
         .post(user=self.admin, code=422)\
         .assertRaiseJsonApiError('/data/attributes/content')
示例#27
0
 def test_field_content_can_be_edited(self):
     news = self.blend_news()
     NewsPayload()\
         .set_content("New content")\
         .patch(news.id, user=self.admin)\
         .assertHasAttribute('content', "New content")
示例#28
0
 def test_field_username_can_be_edited(self):
     news = self.blend_news()
     NewsPayload()\
         .set_username("New username")\
         .patch(news.id, user=self.admin)\
         .assertHasAttribute('username', "New username")
示例#29
0
 def test_news_details_has_normal_attributes_as(self, username):
     user = getattr(self, username) if username else None
     news = self.blend_news(author=self.user_1)
     NewsPayload().get(news.id, user=user)\
         .assertHasPublicAttributes(news)
示例#30
0
 def test_field_author_enforced_to_current_user_if_undefined(self):
     NewsPayload().blend()\
         ._del_relationships('author')\
         .post(user=self.admin)\
         .assertHasRelationshipAuthorData(self.admin.id)