Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
andgineer committed Apr 10, 2019
1 parent 0d7005d commit 7d4d6a9
Show file tree
Hide file tree
Showing 31 changed files with 14,539 additions and 14 deletions.
4 changes: 2 additions & 2 deletions bombard/bombardier.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, supply: dict=None, args=None, campaign_book: dict=None, ok_st
"""
:param args.threads: number of threads to use to request
"""
self.supply = supply
self.supply = supply if supply is not None else {}
self.args = args
self.campaign = campaign_book
self.ok = ok_statuses if ok_statuses is not None else DEFAULT_OK
Expand Down Expand Up @@ -177,7 +177,7 @@ def worker(self, thread_id, ammo):
+ ' ' + (red(resp) if status == EXCEPTION_STATUS else '')
)
except Exception as e:
log.info(pretty_url + ' ' + red(str(e)))
log.info(pretty_url + ' ' + red(str(e)), exc_info=True)

def reload(self, requests, repeat=None, **kwargs):
"""
Expand Down
2 changes: 1 addition & 1 deletion bombard/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def guess_type(value: str):
return value


def setup_logging(level: int, log_file_name: Optional[str]):
def setup_logging(level: int, log_file_name: Optional[str] = None):
log.setLevel(level)
if log_file_name is not None:
log.addHandler(
Expand Down
34 changes: 23 additions & 11 deletions bombard/tests/test_http_requests.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
import unittest
from unittest.mock import MagicMock
from bombard import bombardier


TEST_REQUEST = {
'url': 'https://localhost/users',
'method': 'GET',
'headers': {'x-x': 'json'}
from bombard import http_request
from bombard.main import setup_logging
import logging


TEST_AMMO = {
'request': {
'url': 'https://localhost/users',
'method': 'GET',
'headers': {'x-x': 'json'}
},
'id': 1,
'name': 'request',
'supply': {},
}


class FakeArgs:
threads = 1
timeout = 3
ms = False
threshold = 1000
quiet = False


class TestHttpRequests(unittest.TestCase):
def setUp(self):
bombardier.http.client.HTTPSConnection.request = MagicMock()
bombardier.http.client.HTTPSConnection.getresponse = MagicMock()
http_request.http.client.HTTPSConnection.request = MagicMock()
http_request.http.client.HTTPSConnection.getresponse = MagicMock()
setup_logging(logging.DEBUG)

def testRequest(self):
bombardier.Bombardier(args=FakeArgs()).make_request(**TEST_REQUEST)
bombardier.http.client.HTTPSConnection.request.assert_called_once_with(
bombardier.Bombardier(args=FakeArgs()).worker(1, TEST_AMMO)
http_request.http.client.HTTPSConnection.request.assert_called_once_with(
'GET', '/users', body=None, headers={'x-x': 'json'}
)
bombardier.http.client.HTTPSConnection.getresponse.assert_called_once()
http_request.http.client.HTTPSConnection.getresponse.assert_called_once()


if __name__ == '__main__':
Expand Down
19 changes: 19 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
Binary file added docs/_build/doctrees/environment.pickle
Binary file not shown.
Binary file added docs/_build/doctrees/index.doctree
Binary file not shown.
4 changes: 4 additions & 0 deletions docs/_build/html/.buildinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 4cfb5c9386f6adf285f5fa9c03f3b14c
tags: 645f666f9bcd5a90fca523b33c5a78b7
47 changes: 47 additions & 0 deletions docs/_build/html/_sources/index.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
bombard your app
================
Bombard is a pure Python application to bombard with
hundreds of HTTP-requests.

This is tool for stress-testing with extremely simple
configuration.

You write requests in simple yaml-file (`bombard campaign book`).
And can include a couple of Python lines in it.

If you need more logic you can include external Python file and debug
it in your IDE.

The simplest (but not very useful) example

ammo:
postsList:
url: "https://jsonplaceholder.typicode.com/posts"

More complex example

supply: # you can redefine it from command line (--supply)
host: https://jsonplaceholder.typicode.com/
prepare:
postsList:
url: "{host}posts"
script: |
for post in resp[:3]: # add getPost requests for 1st ten posts in the list
reload(ammo.getPost, id=post['id'])
ammo:
getPost:
url: "{host}posts/{id}"
headers: json

.. toctree::
:maxdepth: 2
:caption: Contents:



Indices and tables
------------------

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

0 comments on commit 7d4d6a9

Please sign in to comment.