mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-27 00:54:54 +00:00
added test cases for auth
This commit is contained in:
@ -105,23 +105,31 @@ base64_image = ("data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoHCBIS
|
||||
|
||||
class BaseSetUp(APITestCase):
|
||||
"""
|
||||
|
||||
basic setup
|
||||
"""
|
||||
|
||||
def setUp(self) -> None:
|
||||
"""
|
||||
|
||||
user data
|
||||
:return:
|
||||
"""
|
||||
self.user_email = 'user@example.com'
|
||||
self.admin_email = 'admin@example.com'
|
||||
self.client = APIClient()
|
||||
self.user = User.objects.create_user(username='user@example.com', password='user@1234')
|
||||
self.admin_user = User.objects.create_user(username='admin@example.com', email='admin@example.com',
|
||||
password='admin@1234', is_staff=True, is_superuser=True)
|
||||
self.user = User.objects.create_user(username=self.user_email, email=self.user_email)
|
||||
self.user.set_password('user@1234')
|
||||
self.user.save()
|
||||
self.admin_user = User.objects.create_user(username=self.admin_email, email=self.admin_email,
|
||||
is_staff=True, is_superuser=True)
|
||||
self.admin_user.set_password('admin@1234')
|
||||
self.admin_user.save()
|
||||
|
||||
|
||||
class ArticleTestSetUp(BaseSetUp):
|
||||
"""
|
||||
test cases data set up for article create, update
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
"""
|
||||
set up data for test
|
||||
@ -131,63 +139,71 @@ class ArticleTestSetUp(BaseSetUp):
|
||||
|
||||
self.article = Article.objects.create(title="Existing Article", description="Existing Description",
|
||||
is_published=True)
|
||||
self.article_card = ArticleCard.objects.create(article=self.article, title="Card 1",
|
||||
description="Card 1 Description")
|
||||
self.article_card = ArticleCard.objects.create(article=self.article, title="Existing Card 1",
|
||||
description="Existing Card 1 Description")
|
||||
self.article_survey = ArticleSurvey.objects.create(article=self.article, points=5,
|
||||
question="Survey Question 1")
|
||||
SurveyOption.objects.create(survey=self.article_survey, option="Option 1", is_answer=True)
|
||||
SurveyOption.objects.create(survey=self.article_survey, option="Option 2", is_answer=False)
|
||||
question="Existing Survey Question 1")
|
||||
SurveyOption.objects.create(survey=self.article_survey, option="Existing Option 1", is_answer=True)
|
||||
SurveyOption.objects.create(survey=self.article_survey, option="Existing Option 2", is_answer=False)
|
||||
|
||||
self.article_list_url = 'web_admin:article-list'
|
||||
self.article_detail_url = 'web_admin:article-detail'
|
||||
|
||||
# article card data with default card image
|
||||
self.article_card_data_with_default_card_image = {
|
||||
"title": "Card 1",
|
||||
"description": "Card 1 Description",
|
||||
"image_name": "card1.jpg",
|
||||
"image_url": "https://example.com/card1.jpg"
|
||||
}
|
||||
|
||||
# article card data with base64 image
|
||||
self.article_card_data_with_base64_image = {
|
||||
"title": "Card base64",
|
||||
"description": "Card base64 Description",
|
||||
"image_name": "base64_image.jpg",
|
||||
"image_url": base64_image
|
||||
}
|
||||
|
||||
# article survey option data
|
||||
self.article_survey_option_data = [
|
||||
{"option": "Option 1", "is_answer": True},
|
||||
{"option": "Option 2", "is_answer": False}
|
||||
]
|
||||
|
||||
# article survey data
|
||||
self.article_survey_data = [
|
||||
{
|
||||
"question": "Survey Question 1",
|
||||
"options": self.article_survey_option_data
|
||||
},
|
||||
{
|
||||
"question": "Survey Question 2",
|
||||
"options": self.article_survey_option_data
|
||||
},
|
||||
{
|
||||
"question": "Survey Question 3",
|
||||
"options": self.article_survey_option_data
|
||||
},
|
||||
{
|
||||
"question": "Survey Question 4",
|
||||
"options": self.article_survey_option_data
|
||||
},
|
||||
{
|
||||
"question": "Survey Question 5",
|
||||
"options": self.article_survey_option_data
|
||||
},
|
||||
]
|
||||
|
||||
# article data with default card image
|
||||
self.article_data_with_default_card_image = {
|
||||
"title": "Test Article",
|
||||
"description": "Test Description",
|
||||
"article_cards": [
|
||||
{
|
||||
"title": "Card 1",
|
||||
"description": "Card 1 Description",
|
||||
"image_name": "card1.jpg",
|
||||
"image_url": "https://example.com/updated_card1.jpg"
|
||||
}
|
||||
self.article_card_data_with_default_card_image
|
||||
],
|
||||
# minimum 5 article survey needed
|
||||
"article_survey": [
|
||||
{
|
||||
"question": "Survey Question 1",
|
||||
"options": [
|
||||
{"option": "Option 1", "is_answer": True},
|
||||
{"option": "Option 2", "is_answer": False}
|
||||
]
|
||||
},
|
||||
{
|
||||
"question": "Survey Question 2",
|
||||
"options": [
|
||||
{"option": "Option 1", "is_answer": True},
|
||||
{"option": "Option 2", "is_answer": False}
|
||||
]
|
||||
},
|
||||
{
|
||||
"question": "Survey Question 3",
|
||||
"options": [
|
||||
{"option": "Option 1", "is_answer": True},
|
||||
{"option": "Option 2", "is_answer": False}
|
||||
]
|
||||
},
|
||||
{
|
||||
"question": "Survey Question 4",
|
||||
"options": [
|
||||
{"option": "Option 1", "is_answer": True},
|
||||
{"option": "Option 2", "is_answer": False}
|
||||
]
|
||||
},
|
||||
{
|
||||
"question": "Survey Question 5",
|
||||
"options": [
|
||||
{"option": "Option 1", "is_answer": True},
|
||||
{"option": "Option 2", "is_answer": False}
|
||||
]
|
||||
},
|
||||
]
|
||||
"article_survey": self.article_survey_data
|
||||
}
|
||||
|
||||
# article data with base64 card image
|
||||
@ -195,51 +211,10 @@ class ArticleTestSetUp(BaseSetUp):
|
||||
"title": "Test Article",
|
||||
"description": "Test Description",
|
||||
"article_cards": [
|
||||
{
|
||||
"title": "Card 1",
|
||||
"description": "Card 1 Description",
|
||||
"image_name": "card1.jpg",
|
||||
"image_url": base64_image
|
||||
}
|
||||
self.article_card_data_with_base64_image
|
||||
],
|
||||
# minimum 5 article survey needed
|
||||
"article_survey": [
|
||||
{
|
||||
"question": "Survey Question 1",
|
||||
"options": [
|
||||
{"option": "Option 1", "is_answer": True},
|
||||
{"option": "Option 2", "is_answer": False}
|
||||
]
|
||||
},
|
||||
{
|
||||
"question": "Survey Question 2",
|
||||
"options": [
|
||||
{"option": "Option 1", "is_answer": True},
|
||||
{"option": "Option 2", "is_answer": False}
|
||||
]
|
||||
},
|
||||
{
|
||||
"question": "Survey Question 3",
|
||||
"options": [
|
||||
{"option": "Option 1", "is_answer": True},
|
||||
{"option": "Option 2", "is_answer": False}
|
||||
]
|
||||
},
|
||||
{
|
||||
"question": "Survey Question 4",
|
||||
"options": [
|
||||
{"option": "Option 1", "is_answer": True},
|
||||
{"option": "Option 2", "is_answer": False}
|
||||
]
|
||||
},
|
||||
{
|
||||
"question": "Survey Question 5",
|
||||
"options": [
|
||||
{"option": "Option 1", "is_answer": True},
|
||||
{"option": "Option 2", "is_answer": False}
|
||||
]
|
||||
}
|
||||
]
|
||||
"article_survey": self.article_survey_data
|
||||
}
|
||||
|
||||
# article update data
|
||||
@ -259,55 +234,16 @@ class ArticleTestSetUp(BaseSetUp):
|
||||
],
|
||||
# updated article survey
|
||||
"article_survey": [
|
||||
# updated article survey
|
||||
{
|
||||
"id": self.article_survey.id,
|
||||
"question": "Updated Survey Question 1",
|
||||
"options": [
|
||||
{"id": self.article_survey.options.first().id,
|
||||
"option": "Updated Option 1", "is_answer": False},
|
||||
# New option
|
||||
{"option": "Option 3", "is_answer": True}
|
||||
]
|
||||
},
|
||||
# new article survey
|
||||
{
|
||||
"question": "Survey Question 2",
|
||||
"options": [
|
||||
{"option": "Option 1", "is_answer": True},
|
||||
{"option": "Option 2", "is_answer": False}
|
||||
]
|
||||
},
|
||||
# new article survey
|
||||
{
|
||||
"question": "Survey Question 3",
|
||||
"options": [
|
||||
{"option": "Option 1", "is_answer": True},
|
||||
{"option": "Option 2", "is_answer": False}
|
||||
]
|
||||
},
|
||||
# new article survey
|
||||
{
|
||||
"question": "Survey Question 4",
|
||||
"options": [
|
||||
{"option": "Option 1", "is_answer": True},
|
||||
{"option": "Option 2", "is_answer": False}
|
||||
]
|
||||
},
|
||||
# new article survey
|
||||
{
|
||||
"question": "Survey Question 5",
|
||||
"options": [
|
||||
{"option": "Option 1", "is_answer": True},
|
||||
{"option": "Option 2", "is_answer": False}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
# article card data with default card image
|
||||
self.article_card_data_with_default_card_image = {
|
||||
"title": "Card 1",
|
||||
"description": "Card 1 Description",
|
||||
"image_name": "card1.jpg",
|
||||
"image_url": "https://example.com/card2.jpg"
|
||||
# updated article survey
|
||||
{
|
||||
"id": self.article_survey.id,
|
||||
"question": "Updated Survey Question 1",
|
||||
"options": [
|
||||
{"id": self.article_survey.options.first().id,
|
||||
"option": "Updated Option 1", "is_answer": False},
|
||||
# New option
|
||||
{"option": "New Option 3", "is_answer": True}
|
||||
]
|
||||
# added new articles
|
||||
}] + self.article_survey_data
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user