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])
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)
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)
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')
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)
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)
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])
def test_field_creation_datetime_set_automatically(self): NewsPayload().blend()\ ._del_attribute('created-on-datetime')\ .post(user=self.admin)\ .assertCreationDateTime()
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)
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)
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')
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')
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)
def test_field_title_accept_unicode(self, title, expected): NewsPayload().blend()\ .set_title(title)\ .post(user=self.admin)\ .assertHasAttribute('title', expected)
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)
def test_field_title_cannot_be_blank(self, title): NewsPayload().blend()\ .set_title(title)\ .post(user=self.admin, code=422)\ .assertRaiseJsonApiError('/data/attributes/title')
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)
def test_field_content_is_mandatory(self): NewsPayload().blend()\ ._del_attribute('content')\ .post(user=self.admin, code=422)\ .assertRaiseJsonApiError('/data/attributes/content')
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)
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)
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)
def test_field_content_cannot_be_blank(self, content): NewsPayload().blend()\ .set_content(content)\ .post(user=self.admin, code=422)\ .assertRaiseJsonApiError('/data/attributes/content')
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")
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")
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)
def test_field_author_enforced_to_current_user_if_undefined(self): NewsPayload().blend()\ ._del_relationships('author')\ .post(user=self.admin)\ .assertHasRelationshipAuthorData(self.admin.id)