Git Product home page Git Product logo

isabella232 / azurite-tox-automation Goto Github PK

View Code? Open in Web Editor NEW

This project forked from azure-samples/azurite-tox-automation

0.0 0.0 0.0 51 KB

Sample code showing that how to manage Azurite as a running background task both on local and in a container by aiming local automation tools in general and tox in this example.

License: MIT License

Dockerfile 16.52% Shell 6.44% Python 77.04%

azurite-tox-automation's Introduction

page_type languages products description urlFragment
sample
python
yaml
dockerfile
azure
azure-blob-storage
This sample demonstrates how to manage Azurite as a background task both on local and in a container.
azurite-tox-automation

Running Azurite in Tox Automation

Overview

This repo presents a sample for automating tests required Azurite in Tox which mainly focuses running the service as a background process in a container and also on local.

The code contains two simple Fast API calls, one for uploading data.txt into a blob storage and one for uploading the txt to local. And same scenario in the code is tested by reproduction with Azurite in conftest.py.

tox.ini file includes two environments, first environment is for running the tests in a Linux container which may be a case for isolation required scenarios. And the other environment is for the scenarios where local automation is satisfactory.

Getting Started

Build

Folder structure

Here's the folder structure for the sample:

  • container
    • Dockerfile - Dockerfile which builds Linux container with all required components for running tests
    • service_start.sh - shell script being used for running Azurite in the container
  • data - a data.txt sample to upload to/download from blob storage
  • src
    • __init__.py
    • app.py - code file including FastAPI calls
    • main.py
    • .env - Environment variable files which includes Storage Account connection string to run FastAPI calls
  • tests
    • __init__.py
    • conftest.py - Configuration file for running tests
    • test_example.py - Azure Blob Storage Test Code
    • .test_env - Environment variable connection details for Azurite
  • requirements.txt - Required pip packages to run the code and tests
  • tox.ini - tox configuration file

Prerequisites

The minimum requirement to see tests are running in the container and on your local is mainly:

If you prefer to run FastAPI calls to see what code does which isn't the main focus of the sample though, you need also a real blob storage in Azure Portal which means, following are prerequisites:

For a better UI experience, it's recommended to use Storage Explorer to track the blob processes on your desktop;

Install and Run Tox with Azurite

As it's mentioned in Prerequisites section, we need to install Tox and then run the environments.

Running tox is platform agnostic. As soon as you have a Docker installed local environment to build a container, you can use Windows or Linux or Powershell/cmd or wsl/bash.

a. Installing Tox

Tox is an PyPI package which means as soon as you have Pip installation on your local, you can install it via

# Install Tox
pip install tox

b. Running Tox environments

In tox.ini file, you can see two environments in envlist section.

  • test_azurite_in_container: virtual environment which builds our Linux image with the repo code and Azurite service script then run the tests in this container.

  • test_azurite_on_local: virtual environment which runs all prerequisites for tests and run them on your local.

To run a specific environment in tox;

# Run test_azurite_in_container venv
tox -e test_azurite_in_container

# Run test_azurite_on_local venv
tox -e test_azurite_on_local

To run both environments at once;

# Run all env at once
tox

the output should be similar to:

Tox Msg

At glance

If you run test_azurite_in_container environment, you can see that it builds a container image on your local.

  • The image is used to run the tests and build with Dockerfile

  • On manual execution, Azurite kills the session and requires a new cmd session start. To run Azurite service at the background in the container, service_starts.sh which starts the service is copied into the container and being triggered from outside in tox environment execution.

  • When tox completes test_azurite_in_container build, you will have a container image called 'pytest_linux' on your local. You can check it

# List docker images
docker images
  • For manual checks, if you prefer to see the container content being run, you can run the image interactively
# Run image interactively
docker run -it pytest_linux bash

License

See LICENSE.

Code of Conduct

See CODE_OF_CONDUCT

Contributing

See CONTRIBUTING Additionally kindly check Issue Template and PR Template

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.