Giter VIP home page Giter VIP logo

automation_api_test_pytest's Introduction

Testing Restful API with Python Pytest

Purpose

Directory Structure

git ls-tree -r --name-only HEAD | tree --fromfile
.
├── .gitignore
├── README.md
├── business
│   ├── api_request.py
│   ├── books
│   │   ├── books_api.py
│   │   └── books_database.py
│   ├── database_execution.py
│   └── users
│       ├── users_api.py
│       └── users_database.py
├── configurations
│   ├── __init__.py
│   ├── api_domain.py
│   └── database.py
├── conftest.py
├── deployments
│   ├── Dockerfile
│   ├── Jenkinsfile
│   └── job_configurations.json
├── logger.py
├── requirements.txt
└── test_suites
    ├── test_books
    │   └── test_get_books_id.py
    └── test_users
        ├── test_get_users.py
        └── test_post_users.py

Step-by-step

Option 1: Build up a simple Docker

Input the command

docker build -t pytest_learn_image -f ./deployments/Dockerfile .

Option 2: Build up Jenkins Docker

Ref: How to Run Jenkins Container as Systemd Service with Docker

  1. Build a Jenkins run in Docker
  • --name jenkins : Container naming
  • -p 8080:8080 : Container 8080 port mapping to localhost 8080 port, which for jenkins administrator login.
  • -p 50000:50000 Container 50000 port mapping to localhost 50000 port, which for jenkins slave node's JNLP (Java Web Start) port.
  • -v ~/jenkins_home:/var/jenkins_home : Build up docker volume. Container /var/jenkins_home mapping to localhost ~/jenkins_home.
  • -v /var/run/docker.sock:/var/run/docker.sock : Let containers can use docker daemon.
$ docker run --name jenkins -p 8080:8080 -p 50000:50000 -v ~/jenkins_home:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock jenkins/jenkins:lts
  1. Started the container and command for installation
$ apt-get update
$ apt install python3
$ apt install python3.11-venv
$ apt-get install -y wget
$ wget https://github.com/allure-framework/allure2/releases/download/2.14.0/allure-2.14.0.zip
$ unzip allure-2.14.0.zip
$ export PATH=$PATH:/path/to/allure-2.14.0/bin

Note: If docker cli encountering no permission

$ docker exec -u 0 -it {#CONTAINER_ID} /bin/bash
  1. Launch browser way to http://localhost:8080/
    a. Unlock the Jenkins with password. The password form container's logs when u started the container.
    b. Install suggested plugins. Ref. How to Run Jenkins Container as Systemd Service with Docker

  2. Change Jenkinsfile configurations
    a. GIT_REPO : Ur repo
    b. _GIT_CREDENTIALS_ID : From Jenkins credentials setting Ref How To Add Git Credentials In Jenkins
    Ref. Configuring the Git Credentials in Jenkins Jenkinsfile_config.png

  3. Change job configurations In this case, the pipeline job will separate by services.
    Thus, We may create the pipeline by services.
    Before create the Jenkins pipeline, we need to add job in job_configuration.json. \

└── test_suites
    ├── test_books
    │   └── test_get_books_id.py
    └── test_users
        ├── test_get_users.py
        └── test_post_users.py

job_config_json.png

  1. Build Jenkins pipeline, select [new items] build a new job. jenkins_new_item.png

  2. Give a job naming and select pipeline jenkins_choose_pipeline.png

  3. Do the config

  1. Okieee, then run the job. Click [Build parameters] jenkins_job_builds_params.png

  2. Input parameters (optional, if didn't input then run as default) job_run_build.png

  3. Job complete jenkins_job_complete.png

  4. May way to allure report to check the result :) allure_report.png

automation_api_test_pytest's People

Contributors

taurus5650 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.