How to use test_is_empty method in assertpy

Best Python code snippet using assertpy_python

test_model.py

Source:test_model.py Github

copy

Full Screen

...4from robot_app.models import User_Question, GNAVI_Question, Youtube_Question, Robot_Evaluation, \5 Blog, News, Schedule, Net_Shop, ChatBot6from users.models import User7class UserQuestionModelTest(TestCase):8 def test_is_empty(self):9 saved_answer = User_Question.objects.all()10 self.assertEqual(saved_answer.count(), 0)11 #内容が保存されているかの検証12 def test_saving_and_retrieving_question(self):13 first_question = User_Question()14 first_question.question = '犬は好きですか?'15 first_question.answer = 'はい好きです'16 first_question.save()17 second_question = User_Question()18 second_question.question = '猫は好きですか?'19 second_question.answer = 'いいえ嫌いです'20 second_question.save()21 saved_items = User_Question.objects.all()22 self.assertEqual(saved_items.count(), 2)23 first_saved_item = saved_items[0]24 second_saved_item = saved_items[1]25 self.assertEqual(first_saved_item.question, '犬は好きですか?')26 self.assertEqual(second_saved_item.question, '猫は好きですか?')27class GNAVI_QuestionModelTest(TestCase):28 def test_is_empty(self):29 saved_answer = GNAVI_Question.objects.all()30 self.assertEqual(saved_answer.count(), 0)31 #内容が保存されているかの検証32 def test_saving_and_retrieving_question(self):33 first_question = GNAVI_Question()34 first_question.question = '都道府県を入力してください1'35 first_question.answer = '東京都'36 first_question.save()37 second_question = GNAVI_Question()38 second_question.question = '都道府県を入力してください2'39 second_question.answer = '北海道'40 second_question.save()41 saved_items = GNAVI_Question.objects.all()42 self.assertEqual(saved_items.count(), 2)43 first_saved_item = saved_items[0]44 second_saved_item = saved_items[1]45 self.assertEqual(first_saved_item.question, '都道府県を入力してください1')46 self.assertEqual(second_saved_item.question, '都道府県を入力してください2')47class Youtube_QuestionModelTest(TestCase):48 def test_is_empty(self):49 saved_answer = Youtube_Question.objects.all()50 self.assertEqual(saved_answer.count(), 0)51 #内容が保存されているかの検証52 def test_saving_and_retrieving_question(self):53 first_question = Youtube_Question()54 first_question.question = 'キーワードを入力してください1'55 first_question.answer = 'ヒカキン'56 first_question.save()57 second_question = Youtube_Question()58 second_question.question = 'キーワードを入力してください2'59 second_question.answer = 'はじめしゃちょー'60 second_question.save()61 saved_items = Youtube_Question.objects.all()62 self.assertEqual(saved_items.count(), 2)63 first_saved_item = saved_items[0]64 second_saved_item = saved_items[1]65 self.assertEqual(first_saved_item.question, 'キーワードを入力してください1')66 self.assertEqual(second_saved_item.question, 'キーワードを入力してください2')67class Robot_EvaluationModelTest(TestCase):68 #ログインさせる69 def setUp(self):70 self.user = User.objects.create_user('test@gmail.com', 'test123')71 self.client = Client()72 self.client.login(email='test@gmail.com', password='test123')73 def test_is_empty(self):74 saved_answer = Robot_Evaluation.objects.all()75 self.assertEqual(saved_answer.count(), 0)76 #内容が保存されているかの検証77 def test_saving_and_retrieving_question(self):78 robot_evaluation1 = Robot_Evaluation()79 robot_evaluation1.user_name = self.user80 robot_evaluation1.robot_name = '案内ロボット1'81 robot_evaluation1.score = '3'82 robot_evaluation1.save()83 robot_evaluation2 = Robot_Evaluation()84 robot_evaluation2.user_name = self.user85 robot_evaluation2.robot_name = '案内ロボット2'86 robot_evaluation2.score = '5'87 robot_evaluation2.save()88 saved_review = Robot_Evaluation.objects.all()89 self.assertEqual(saved_review.count(), 2)90 first_saved_review = saved_review[0]91 second_saved_review = saved_review[1]92 self.assertEqual(first_saved_review.robot_name, '案内ロボット1')93 self.assertEqual(second_saved_review.score, 5)94class BlogModelTest(TestCase):95 #ログインさせる96 def setUp(self):97 self.user = User.objects.create_user('test@gmail.com', 'test123')98 self.client = Client()99 self.client.login(email='test@gmail.com', password='test123')100 def test_is_empty(self):101 saved_answer = Blog.objects.all()102 self.assertEqual(saved_answer.count(), 0)103 #内容が保存されているかの検証104 def test_saving_and_retrieving_question(self):105 blog1 = Blog()106 blog1.user_name = self.user107 blog1.title = 'タイトル1'108 blog1.text = '本文1'109 blog1.save()110 blog2 = Blog()111 blog2.user_name = self.user112 blog2.title = 'タイトル2'113 blog2.text = '本文2'114 blog2.save()115 saved_blog = Blog.objects.all()116 self.assertEqual(saved_blog.count(), 2)117 first_saved_blog = saved_blog[0]118 second_saved_blog = saved_blog[1]119 self.assertEqual(first_saved_blog.title, 'タイトル1')120 self.assertEqual(second_saved_blog.text, '本文2')121class NewsModelTest(TestCase):122 def test_is_empty(self):123 saved_answer = News.objects.all()124 self.assertEqual(saved_answer.count(), 0)125 #内容が保存されているかの検証126 def test_saving_and_retrieving_question(self):127 first_question = News()128 first_question.question = '好きなタレントは誰ですか?'129 first_question.answer = 'ヒカキン'130 first_question.save()131 second_question = News()132 second_question.question = 'どんなカテゴリが好きですか?'133 second_question.answer = 'general'134 second_question.save()135 saved_items = News.objects.all()136 self.assertEqual(saved_items.count(), 2)137 first_saved_item = saved_items[0]138 second_saved_item = saved_items[1]139 self.assertEqual(first_saved_item.question, '好きなタレントは誰ですか?')140 self.assertEqual(second_saved_item.question, 'どんなカテゴリが好きですか?')141class ScheduleModelTest(TestCase):142 #ログインさせる143 def setUp(self):144 self.user = User.objects.create_user('test@gmail.com', 'test123')145 self.client = Client()146 self.client.login(email='test@gmail.com', password='test123')147 def test_is_empty(self):148 saved_answer = Schedule.objects.all()149 self.assertEqual(saved_answer.count(), 0)150 #内容が保存されているかの検証151 def test_saving_and_retrieving_question(self):152 first_question = Schedule()153 first_question.user_name = self.user154 first_question.summary = '釣り'155 first_question.description = '友達と釣りに行く'156 first_question.date = '2020-01-01'157 first_question.save()158 second_question = Schedule()159 second_question.user_name = self.user160 second_question.summary = '旅行'161 second_question.description = '旅行に行く'162 second_question.date = '2020-02-01'163 second_question.save()164 saved_items = Schedule.objects.all()165 self.assertEqual(saved_items.count(), 2)166 first_saved_item = saved_items[0]167 second_saved_item = saved_items[1]168 self.assertEqual(first_saved_item.summary, '釣り')169 self.assertEqual(second_saved_item.description, '旅行に行く')170class Net_ShopModelTest(TestCase):171 def test_is_empty(self):172 saved_answer = Net_Shop.objects.all()173 self.assertEqual(saved_answer.count(), 0)174 #内容が保存されているかの検証175 def test_saving_and_retrieving_question(self):176 first_question = Net_Shop()177 first_question.question = '何かほしいものはありますか?'178 first_question.answer = '靴'179 first_question.save()180 second_question = Net_Shop()181 second_question.question = 'どんなカテゴリが好きですか?'182 second_question.answer = 'shoes'183 second_question.save()184 saved_items = Net_Shop.objects.all()185 self.assertEqual(saved_items.count(), 2)186 first_saved_item = saved_items[0]187 second_saved_item = saved_items[1]188 self.assertEqual(first_saved_item.question, '何かほしいものはありますか?')189 self.assertEqual(second_saved_item.answer, 'shoes')190class ChatBotModelTest(TestCase):191 def test_is_empty(self):192 saved_answer = ChatBot.objects.all()193 self.assertEqual(saved_answer.count(), 0)194 #内容が保存されているかの検証195 def test_saving_and_retrieving_question(self):196 first_question = ChatBot()197 first_question.question = 'ワインは好きですか?'198 first_question.answer = 'はい'199 first_question.save()200 second_question = ChatBot()201 second_question.question = 'ビールは好きですか?'202 second_question.answer = 'ビールが好きです'203 second_question.save()204 saved_items = ChatBot.objects.all()205 self.assertEqual(saved_items.count(), 2)206 first_saved_item = saved_items[0]207 second_saved_item = saved_items[1]208 self.assertEqual(first_saved_item.question, 'ワインは好きですか?')209 self.assertEqual(second_saved_item.answer, 'ビールが好きです')210class UserModelTest(TestCase):211 def test_is_empty(self):212 saved_answer = User.objects.all()213 self.assertEqual(saved_answer.count(), 0)214 #内容が保存されているかの検証215 def test_saving_and_retrieving_question(self):216 first_question = User()217 first_question.email = 'test@gmail.com'218 first_question.profname = 'test'219 first_question.save()220 second_question = User()221 second_question.email = 'test2@gmail.com'222 second_question.profname = 'test2'223 second_question.save()224 saved_items = User.objects.all()225 self.assertEqual(saved_items.count(), 2)...

Full Screen

Full Screen

api-tests.py

Source:api-tests.py Github

copy

Full Screen

...34 self.video_dict_list = get_JSON_string(url)35 36 def tearDown(self):37 pass38 def test_is_empty(self): 39 self.assertFalse(not self.video_dict_list)40 def test_keys(self):41 video = self.playlists[0][0]42 keys = ['link','title','channel','publish_time','views','likes','dislikes','comments','thumbnail_link']43 self.assertTrue(video.keys() == keys)44 def test_types(self):45 video = self.video_dict_list[0]46 self.assertIsInstance(video.get('link'), str)47 self.assertIsInstance(video.get('title'), str)48 self.assertIsInstance(video.get('channel'), str)49 self.assertIsInstance(video.get('publish_time'), str)50 self.assertIsInstance(video.get('views'), int)51 self.assertIsInstance(video.get('likes'), int)52 self.assertIsInstance(video.get('dislikes'), int)53 self.assertIsInstance(video.get('comments'), int)54 self.assertIsInstance(video.get('thumbnail_link'), str)55class SignUpTester(unittest.TestCase):56 ''' tests the ednpoint /sign-up '''57 def setUp(self):58 ''' returns a success code if the username is not taken, else an error code '''59 url = {API_BASE_URL} + '/sign-up/'60 self.message = get_JSON_string(url)61 def tearDown(self):62 pass63 def test_is_empty(self):64 self.assertFalse(not self.message)65 # After implementing server and database, add a test to check whether message already exists in the database.66class LogInTester(unittest.TestCase):67 ''' tests the endpoint /log-in'''68 def setUp(self):69 ''' Returns a success code and user information if the username exists, else an error code'''70 url = {API_BASE_URL} + '/log-in/'71 self.message = get_JSON_string(url)72 def tearDown(self):73 pass74 def test_is_empty(self):75 self.assertFalse(not self.message)76 # After implementing server and database, add a test to check whether message already exists in the database.77class SaveToPlaylistTester(unittest.TestCase):78 ''' test the endpoint /save-to-playlist '''79 80 def setUp(self):81 ''' returns a success code if the video is not in the playlist and saved successfully, else an error code '''82 url = {API_BASE_URL} + '/save-to-playlist/'83 self.message = get_JSON_string(url)84 def tearDown(self):85 pass86 def test_is_empty(self):87 self.assertFalse(not self.message)88class SearchTester(unittest.TestCase):89 '''90 test for the search endpoint 91 /videos?title_contains={search_text}&category={category}&channel={channel}&publish-time={publish-time}&sort-option={sort-option}92 '''93 def setUp(self):94 ''' Return a list of data of videos searched by queries below:95 search_text, category, channel, publish_time, sort_option.96 The data of vidoes are represented as dictionaries of the form same as the list from MainPageTester: 97 The full result of setUp would be like below:98 [{'link':'kgaO45SyaO4', ... ,'thumbnail_link':'https://i.ytimg.com/vi/kgaO45SyaO4/default.jpg'},99 {'link':'PaJCFHXcWmM', ... ,'thumbnail_link':'https://i.ytimg.com/vi/PaJCFHXcWmM/default.jpg'}] 100 '''101 search_text = 'Is'102 category = 'music'103 channel = 'ChildishGambinoVEVO'104 publish_time = '2018_05'105 sort_option = 'views'106 url = f'{API_BASE_URL}/videos?title-contains={search_text}&category={category}'107 +f'&channel={channel}&publish-time={publish_time}&sort-option={sort_option}/'108 self.video_dict_list = get_JSON_string(url)109 def tearDown(self):110 pass111 def test_is_empty(self): 112 self.assertFalse(not self.video_dict_list)113 def test_keys(self):114 video = self.playlists[0][0]115 keys = ['link','title','channel','publish_time','views','likes','dislikes','comments','thumbnail_link']116 self.assertTrue(video.keys() == keys)117 def test_types(self):118 video = self.video_dict_list[0]119 self.assertIsInstance(video.get('link'), str)120 self.assertIsInstance(video.get('title'), str)121 self.assertIsInstance(video.get('channel'), str)122 self.assertIsInstance(video.get('publish_time'), str)123 self.assertIsInstance(video.get('views'), int)124 self.assertIsInstance(video.get('likes'), int)125 self.assertIsInstance(video.get('dislikes'), int)126 self.assertIsInstance(video.get('comments'), int)127 self.assertIsInstance(video.get('thumbnail_link'), str)128class InvalidSearchTester(unittest.TestCase):129 '''130 test for the search endpoint /videos?title_contains={search_text}131 in this case the search string cannot be found and the API should return an empty list132 '''133 def setUp(self):134 ''' Returns Null because the search string cannot be found '''135 search_text = '---------------------'136 url = f'{API_BASE_URL}/videos?title-contains={search_text}/'137 self.video_dict_list = get_JSON_string(url)138 def tearDown(self):139 pass140 def test_is_empty(self): 141 self.assertTrue(not self.video_dict_list)142class MyPageTester(unittest.TestCase):143 '''144 test for endpoint /my-page?user={username}, where username is a user with existing playlists145 '''146 147 def setUp(self):148 ''' 149 Returns a JSON array of arrays, each of which represents a playlist. 150 Each playlist array is a JSON list of dictionaries, each of represents a video. 151 '''152 username = 'user1'153 url = f'{API_BASE_URL}/my-page?user={username}/'154 self.playlists = get_JSON_string(url)155 def tearDown(self):156 pass157 def test_is_empty(self): 158 self.assertFalse(not self.playlists)159 self.assertFalse(not self.playlists[0])160 def test_keys(self):161 video = self.playlists[0][0]162 keys = ['link','title','channel','publish_time','views','likes','dislikes','comments','thumbnail_link']163 self.assertTrue(video.keys() == keys)164 def test_types(self):165 video = self.playlists[0][0]166 self.assertIsInstance(video.get('link'), str)167 self.assertIsInstance(video.get('title'), str)168 self.assertIsInstance(video.get('channel'), str)169 self.assertIsInstance(video.get('publish_time'), str)170 self.assertIsInstance(video.get('views'), int)171 self.assertIsInstance(video.get('likes'), int)172 self.assertIsInstance(video.get('dislikes'), int)173 self.assertIsInstance(video.get('comments'), int)174 self.assertIsInstance(video.get('thumbnail_link'), str)175class EmptyMyPageTester(unittest.TestCase):176 '''177 test for endpoint /my-page?user={username}, where the user has no existing playlists178 '''179 180 def setUp(self):181 ''' 182 Returns a JSON array of arrays, each of which represents a playlist. 183 Each playlist array is a JSON list of dictionaries, each of represents a video. 184 '''185 username = 'user1'186 url = f'{API_BASE_URL}/my-page?user={username}/'187 self.playlists = get_JSON_string(url)188 def tearDown(self):189 pass190 def test_is_empty(self): 191 self.assertTrue(not self.playlists)192class LogOutTester(unittest.TestCase):193 ''' tests /log-out/ endpoint '''194 def setUp(self):195 ''' returns a success code if logged out successfully, else an error code '''196 url = {API_BASE_URL} + 'log-out/'197 self.message = get_JSON_string(url)198 def tearDown(self):199 pass200 def test_is_empty(self):201 self.assertFalse(not self.message)202if __name__ == '__main__':...

Full Screen

Full Screen

test_models.py

Source:test_models.py Github

copy

Full Screen

2from django.test import TestCase3from push.models import DeviceTokenModel, NotificationModel, DevelopFileModel, ProductFileModel4from datetime import datetime5class DeviceTokenModelTests(TestCase):6 def test_is_empty(self):7 saved_device_token = DeviceTokenModel.objects.all()8 self.assertEqual(saved_device_token.count(), 0)9 def test_is_not_empty(self):10 device_token = DeviceTokenModel(os_version = 1.0,11 device_token = 'test',12 username = 'jenkins',13 uuid = 'uuid')14 device_token.save()15 saved_device_token = DeviceTokenModel.objects.all()16 self.assertEqual(saved_device_token.count(), 1)17 token = saved_device_token[0]18 self.assertEqual(token.os_version, 1.0)19 self.assertEqual(token.device_token, 'test')20 self.assertEqual(token.username, 'jenkins')21 self.assertEqual(token.uuid, 'uuid')22class NotificationModelTest(TestCase):23 def test_is_empty(self):24 saved_notification = NotificationModel.objects.all()25 self.assertEqual(saved_notification.count(), 0)26 def test_is_not_empty(self):27 create_notification = NotificationModel(os_version = 1.0,28 username = 'jenkins',29 badge = 1,30 execute_datetime = '2016/11/08 01:17')31 create_notification.save()32 saved_notification = NotificationModel.objects.all()33 self.assertEqual(saved_notification.count(), 1)34 one_notification = saved_notification[0]35 self.assertEqual(one_notification.title, '')36 self.assertEqual(one_notification.message, '')37 self.assertEqual(one_notification.os_version, 1.0)38 self.assertEqual(one_notification.sound, '')39 self.assertEqual(one_notification.badge, 1)40 self.assertEqual(one_notification.url, '')41 self.assertEqual(one_notification.json, '')42 self.assertEqual(one_notification.content_available, False)43 self.assertEqual(one_notification.is_production, False)44 self.assertEqual(one_notification.username, 'jenkins')45 self.assertEqual(one_notification.is_sent, False)46class DevelopFileModelTest(TestCase):47 def test_is_empty(self):48 saved_develop = DevelopFileModel.objects.all()49 self.assertEqual(saved_develop.count(), 0)50 def test_is_not_empty(self):51 one_develop = DevelopFileModel(upload_username = 'jenkins',52 development_file_name = 'test/develop.pem')53 one_develop.save()54 saved_develop = DevelopFileModel.objects.all()55 develop = saved_develop[0]56 self.assertEqual(develop.upload_username, 'jenkins')57 self.assertEqual(develop.development_file_name, 'test/develop.pem')58class ProductFileModelTest(TestCase):59 def test_is_empty(self):60 saved_product = ProductFileModel.objects.all()61 self.assertEqual(saved_product.count(), 0)62 def test_is_not_empty(self):63 one_product = ProductFileModel(upload_username = 'jenkins',64 production_file_name = 'test/product.pem')65 one_product.save()66 saved_product = ProductFileModel.objects.all()67 product = saved_product[0]68 self.assertEqual(product.upload_username, 'jenkins')...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run assertpy automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful