コード例 #1
0
 def test_update_article_record(self):
     client = get_test_graphql_client()
     context = get_query_context()
     context.user = self.mock_usr
     perm = Permission.objects.get(
         content_type=ContentType.objects.get_for_model(HomeArticle),
         codename="add_homearticle")
     self.mock_usr.user_permissions.add(perm)
     self.mock_usr.save()
     response = client.execute(
         self.TEST_CREATE_HOME_ARTICLE,
         variables={
             'title': self.TEST_ARTICLE_TITLE,
             'content': self.TEST_ARTICLE_CONTENT,
             'preview': self.TEST_ARTICLE_PREVIEW
         },
         context_value=context,
     )
     article = HomeArticle.objects.get(
         slug=response.get('data').get('createHomeArticle').get('slug'))
     response = client.execute(self.TEST_UPDATE_ARTICLE_RECORD,
                               variables={'pk': article.pk})
     assert response.get('data').get('updateArticleRecord').get(
         'state') is True
     response = client.execute(self.TEST_QUERY_ARTICLE_RECORD,
                               variables={'slug': article.slug})
     assert response.get('data').get('homeArticle').get('record').get(
         'count') == 1
コード例 #2
0
 def test_create_and_update_home_article(self):
     client = get_test_graphql_client()
     context = get_query_context()
     context.user = self.mock_usr
     perm = Permission.objects.get(
         content_type=ContentType.objects.get_for_model(HomeArticle),
         codename="add_homearticle")
     self.mock_usr.user_permissions.add(perm)
     perm = Permission.objects.get(
         content_type=ContentType.objects.get_for_model(HomeArticle),
         codename="change_homearticle")
     self.mock_usr.user_permissions.add(perm)
     self.mock_usr.save()
     client.execute(
         self.TEST_CREATE_HOME_ARTICLE,
         variables={
             'title': 'Previous',
             'content': '',
             'preview': ''
         },
         context_value=context,
     )
     article = get_object_or_None(HomeArticle, title='Previous')
     assert article
     response = client.execute(self.TEST_QUERY_HOME_ARTICLE,
                               variables={
                                   'slug': article.slug,
                               },
                               context_value=context)
     assert response.get('data').get('homeArticle') == {
         'title': 'Previous',
         'content': '',
         'preview': '',
         'author': {
             'username': self.TEST_MOCK_USERNAME
         }
     }
     response = client.execute(self.TEST_UPDATE_HOME_ARTICLE,
                               variables={
                                   'slug': article.slug,
                                   'title': self.TEST_ARTICLE_TITLE,
                                   'content': self.TEST_ARTICLE_CONTENT,
                                   'preview': self.TEST_ARTICLE_PREVIEW,
                                   'disable': False,
                               },
                               context_value=context)
     # After updated, refresh the slug
     article = get_object_or_None(HomeArticle, pk=article.pk)
     response = client.execute(self.TEST_QUERY_HOME_ARTICLE,
                               variables={'slug': article.slug},
                               context_value=context)
     assert response.get('data').get('homeArticle') == {
         'title': self.TEST_ARTICLE_TITLE,
         'content': self.TEST_ARTICLE_CONTENT,
         'preview': self.TEST_ARTICLE_PREVIEW,
         'author': {
             'username': self.TEST_MOCK_USERNAME
         }
     }
コード例 #3
0
 def test_query_disable_article(self):
     context = get_query_context()
     context.user = self.mock_usr
     self.test_article.disable = True
     self.test_article.save()
     client = get_test_graphql_client()
     response = client.execute(self.TEST_EXECUTE_QUERY,
                               variables={'slug': self.test_article.slug},
                               context_value=context)
     assert HomeArticleTest.get_response_result(response) is None
コード例 #4
0
 def test_query_user_article(self):
     client = get_test_graphql_client()
     response = client.execute(self.TEST_EXECUTE_QUERY,
                               variables={'pk': self.test_article.pk})
     assert UserArticleTest.get_response_result(response) == {
         'title': self.TEST_ARTICLE_TITLE,
         'content': self.TEST_ARTICLE_CONTENT,
         'author': {
             'username': self.TEST_MOCK_USERNAME
         }
     }
コード例 #5
0
 def test_query_home_article(self):
     client = get_test_graphql_client()
     response = client.execute(self.TEST_EXECUTE_QUERY,
                               variables={'slug': self.test_article.slug})
     assert HomeArticleTest.get_response_result(response) == {
         'title': self.TEST_ARTICLE_TITLE,
         'content': self.TEST_ARTICLE_CONTENT,
         'author': {
             'username': self.TEST_MOCK_USERNAME
         },
         'preview': self.TEST_ARTICLE_PREVIEW
     }
コード例 #6
0
 def create_test_article(self):
     client = get_test_graphql_client()
     context = get_query_context()
     context.user = self.mock_usr
     res = client.execute(self.TEST_CREATE_USER_ARTICLE,
                          variables={
                              'title': 'TestTitle',
                              'content': 'TestContent',
                          },
                          context_value=context)
     return UserArticle.objects.get(
         pk=res.get('data').get('createUserArticle').get('pk'))
コード例 #7
0
 def test_create_and_update_user_article(self):
     client = get_test_graphql_client()
     context = get_query_context()
     context.user = self.mock_usr
     response = client.execute(
         self.TEST_CREATE_USER_ARTICLE,
         variables={
             'title': 'Previous',
             'content': ''
         },
         context_value=context,
     )
     article = get_object_or_None(UserArticle, title='Previous')
     assert article and article.pk == int(
         response.get('data').get('createUserArticle').get('pk'))
     response = client.execute(self.TEST_QUERY_USER_ARTICLE,
                               variables={
                                   'pk': article.pk,
                               },
                               context_value=context)
     assert response.get('data').get('userArticle') == {
         'title': 'Previous',
         'content': '',
         'author': {
             'username': self.TEST_MOCK_USERNAME
         }
     }
     response = client.execute(self.TEST_UPDATE_USER_ARTICLE,
                               variables={
                                   'pk': article.pk,
                                   'title': self.TEST_ARTICLE_TITLE,
                                   'content': self.TEST_ARTICLE_CONTENT
                               },
                               context_value=context)
     assert response.get('data').get('updateUserArticle').get(
         'state') is True
     response = client.execute(self.TEST_QUERY_USER_ARTICLE,
                               variables={
                                   'pk': article.pk,
                               },
                               context_value=context)
     assert response.get('data').get('userArticle') == {
         'title': self.TEST_ARTICLE_TITLE,
         'content': self.TEST_ARTICLE_CONTENT,
         'author': {
             'username': self.TEST_MOCK_USERNAME
         }
     }
コード例 #8
0
 def test_query_disable_article_with_permission_allowed(self):
     perm = Permission.objects.get(
         content_type=ContentType.objects.get_for_model(UserArticle),
         codename="view_userarticle")
     self.mock_usr.user_permissions.add(perm)
     self.mock_usr.save()
     client = get_test_graphql_client()
     response = client.execute(self.TEST_EXECUTE_QUERY,
                               variables={'pk': self.test_article.pk})
     assert UserArticleTest.get_response_result(response) == {
         'title': self.TEST_ARTICLE_TITLE,
         'content': self.TEST_ARTICLE_CONTENT,
         'author': {
             'username': self.TEST_MOCK_USERNAME
         }
     }
コード例 #9
0
 def test_create_and_update_article_comment(self):
     client = get_test_graphql_client()
     context = get_query_context()
     context.user = self.mock_usr
     article = self.create_test_article()
     response = client.execute(self.TEST_CREATE_ARTICLE_COMMENT,
                               variables={
                                   'pk': article.pk,
                                   'content': 'TestContent'
                               },
                               context_value=context)
     pk = response.get('data').get('createArticleComment').get('pk')
     assert pk is not None
     response = client.execute(self.TEST_UPDATE_ARTICLE_COMMENT,
                               variables={
                                   'pk': pk,
                                   'content': 'TestContent2'
                               },
                               context_value=context)
     assert response.get('data').get('updateBaseReply').get('state') is True
     assert ArticleComment.objects.get(pk=pk).content == 'TestContent2'
コード例 #10
0
 def test_create_comment_with_reply(self):
     client = get_test_graphql_client()
     context = get_query_context()
     context.user = self.mock_usr
     article = self.create_test_article()
     response = client.execute(self.TEST_CREATE_ARTICLE_COMMENT,
                               variables={
                                   'pk': article.pk,
                                   'content': 'Parent'
                               },
                               context_value=context)
     parent = response.get('data').get('createArticleComment').get('pk')
     assert parent is not None
     response = client.execute(self.TEST_CREATE_ARTICLE_COMMENT,
                               variables={
                                   'pk': article.pk,
                                   'content': 'Child',
                                   'reply': parent
                               },
                               context_value=context)
     child = response.get('data').get('createArticleComment').get('pk')
     assert child is not None
     assert ArticleComment.objects.get(pk=child).reply.pk == int(parent)