Best Python code snippet using playwright-python
test_parse_lines.py
Source:test_parse_lines.py  
...23class ParseOneLineTestCase(TestCase):24    def test_can_parse_line(self):25        result = parse(LOG_LINE)26        expect(result).not_to_be_null()27        expect(result).not_to_be_empty()28        expect(result[0]).to_be_instance_of(Response)29    def test_can_get_datetime(self):30        result = parse(LOG_LINE)31        dt = datetime(year=2015, month=7, day=28, hour=11, minute=28, second=40)32        expect(result).not_to_be_empty()33        item = result[0]34        expect(item.timestamp).to_equal(dt)35    def test_can_get_information_on_edge(self):36        result = parse(LOG_LINE)37        expect(result).not_to_be_empty()38        item = result[0]39        expect(item.edge).to_be_true()40        expect(item.edge['city']).to_equal('Miami')41        expect(item.edge['number']).to_equal(50)42        expect(item.edge['reference']['latitude']).to_equal(25.7931995)43    def test_can_get_number_of_bytes_on_response(self):44        result = parse(LOG_LINE)45        expect(result).not_to_be_empty()46        item = result[0]47        expect(item.response_size).to_equal(12330)48    def test_can_get_user_ip_using_c_ip(self):49        result = parse(LOG_LINE)50        expect(result).not_to_be_empty()51        item = result[0]52        expect(item.ip_address).to_equal('179.34.7.52')53    def test_can_get_http_method(self):54        result = parse(LOG_LINE)55        expect(result).not_to_be_empty()56        item = result[0]57        expect(item.http_method).to_equal('GET')58    def test_can_get_cloudfront_host(self):59        result = parse(LOG_LINE)60        expect(result).not_to_be_empty()61        item = result[0]62        expect(item.cloudfront_host).to_equal('d3n18mvc4wxsim.cloudfront.net')63    def test_can_get_path(self):64        result = parse(LOG_LINE)65        expect(result).not_to_be_empty()66        url = '/sample-user-id/gnQ93w5t5BwDe8Je7OUa/tOiP6Y_L1xKUIEfURwwiSIVprFA%253D/200x150/http%253A/extra.globo.com/' \67            'incoming/16823873-03c-cf8/w640h360-PROP/Romario.jpg'68        item = result[0]69        expect(item.path).to_equal(url)70    def test_can_get_status_code(self):71        result = parse(LOG_LINE)72        expect(result).not_to_be_empty()73        item = result[0]74        expect(item.status_code).to_equal('200')75        expect(item.aborted).to_be_false()76    def test_can_get_aborted_request(self):77        result = parse(ABORTED_LOG_LINE)78        expect(result).not_to_be_empty()79        item = result[0]80        expect(item.status_code).to_equal('000')81        expect(item.aborted).to_be_true()82    def test_can_get_referrer(self):83        result = parse(LOG_LINE)84        expect(result).not_to_be_empty()85        item = result[0]86        expect(item.referrer).to_equal('http://facebook.com/')87    def test_can_parse_user_agent(self):88        result = parse(LOG_LINE)89        expect(result).not_to_be_empty()90        ua = 'Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 ' \91            'Mobile/9B179 Safari/7534.48.3'92        item = result[0]93        expect(item.user_agent).to_equal(ua)94        expect(item.browser_family).to_equal('Mobile Safari')95        expect(item.browser_version).to_equal('5.1')96        expect(item.os_family).to_equal('iOS')97        expect(item.os_version).to_equal('5.1')98        expect(item.device).to_equal('iPhone')99        expect(item.is_mobile).to_be_true()100        expect(item.is_tablet).to_be_false()101        expect(item.is_pc).to_be_false()102        expect(item.is_touch_capable).to_be_true()103        expect(item.is_bot).to_be_false()104    def test_can_get_querystring(self):105        result = parse(QS_LOG_LINE)106        expect(result).not_to_be_empty()107        item = result[0]108        expect(item.querystring).to_equal('a=1&b=2')109    def test_querystring_is_null_when_hyphen(self):110        result = parse(LOG_LINE)111        expect(result).not_to_be_empty()112        item = result[0]113        expect(item.querystring).to_be_null()114    def test_can_get_cookies(self):115        result = parse(COOKIE_LOG_LINE)116        expect(result).not_to_be_empty()117        item = result[0]118        expect(item.cookies).not_to_be_null()119        expect(item.cookies).to_equal('session-token="some-session"; x-main=some-main-string;')120    def test_cookies_are_null_when_hyphen(self):121        result = parse(LOG_LINE)122        expect(result).not_to_be_empty()123        item = result[0]124        expect(item.cookies).to_be_null()125    def test_can_get_edge_result(self):126        result = parse(LOG_LINE)127        expect(result).not_to_be_empty()128        item = result[0]129        expect(item.edge_result_type).to_equal(Response.Result.Miss)130    def test_can_get_request_id(self):131        result = parse(LOG_LINE)132        expect(result).not_to_be_empty()133        expected_id = '9fSyxPBMgh0D7BFVPg1snTTm1Agq-Xcrq6gVZF_6vCfRr96WkBtiZQ=='134        item = result[0]135        expect(item.request_id).to_equal(expected_id)136    def test_can_get_request_host(self):137        result = parse(LOG_LINE)138        expect(result).not_to_be_empty()139        item = result[0]140        expect(item.request_host).to_equal('d3n18mvc4wxsim.cloudfront.net')141    def test_can_get_request_protocol(self):142        result = parse(LOG_LINE)143        expect(result).not_to_be_empty()144        item = result[0]145        expect(item.request_protocol).to_equal('http')146    def test_can_get_request_size(self):147        result = parse(LOG_LINE)148        expect(result).not_to_be_empty()149        item = result[0]150        expect(item.request_size).to_equal(228)151    def test_can_get_response_duration(self):152        result = parse(LOG_LINE)153        expect(result).not_to_be_empty()154        item = result[0]155        expect(item.response_duration).to_equal(0.086)156    def test_can_get_ip_from_x_forwarded_for(self):157        result = parse(XF_LOG_LINE)158        expect(result).not_to_be_empty()159        item = result[0]160        expect(item.ip_address).to_equal('179.34.7.54')161    def test_ssl_protocol_is_null_when_hyphen(self):162        result = parse(LOG_LINE)163        expect(result).not_to_be_empty()164        item = result[0]165        expect(item.ssl_protocol).to_be_null()166    def test_can_get_ssl_protocol(self):167        result = parse(SSL_LOG_LINE)168        expect(result).not_to_be_empty()169        item = result[0]170        expect(item.ssl_protocol).to_equal('SSLv3')171    def test_ssl_cypher_is_null_when_hyphen(self):172        result = parse(LOG_LINE)173        expect(result).not_to_be_empty()174        item = result[0]175        expect(item.ssl_cypher).to_be_null()176    def test_can_get_ssl_cypher(self):177        result = parse(SSL_LOG_LINE)178        expect(result).not_to_be_empty()179        item = result[0]180        expect(item.ssl_cypher).to_equal('AES256-SHA')181    def test_can_get_edge_response_result(self):182        result = parse(LOG_LINE)183        expect(result).not_to_be_empty()184        item = result[0]185        expect(item.edge_response_result_type).to_equal(Response.Result.Miss)186class ParseMultiLineTestCase(TestCase):187    def test_can_parse_file_like(self):188        items = """#Version: 1.0189#Fields: date time x-edge-location sc-bytes c-ip cs-method cs(Host) cs-uri-stem sc-status cs(Referer) cs(User-Agent) cs-uri-query cs(Cookie) x-edge-result-type x-edge-request-id x-host-header cs-protocol cs-bytes time-taken x-forwarded-for ssl-protocol ssl-cipher x-edge-response-result-type190%s191%s""" % (192            LOG_LINE,193            SSL_LOG_LINE,194        )195        log_line = StringIO(items)196        result = parse(log_line)197        expect(result).not_to_be_empty()...JobSupervisorTest.py
Source:JobSupervisorTest.py  
...8        js = arc.JobSupervisor(self.usercfg, [9            self.create_test_job(job_id = id1),10            self.create_test_job(job_id = id2)11        ]);12        self.expect(js.GetAllJobs()).not_to_be_empty()13        jobs = js.GetAllJobs()14        self.expect(jobs).to_have(2).jobs()15        self.expect(jobs[0].JobID).to_be(id1)16        self.expect(jobs[1].JobID).to_be(id2)17    def test_add_job(self):18        js = arc.JobSupervisor(self.usercfg, arc.JobList())19        self.expect(js.GetAllJobs()).to_be_empty()20        job = self.create_test_job(job_id = "http://test.nordugrid.org/1234567890test1")21        self.expect(js.AddJob(job)).to_be(True, message = "AddJob was expected to return True")22        self.expect(js.GetAllJobs()).not_to_be_empty()23        job.JobManagementInterfaceName = ""24        self.expect(js.AddJob(job)).to_be(False, message = "AddJob was expected to return False")25        self.expect(js.GetAllJobs()).to_have(1).job()26        job.JobManagementInterfaceName = "non.existent.interface"27        self.expect(js.AddJob(job)).to_be(False, message = "AddJob was expected to return False")28        self.expect(js.GetAllJobs()).to_have(1).job()29    def test_resubmit(self):30        self.usercfg.Broker("TEST")31        arc.TargetInformationRetrieverPluginTESTControl.targets = [self.create_test_target("http://test2.nordugrid.org")]32        arc.TargetInformationRetrieverPluginTESTControl.status = arc.EndpointQueryingStatus(arc.EndpointQueryingStatus.SUCCESSFUL)33        js = arc.JobSupervisor(self.usercfg, [34            self.create_test_job(job_id = "http://test.nordugrid.org/1234567890test1", state = arc.JobState.FAILED),35            self.create_test_job(job_id = "http://test.nordugrid.org/1234567890test2", state = arc.JobState.RUNNING)36        ])...sentry_error_handler_vows.py
Source:sentry_error_handler_vows.py  
...52            http_handler = FakeHandler()53            handler.handle_error(ctx, http_handler, RuntimeError("Test"))54            return client_mock55        def should_have_called_client(self, topic):56            expect(topic.captured_exceptions).not_to_be_empty()57            expect(topic.captured_exceptions).to_length(1)58            exception, args, kw = topic.captured_exceptions[0]59            expect(exception.__class__.__name__).to_equal("RuntimeError")60            expect(kw).to_include('data')61            expect(kw).to_include('extra')62            data, extra = kw['data'], kw['extra']63            expect(extra).to_include('thumbor-version')64            expect(extra['thumbor-version']).to_equal(__version__)65            expect(extra).to_include('Headers')66            expect(extra['Headers']).to_length(2)67            expect(extra['Headers']).to_include('Cookie')68            expect(extra['Headers']['Cookie']).to_length(2)69            expect(data['modules']).not_to_be_empty()70            del data['modules']71            expect(data).to_be_like({72                'sentry.interfaces.Http': {73                    'url': "http://test/test/",74                    'method': "GET",75                    'data': [],76                    'body': "body",77                    'query_string': "a=1&b=2"78                },79                'sentry.interfaces.User': {80                    'ip': "127.0.0.1",81                }...test_sentry.py
Source:test_sentry.py  
...53        )54    def test_when_error_occurs_should_have_called_client(self):55        handler = ErrorHandler(self.config, client=self.client_mock)56        handler.handle_error(self.context, self.http_handler, RuntimeError("Test"))57        expect(self.client_mock.captured_exceptions).not_to_be_empty()58        expect(self.client_mock.captured_exceptions).to_length(1)59        exception, args, kw = self.client_mock.captured_exceptions[0]60        expect(exception.__class__.__name__).to_equal("RuntimeError")61        expect(kw).to_include('data')62        expect(kw).to_include('extra')63        data, extra = kw['data'], kw['extra']64        expect(extra).to_include('thumbor-version')65        expect(extra['thumbor-version']).to_equal(__version__)66        expect(extra).to_include('Headers')67        expect(extra['Headers']).to_length(2)68        expect(extra['Headers']).to_include('Cookie')69        expect(extra['Headers']['Cookie']).to_length(2)70        expect(data['modules']).not_to_be_empty()71        del data['modules']72        expect(data).to_be_like({73            'sentry.interfaces.Http': {74                'url': "http://test/test/",75                'method': "GET",76                'data': [],77                'body': "body",78                'query_string': "a=1&b=2"79            },80            'sentry.interfaces.User': {81                'ip': "127.0.0.1",82            }...LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!
