How to use test_presentation method in SeleniumBase

Best Python code snippet using SeleniumBase

rest_test.py

Source:rest_test.py Github

copy

Full Screen

1import unittest2from view.rest import EstimatorServer3import io4from werkzeug.datastructures import FileStorage5import os6import json7from storage.schema import LabelType, GradeType8from nltk.tokenize import sent_tokenize9TEST_DATA_PATH = "resources/test_data.json"10def read_test_data():11 with open(TEST_DATA_PATH) as json_file:12 return json.load(json_file)13class RestTest(unittest.TestCase):14 def setUp(self):15 self.server = EstimatorServer("../../downloader/resources")16 self.flask_client = self.server.server.test_client()17 self.socket_client = self.server.socketio.test_client(self.server.server,18 flask_test_client=self.flask_client)19 self.test_data = read_test_data()20 pass21 def tearDown(self):22 pass23 def test_socketio_connect(self):24 self.assertTrue(self.socket_client.is_connected())25 self.socket_client.disconnect()26 self.assertFalse(self.socket_client.is_connected())27 def test_index(self):28 response = self.flask_client.get('/')29 self.assertEqual(response.status_code, 200)30 self.assertIsNotNone(response.data)31 def test_upload(self):32 data = {}33 lecture = FileStorage(34 stream=open("resources/test_presentation.pptx", "rb"),35 filename="test_presentation.pptx",36 )37 essays = FileStorage(38 stream=open("resources/test_essays_list.xlsx", "rb"),39 filename="test_essays_list.xlsx",40 ),41 data['lecture'] = lecture42 data['essays'] = essays43 response = self.flask_client.post('/upload', content_type='multipart/form-data', data=data)44 socket_response = self.socket_client.get_received()45 self.assertEqual(response.status_code, 200)46 self.assertEqual(len(socket_response), 3)47 handling_notification = socket_response[0]48 self.assertEqual(handling_notification['name'], 'changed-report-status')49 self.assertEqual(len(handling_notification['args']), 1)50 status_message = json.loads(handling_notification['args'][0])51 self.assertEqual(status_message["status"], "handling")52 handled_notification = socket_response[2]53 self.assertEqual(handled_notification['name'], 'changed-report-status')54 self.assertEqual(len(handled_notification['args']), 1)55 status_message = json.loads(handled_notification['args'][0])56 self.assertEqual(status_message["status"], "handled")57 report = json.loads(response.data)58 essays = self.test_data["upload_test_essays"]59 self.assert_lecture(self.test_data["lecture_expected_text"], report["lecture"], 176)60 self.assert_essay(essays[0], report["essays"][0], GradeType.FAIL, 1,61 [LabelType.FAIL, LabelType.LECTURE_PLAGIARISM], 302)62 self.assert_essay(essays[1], report["essays"][1], GradeType.SUCCESS, 1, [LabelType.SUCCESS], 338)63 self.assert_essay(essays[2], report["essays"][2], GradeType.FAIL, 2, [LabelType.FAIL], 246)64 def assert_lecture(self, text, lecture, num_words):65 self.assertEqual(lecture["text"], text)66 self.assertEqual(lecture["statistic"]["num_letters"], len(text))67 self.assertEqual(lecture["statistic"]["num_sentences"], len(sent_tokenize(text)))68 self.assertEqual(lecture["statistic"]["num_words"], num_words)69 def assert_essay(self, text, essay, grade, group, labels, num_words):70 self.assertEqual(essay["text"], text)71 self.assertEqual(essay["statistic"]["num_letters"], len(text))72 self.assertEqual(essay["statistic"]["num_sentences"], len(sent_tokenize(text)))73 self.assertEqual(essay["statistic"]["num_words"], num_words)74 self.assertEqual(essay["grade"], grade)75 self.assertEqual(essay["group"], group)76 self.assertEqual(len(labels), len(essay["labels"]))77 for label in essay["labels"]:78 if label["type"] in labels:79 labels.remove(label["type"])80 else:81 self.assertEqual(True, False)82 self.assertEqual(len(labels), 0)83 def test_upload_incorrect_essay_list(self):84 data = {}85 lecture = FileStorage(86 stream=open("resources/test_presentation.pptx", "rb"),87 filename="test_presentation.pptx",88 )89 essays = FileStorage(90 stream=open("resources/test_incorrect_list.xlsx", "rb"),91 filename="test_incorrect_list.xlsx",92 ),93 data['lecture'] = lecture94 data['essays'] = essays95 response = self.flask_client.post('/upload', content_type='multipart/form-data', data=data)96 socket_response = self.socket_client.get_received()97 self.assertEqual(response.status_code, 500)98 self.assertEqual(len(socket_response), 2)99 handling_notification = socket_response[0]100 self.assertEqual(handling_notification['name'], 'changed-report-status')101 self.assertEqual(len(handling_notification['args']), 1)102 status_message = json.loads(handling_notification['args'][0])103 self.assertEqual(status_message["status"], "handling")104 exception = json.loads(response.data)105 self.assertEqual(exception["status"], "error")106 self.assertIsNotNone(exception["text"])107 def test_upload_without_files(self):108 data = {}109 response = self.flask_client.post('/upload', content_type='multipart/form-data', data=data)110 socket_response = self.socket_client.get_received()111 self.assertEqual(response.status_code, 302)112 self.assertEqual(len(socket_response), 0)113 def test_upload_incorrect_files(self):114 data = {}115 lecture = FileStorage(116 stream=io.BytesIO(b"Empty file"),117 filename="test_presentation.pptx",118 )119 essays = FileStorage(120 stream=io.BytesIO(b"Empty file"),121 filename="test_incorrect_list.xlsx",122 ),123 data['lecture'] = lecture124 data['essays'] = essays125 response = self.flask_client.post('/upload', content_type='multipart/form-data', data=data)126 socket_response = self.socket_client.get_received()127 self.assertEqual(500, response.status_code)128 self.assertEqual(1, len(socket_response))129 exception = json.loads(response.data)130 self.assertEqual(exception["status"], "error")131 self.assertIsNotNone(exception["text"])132 def test_end_check(self):133 data = {}134 lecture = FileStorage(135 stream=open("resources/test_presentation.pptx", "rb"),136 filename="test_presentation.pptx",137 )138 essays = FileStorage(139 stream=open("resources/test_essays_list.xlsx", "rb"),140 filename="test_essays_list.xlsx",141 ),142 data['lecture'] = lecture143 data['essays'] = essays144 response = self.flask_client.post('/upload', content_type='multipart/form-data', data=data)145 socket_response = self.socket_client.get_received()146 self.assertEqual(response.status_code, 200)147 self.assertEqual(len(socket_response), 3)148 report = json.loads(response.data)149 change_essay = report["essays"][0]150 change_essay["teacher_grade"] = "SUCCESS"151 change_essay["labels"].append({"type": "TEACHER_SUCCESS"})152 json_report = json.dumps(report)153 response = self.flask_client.post('/end_check', data=json_report)154 socket_response = self.socket_client.get_received()155 self.assertEqual(response.status_code, 200)156 self.assertEqual(len(socket_response), 0)157 success = json.loads(response.data)158 self.assertEqual(success["status"], "success")159 self.assertIsNotNone(success["text"])160 def test_end_check_incorrect_data(self):161 json_report = json.dumps({"data": "incorrect"})162 response = self.flask_client.post('/end_check', data=json_report)163 socket_response = self.socket_client.get_received()164 self.assertEqual(response.status_code, 500)165 self.assertEqual(len(socket_response), 0)166 exception = json.loads(response.data)167 self.assertEqual(exception["status"], "error")168 self.assertIsNotNone(exception["text"])169if __name__ == '__main__':...

Full Screen

Full Screen

test_slides.py

Source:test_slides.py Github

copy

Full Screen

1from pygsuite.slides import ShapeType, ElementProperties2BRIGHT_GREEN_HEX = "#72FF33"3def test_presentation(test_presentation):4 prez = test_presentation5 slide = prez.add_slide(flush=True)6 slide.add_shape(7 ShapeType.TEXT_BOX, ElementProperties(x=0, y=0, height=50, width="100%")8 ).text = "test"9 prez.flush()10 assert prez[1].shapes[0].text.strip() == "test"11def test_layouts(test_presentation):12 deck = test_presentation13 deck.add_slide(14 layout=deck.layouts["Title slide"],15 index=0,16 placeholders={"CENTERED_TITLE": """ TEST_PREZ""", "SUBTITLE": "SUB_TITLE"},17 )...

Full Screen

Full Screen

test_presentation.py

Source:test_presentation.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2SECRET_KEY = 'type random secret_key'3SUIT_CONFIG = {4 'ADMIN_NAME': u'test_presentation',5}6# Make '' first app to overload templates7apps = list(INSTALLED_APPS) # NOQA8apps.insert(9 0,10 'test_presentation',11)12INSTALLED_APPS = apps13INSTALLED_APPS += ( # NOQA14)15TEMPLATE_CONTEXT_PROCESSORS += ( # NOQA16 'test_presentation.context_processors.version',17)18MIDDLEWARE_CLASSES += ( # NOQA19 'test_presentation.middleware.GoogleAnalyticsMiddleware',20)...

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 SeleniumBase 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