Best Python code snippet using tempest_python
social_test.py
Source:social_test.py  
...20@patch("flask_jwt_extended.view_decorators.verify_jwt_in_request")21def test_add_like(mock_jwt):22  with application.test_client() as c:23    with application.app_context():24      access_token = create_access_token("john@mail.com")25      headers = {"Authorization": "Bearer {}".format(access_token)}26      json_response = c.post(27        "/social/add_like",28        headers=headers,29        json={"tickr": "EX"},30      )31      assert json_response.status == "200 OK"32      cur.execute(33        "DELETE FROM likes WHERE username='john.doe' and tickr='EX'"34      )35      conn.commit()36@patch("flask_jwt_extended.view_decorators.verify_jwt_in_request")37def test_add_like_like_twice(mock_jwt):38  with application.test_client() as c:39    with application.app_context():40      access_token = create_access_token("john@mail.com")41      headers = {"Authorization": "Bearer {}".format(access_token)}42      json_response = c.post(43        "/social/add_like",44        headers=headers,45        json={"tickr": "E"}46      )47      assert json_response.status == "200 OK"48      json_response = c.post(49        "/social/add_like",50        headers=headers,51        json={"tickr": "E"},52      )53      assert json_response.status == "500 INTERNAL SERVER ERROR"54      cur.execute(55        "DELETE FROM likes WHERE username=%s and tickr=%s",56        ("john.doe", "E"),57      )58      conn.commit()59@patch("flask_jwt_extended.view_decorators.verify_jwt_in_request")60def test_remove_like(mock_jwt):61  with application.test_client() as c:62    with application.app_context():63      access_token = create_access_token("john@mail.com")64      headers = {"Authorization": "Bearer {}".format(access_token)}65      json_response = c.post(66        "/social/add_like",67        headers=headers,68        json={"tickr": "ABC"},69      )70      assert json_response.status == "200 OK"71      json_response = c.delete(72        "/social/remove_like",73        headers=headers,74        json={"tickr": "ABC"},75      )76      assert json_response.status == "200 OK"77      cur.execute(78        "DELETE FROM likes WHERE username=%s and tickr=%s",79        ("john.doe", "ABC"),80      )81      conn.commit()82@patch("flask_jwt_extended.view_decorators.verify_jwt_in_request")83def test_liked(mock_jwt):84  with application.test_client() as c:85    with application.app_context():86      access_token = create_access_token("john@mail.com")87      headers = {"Authorization": "Bearer {}".format(access_token)}88      json_response = c.put(89        "/social/liked", headers=headers, json={"tickr": "EXMPL"}90      )91      assert json_response.status == "200 OK"92@patch("flask_jwt_extended.view_decorators.verify_jwt_in_request")93def test_user_likes(mock_jwt):94  with application.test_client() as c:95    with application.app_context():96      access_token = create_access_token("john@mail.com")97      headers = {"Authorization": "Bearer {}".format(access_token)}98      json_response = c.get("/social/user_likes", headers=headers)99      assert json_response.status == "200 OK"100@patch("flask_jwt_extended.view_decorators.verify_jwt_in_request")101def test_total_likes(mock_jwt):102  with application.test_client() as c:103    with application.app_context():104      access_token = create_access_token("john@mail.com")105      headers = {"Authorization": "Bearer {}".format(access_token)}106      json_response = c.put(107        "/social/total_likes", headers=headers, json={"tickr": "EXMPL"}108      )109      assert json_response.status == "200 OK"110@patch("flask_jwt_extended.view_decorators.verify_jwt_in_request")111def test_all_likes(mock_jwt):112  with application.test_client() as c:113    with application.app_context():114      access_token = create_access_token("john@mail.com")115      headers = {"Authorization": "Bearer {}".format(access_token)}116      json_response = c.put(117        "/social/all_likes", headers=headers, json={"tickr": "EXMPL"}118      )119      assert json_response.status == "200 OK"120@patch("flask_jwt_extended.view_decorators.verify_jwt_in_request")121def test_add_comment(mock_jwt):122  with application.test_client() as c:123    with application.app_context():124      access_token = create_access_token("john@mail.com")125      headers = {"Authorization": "Bearer {}".format(access_token)}126      json_response = c.post(127        "/social/add_comment",128        headers=headers,129        json={"tickr": "EX", "comment": "test comment"},130      )131      assert json_response.status == "200 OK"132      cur.execute("DELETE FROM comments WHERE tickr='EX'")133      conn.commit()134@patch("flask_jwt_extended.view_decorators.verify_jwt_in_request")135def test_user_comments(mock_jwt):136  with application.test_client() as c:137    with application.app_context():138      access_token = create_access_token("john@mail.com")139      headers = {"Authorization": "Bearer {}".format(access_token)}140      json_response = c.put(141        "/social/user_comments",142        headers=headers,143        json={"tickr": "EXMPL"},144      )145      assert json_response.status == "200 OK"146@patch("flask_jwt_extended.view_decorators.verify_jwt_in_request")147def test_fetch_latest_comments(mock_jwt):148  with application.test_client() as c:149    with application.app_context():150      access_token = create_access_token("john@mail.com")151      headers = {"Authorization": "Bearer {}".format(access_token)}152      json_response = c.put(153        "/social/fetch_latest_comments",154        headers=headers,155        json={"tickr": "EXMPL"},156      )157      assert json_response.status == "200 OK"158@patch("flask_jwt_extended.view_decorators.verify_jwt_in_request")159def test_all_comments(mock_jwt):160  with application.test_client() as c:161    with application.app_context():162      access_token = create_access_token("john@mail.com")163      headers = {"Authorization": "Bearer {}".format(access_token)}164      json_response = c.put(165        "/social/all_comments",166        headers=headers,167        json={"tickr": "EXMPL"},168      )...controllers.py
Source:controllers.py  
...34        schema = LoginSchema()35        dados = schema.load(request.json)36        administrador = Administrador.query.filter_by(email=dados['email']).first()37        if administrador and administrador.verify_password(dados['password']): 38            token = create_access_token(identity=administrador.id, expires_delta=timedelta(minutes=900), fresh=True)39            refresh_token = create_refresh_token(identity=administrador.id, expires_delta=timedelta(minutes=1500))40            return {'user': 'administrador',41                    'token': token,42                    'refresh_token': refresh_token}, 20043        else: 44            advogado = Advogado.query.filter_by(email=dados['email']).first()45            if advogado and advogado.verify_password(dados['password']):46                token = create_access_token(identity=advogado.id, expires_delta=timedelta(minutes=900), fresh=True)47                refresh_token = create_refresh_token(identity=advogado.id, expires_delta=timedelta(minutes=1500))48                return {'user': 'advogado',49                        'token': token,50                        'refresh_token': refresh_token}, 20051            else:52                gestor = Gestor.query.filter_by(email=dados['email']).first()53                if gestor and gestor.verify_password(dados['password']): 54                    token = create_access_token(identity=gestor.id, expires_delta=timedelta(minutes=900), fresh=True)55                    refresh_token = create_refresh_token(identity=gestor.id, expires_delta=timedelta(minutes=1500))56                    return {'user': 'gestor',57                            'token': token,58                            'refresh_token': refresh_token}, 20059                else:60                    medico = Medico.query.filter_by(email=dados['email']).first()61                    if medico and medico.verify_password(dados['password']):62                        token = create_access_token(identity=medico.id, expires_delta=timedelta(minutes=900), fresh=True)63                        refresh_token = create_refresh_token(identity=medico.id, expires_delta=timedelta(minutes=1500))64                        return {'user': 'medico',65                                'token': token,66                                'refresh_token': refresh_token}, 20067                    else:68                        outros = Outros.query.filter_by(email=dados['email']).first()69                        if outros and outros.verify_password(dados['password']):70                            token = create_access_token(identity=outros.id, expires_delta=timedelta(minutes=900), fresh=True)71                            refresh_token = create_refresh_token(identity=outros.id, expires_delta=timedelta(minutes=1500))72                            return {'user': 'outros',73                                    'token': token,74                                    'refresh_token': refresh_token}, 20075                        else:76                            paciente = Paciente.query.filter_by(email=dados['email']).first()77                            if paciente and paciente.verify_password(dados['password']):78                                token = create_access_token(identity=paciente.id, expires_delta=timedelta(minutes=900), fresh=True)79                                refresh_token = create_refresh_token(identity=paciente.id, expires_delta=timedelta(minutes=1500))80                                return {'user': 'paciente',81                                        'token': token,82                                        'refresh_token': refresh_token}, 20083                            else:84                                responsavel = Responsavel.query.filter_by(email=dados['email']).first()85                                if responsavel and responsavel.verify_password(dados['password']):86                                    token = create_access_token(identity=responsavel.id, expires_delta=timedelta(minutes=900), fresh=True)87                                    refresh_token = create_refresh_token(identity=responsavel.id, expires_delta=timedelta(minutes=1500)) 88                                    return  {'user': 'responsavel',89                                             'token': token,90                                             'refresh_token': refresh_token}, 200                                 91                                else: 92                                    return {'error': 'email ou senha inválidos'}, 401...test_company_controller.py
Source:test_company_controller.py  
...9def test_get_companies(app, db):10    from flask_jwt_extended import create_access_token11    with app.app_context():12        client = app.test_client()13        access_token = create_access_token(1)14        headers = {"Authorization": "Bearer {}".format(access_token)}15        url = "/companies"16        response = client.get(url, headers=headers)17        output = json.loads(response.get_data())18        print(output)19        assert output["pagination"]["itens_count"] == 6720        assert not output["has_error"]21        assert response.status_code == 20022def test_view_company(app, db):23    from flask_jwt_extended import create_access_token24    with app.app_context():25        client = app.test_client()26        access_token = create_access_token(1)27        headers = {"Authorization": "Bearer {}".format(access_token)}28        url = "/company/67"29        response = client.get(url, headers=headers)30        output = json.loads(response.get_data())31        print(output)32        assert not output["has_error"]33        assert response.status_code == 20034def test_delete_company(app, db):35    from flask_jwt_extended import create_access_token36    with app.app_context():37        client = app.test_client()38        access_token = create_access_token(1)39        headers = {"Authorization": "Bearer {}".format(access_token)}40        url = "/company/67"41        response = client.delete(url, headers=headers)42        output = json.loads(response.get_data())43        assert not output["has_error"]44        assert response.status_code == 20045        url = "/companies"46        response = client.get(url, headers=headers)47        output = json.loads(response.get_data())48        print(output)49        assert output["pagination"]["itens_count"] == 6650        assert not output["has_error"]51        assert response.status_code == 20052def test_get_history(app, db):53    from flask_jwt_extended import create_access_token54    with app.app_context():55        client = app.test_client()56        access_token = create_access_token(1)57        headers = {"Authorization": "Bearer {}".format(access_token)}58        url = "/company/^BVSP/history"59        response = client.get(url, headers=headers)60        output = json.loads(response.get_data())61        assert len(output.get("history", []))62        assert not output["has_error"]63        assert response.status_code == 20064def test_post_company(app, db):65    from flask_jwt_extended import create_access_token66    with app.app_context():67        client = app.test_client()68        access_token = create_access_token(1)69        headers = {"Authorization": "Bearer {}".format(access_token)}70        url = "/company"71        input = {"name": "teste", "symbol": "teste", "peso": 0.0}72        response = client.post(url, data=input, headers=headers)73        output = json.loads(response.get_data())74        print(output)75        assert output["has_error"]76        assert output["message"] == "Ocorreram erros no preenchimento do formulário."...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
