Skyaz123 / imagesnw

0 stars 0 forks source link

API #1

Open Skyaz123 opened 1 year ago

Skyaz123 commented 1 year ago

Install the necessary libraries:

Install the requests library using pip: pip install requests. Authenticate with Jira:

Generate an API token in Jira (if required). Obtain your Jira username and API token. Use the requests library to authenticate with Jira using basic authentication or API token authentication. Create a test case:

Use the requests library to send a POST request to the Jira API endpoint for creating test cases. Include relevant details such as the test case name, description, project, and issue type in the request payload. Retrieve the test case key or ID from the API response for further use. Update test case status:

Depending on your automation script's execution status, you can update the status of the linked test case in Jira. Use the requests library to send a PUT request to the Jira API endpoint for updating test case status. Include the test case key or ID and the new status in the request payload. Link test case to automation script:

You can add a custom field or a comment to the test case, containing the link or reference to your automation script. Use the requests library to send a PUT request to the Jira API endpoint for updating the test case with the link or reference. Handle errors and exceptions:

Implement error handling in your Python script to catch any exceptions that may occur during the API calls. Check the HTTP status codes of the API responses to ensure the requests were successful. Handle any errors gracefully and log any relevant information for debugging purposes. By following these steps, you can establish a connection between your automation Python script and Jira, allowing you to create test cases, update their status, and link them to your automation script

Skyaz123 commented 1 year ago

To automatically update your test case in Zephyr Squad on Jira after a test is complete in your Python framework with Pytest, you can follow these steps:

Install necessary libraries: Install the required libraries to interact with Jira REST API and handle HTTP requests. You can use the requests library by running pip install requests.

Retrieve test case details: Retrieve the necessary details of the test case from your Python framework. This can include information such as the test case ID or key, test execution status, duration, or any other relevant information that you want to update in Jira.

Update test case in Jira: Use the Jira REST API to update the test case in Zephyr Squad. You can use the requests library to send an HTTP request with the updated information. Here's an example of how to update a test case:

python

import requests

def update_test_case(test_case_key, execution_status, duration):
    url = f'https://your-jira-instance/rest/zapi/latest/execution/{test_case_key}'

    # Set authentication headers (username and API token or password)
    auth = ('username', 'api_token_or_password')

    # Set the request payload with the updated data
    data = {
        'status': execution_status,
        'executionTime': duration
    }

    response = requests.put(url, auth=auth, json=data)

    if response.ok:
        print(f'Test case {test_case_key} updated successfully.')
    else:
        print(f'Failed to update test case {test_case_key}.')
        print('Response:', response.text)

Replace 'your-jira-instance' with the actual URL of your Jira instance. Adjust the authentication details, such as the username and API token or password, to match your credentials.

Customize the update_test_case() function according to your needs. Pass the relevant parameters such as the test case key, execution status, and duration to the function.

Integrate with Pytest: In your Pytest test framework, call the update_test_case() function at the end of each test case or in a test teardown section. Pass the appropriate parameters to update the test case status and duration based on the outcome of the test execution. By following these steps, you can automatically update your test case in Zephyr Squad on Jira after each test is complete in your Python framework with Pytest. Adjust the code according to your specific needs, including the Jira REST API endpoints and the data you want to update in the test case.

Skyaz123 commented 1 year ago
import requests

# Retrieve test case information
test_case_id = 'ZephyrSquadTestCase1'
status = 'Pass'  # Update with the actual status

# Set Jira API endpoint and authentication
url = f'https://lptestingteam.atlassian.net/rest/api/3/issue/pc-4{test_case_id}'
auth = ('skyaz123', 'OWNkMjNjOWYtNDhlZS0zMGZiLWE3ODEtNDE5MGY1NmJiZjVlIDVjMGFlMjUyZTkxZDE2NjkyYTNhMGJhNCBVU0VSX0RFRkFVTFRfTkFNRQ')

# Prepare data for updating the test case
data = {
    'fields': {
        'customfield_10034': status,  # Update with the appropriate custom field ID for status
    }
}

# Send the PUT request to update the test case
response = requests.put(url, auth=auth)

# Process the response

if response.ok: print('Test case updated successfully in Jira.') else: print('Failed to update test case in Jira:', response.text) print ('error =', response.status_code)

Skyaz123 commented 1 year ago
Skyaz123 commented 12 months ago
def date_str_to_julian(date_str):
    year, month, day = map(int, date_str.split('-'))

    def is_leap_year(year):
        return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)

    days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

    if is_leap_year(year):
        days_in_month[1] = 29

    julian_day = day
    for m in range(1, month):
        julian_day += days_in_month[m - 1]

    for y in range(4713, year):
        julian_day += 366 if is_leap_year(y) else 365

    julian_date = int(f"{year}{julian_day:03d}")
    return julian_date

# Example of using the function with a date from the database
date_from_database = "2023-07-11"
julian_date = date_str_to_julian(date_from_database)
print("Julian date for", date_from_database, "is", julian_date)