Best Python code snippet using Kiwi_python
tests.py
Source:tests.py
1from dataclasses import dataclass2import pytest3from src.api_spec import APISpec4from src.endpoint import Endpoint5from src.main import load_api_spec6@pytest.fixture7def global_headers_raw():8 return {9 "header1": "header1_value",10 "header2": "header2_value",11 "header3": "header3_value",12 }13@pytest.fixture14def endpoints_raw():15 return {16 "get_issue_by_key": {17 "url": "/rest/api/2/issue/{key}",18 "verb": "GET",19 "additional_headers": {},20 "remove_global_headers": [],21 "path_parameters": ["key"],22 "query_parameters": {},23 },24 "create_issue": {25 "url": "/rest/api/2/issue",26 "verb": "POST",27 "additional_headers": {28 "header2": "header2_value_overridden",29 "header4": "header4_value",30 },31 "remove_global_headers": ["header3"],32 "path_parameters": [],33 "query_parameters": {},34 },35 }36@pytest.fixture37def endpoints_as_obj():38 return {39 "get_issue_by_key": Endpoint(40 name="get_issue_by_key",41 url="/rest/api/2/issue/{key}",42 verb="GET",43 global_headers={44 "header1": "header1_value",45 "header2": "header2_value",46 "header3": "header3_value",47 },48 additional_headers={},49 remove_global_headers=[],50 path_parameters=["key"],51 query_parameters={},52 ),53 "create_issue": Endpoint(54 name="create_issue",55 url="/rest/api/2/issue",56 verb="POST",57 global_headers={58 "header1": "header1_value",59 "header2": "header2_value",60 "header3": "header3_value",61 },62 additional_headers={63 "header2": "header2_value_overridden",64 "header4": "header4_value",65 },66 remove_global_headers=['header3'],67 path_parameters=[],68 query_parameters={},69 ),70 }71@pytest.fixture72def headers_overridden():73 return {74 "header1": "header1_value",75 "header2": "header2_value_overridden",76 #"header3": "header3_value",77 "header4": "header4_value",78 }79@pytest.fixture80def jira_api_spec_no_yaml(global_headers_raw, endpoints_raw):81 name = "FakeJiraAPISpec"82 api_spec = APISpec(83 name=name, global_headers=global_headers_raw, endpoints_raw=endpoints_raw84 )85 return api_spec86@pytest.fixture87def jira_api_spec():88 path_jira_api_spec = "jira_api_specification.yaml"89 return load_api_spec("JiraAPI", path_jira_api_spec)90def test_jira_api_no_yaml(91 jira_api_spec_no_yaml, global_headers_raw, endpoints_raw, endpoints_as_obj92):93 api_spec = jira_api_spec_no_yaml94 assert api_spec.global_headers == global_headers_raw95 assert api_spec.endpoints_raw == endpoints_raw96 assert api_spec.endpoints == endpoints_as_obj97def test_api_spec_endpoint_headers_overridden(jira_api_spec_no_yaml, headers_overridden, global_headers_raw):98 create_issue = jira_api_spec_no_yaml.get_endpoint("create_issue")99 assert create_issue.headers == headers_overridden100 get_issue_by_key = jira_api_spec_no_yaml.get_endpoint("get_issue_by_key")101 assert get_issue_by_key.headers == global_headers_raw102def test_api_spec_endpoint_ready_url(jira_api_spec_no_yaml):103 create_issue = jira_api_spec_no_yaml.get_endpoint("create_issue")104 assert create_issue.has_path_parameters_in_url is False105 assert create_issue.path_parameters_provided is False106 assert create_issue._actual_path_parameters == {}107 get_issue_by_key = jira_api_spec_no_yaml.get_endpoint("get_issue_by_key")108 assert get_issue_by_key.has_path_parameters_in_url is True109 assert get_issue_by_key._actual_path_parameters == {}110 assert get_issue_by_key.path_parameters_provided is False111 path_parameters = {"key": "ISSUE-1234"}112 get_issue_by_key.provide_path_parameters(path_parameters)113 assert get_issue_by_key._actual_path_parameters == path_parameters114 assert create_issue._actual_path_parameters == {}115# @pytest.mark.skip116# def test_jira_api_spec(jira_api_spec):117# assert jira_api_spec.global_headers == {118# "header1": "header1_value",119# "header2": "header2_value",120# "header3": "header3_value",121# }122#123# endpoints = {124# "get_issue_by_key": Endpoint(125# name="get_issue_by_key",126# url="/rest/api/2/issue/{key}",127# verb="GET",128# global_headers={129# "header1": "header1_value",130# "header2": "header2_value",131# "header3": "header3_value",132# },133# additional_headers={},134# remove_global_headers={},135# path_parameters={},136# query_parameters={},137# ),138# "create_issue": Endpoint(139# name="create_issue",140# url="/rest/api/2/issue",141# verb="POST",142# global_headers={143# "header1": "header1_value",144# "header2": "header2_value",145# "header3": "header3_value",146# },147# additional_headers={148# "header2": "header2_value_overridden",149# "header4": "header4_value",150# },151# remove_global_headers={},152# path_parameters={},153# query_parameters={},154# ),155# }156#157# assert jira_api_spec.endpoints == endpoints158#159# endpoint = jira_api_spec.get_endpoint("create_issue")160# assert endpoint.name == "create_issue"161#162# headers_property = {163# "header1": "header1_value",164# "header2": "header2_value_overridden",165# "header3": "header3_value",166# "header4": "header4_value",167# }168#...
test_issues.py
Source:test_issues.py
...38 response = client.json.post(url, json.dumps(data))39 assert response.status_code == 200, response.data40def test_api_filter_by_subject(client):41 user = f.UserFactory(is_superuser=True)42 f.create_issue(owner=user)43 issue = f.create_issue(subject="some random subject", owner=user)44 url = reverse("issues-list") + "?q=some subject"45 client.login(issue.owner)46 response = client.get(url)47 number_of_issues = len(response.data)48 assert response.status_code == 20049 assert number_of_issues == 1, number_of_issues50def test_api_filter_by_text_1(client):51 user = f.UserFactory(is_superuser=True)52 f.create_issue(owner=user)53 issue = f.create_issue(subject="this is the issue one", owner=user)54 f.create_issue(subject="this is the issue two", owner=issue.owner)55 url = reverse("issues-list") + "?q=one"56 client.login(issue.owner)57 response = client.get(url)58 number_of_issues = len(response.data)59 assert response.status_code == 20060 assert number_of_issues == 161def test_api_filter_by_text_2(client):62 user = f.UserFactory(is_superuser=True)63 f.create_issue(owner=user)64 issue = f.create_issue(subject="this is the issue one", owner=user)65 f.create_issue(subject="this is the issue two", owner=issue.owner)66 url = reverse("issues-list") + "?q=this is the issue one"67 client.login(issue.owner)68 response = client.get(url)69 number_of_issues = len(response.data)70 assert response.status_code == 20071 assert number_of_issues == 172def test_api_filter_by_text_3(client):73 user = f.UserFactory(is_superuser=True)74 f.create_issue(owner=user)75 issue = f.create_issue(subject="this is the issue one", owner=user)76 f.create_issue(subject="this is the issue two", owner=issue.owner)77 url = reverse("issues-list") + "?q=this is the issue"78 client.login(issue.owner)79 response = client.get(url)80 number_of_issues = len(response.data)81 assert response.status_code == 20082 assert number_of_issues == 283def test_api_filter_by_text_4(client):84 user = f.UserFactory(is_superuser=True)85 f.create_issue(owner=user)86 issue = f.create_issue(subject="this is the issue one", owner=user)87 f.create_issue(subject="this is the issue two", owner=issue.owner)88 url = reverse("issues-list") + "?q=one two"89 client.login(issue.owner)90 response = client.get(url)91 number_of_issues = len(response.data)92 assert response.status_code == 20093 assert number_of_issues == 094def test_api_filter_by_text_5(client):95 user = f.UserFactory(is_superuser=True)96 f.create_issue(owner=user)97 issue = f.create_issue(subject="python 3", owner=user)98 url = reverse("issues-list") + "?q=python 3"99 client.login(issue.owner)100 response = client.get(url)101 number_of_issues = len(response.data)102 assert response.status_code == 200103 assert number_of_issues == 1104def test_api_filter_by_text_6(client):105 user = f.UserFactory(is_superuser=True)106 f.create_issue(owner=user)107 issue = f.create_issue(subject="test", owner=user)108 issue.ref = 123109 issue.save()110 print(issue.ref, issue.subject)111 url = reverse("issues-list") + "?q=%s" % (issue.ref)112 client.login(issue.owner)113 response = client.get(url)114 number_of_issues = len(response.data)115 assert response.status_code == 200...
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!!