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])
Exemple #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])
    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)
    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)
Exemple #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)
Exemple #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')
Exemple #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)
Exemple #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)
Exemple #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])
Exemple #11
0
 def test_field_creation_datetime_set_automatically(self):
     NewsPayload().blend()\
         ._del_attribute('created-on-datetime')\
         .post(user=self.admin)\
         .assertCreationDateTime()
Exemple #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)
Exemple #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)
Exemple #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')
Exemple #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')
Exemple #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)
Exemple #18
0
 def test_field_title_accept_unicode(self, title, expected):
     NewsPayload().blend()\
         .set_title(title)\
         .post(user=self.admin)\
         .assertHasAttribute('title', expected)
Exemple #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)
Exemple #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')
Exemple #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)
Exemple #22
0
 def test_field_content_is_mandatory(self):
     NewsPayload().blend()\
         ._del_attribute('content')\
         .post(user=self.admin, code=422)\
         .assertRaiseJsonApiError('/data/attributes/content')
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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')
Exemple #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")
Exemple #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")
Exemple #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)
Exemple #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)