|
| 1 | +Dependency Injector + Sanic Example |
| 2 | +===================================== |
| 3 | + |
| 4 | +Application ``giphynavigator`` is a `Sanic <https://sanic.readthedocs.io/en/latest/index.html>`_ + |
| 5 | +`Dependency Injector <http://python-dependency-injector.ets-labs.org/>`_ example application. |
| 6 | + |
| 7 | +Run |
| 8 | +--- |
| 9 | + |
| 10 | +Create virtual environment: |
| 11 | + |
| 12 | +.. code-block:: bash |
| 13 | +
|
| 14 | + virtualenv venv |
| 15 | + . venv/bin/activate |
| 16 | +
|
| 17 | +Install requirements: |
| 18 | + |
| 19 | +.. code-block:: bash |
| 20 | +
|
| 21 | + pip install -r requirements.txt |
| 22 | +
|
| 23 | +To run the application do: |
| 24 | + |
| 25 | +.. code-block:: bash |
| 26 | +
|
| 27 | + export GIPHY_API_KEY=wBJ2wZG7SRqfrU9nPgPiWvORmloDyuL0 |
| 28 | + python -m giphynavigator |
| 29 | +
|
| 30 | +The output should be something like: |
| 31 | + |
| 32 | +.. code-block:: |
| 33 | +
|
| 34 | + [2020-09-23 18:16:31 -0400] [48258] [INFO] Goin' Fast @ http://0.0.0.0:8000 |
| 35 | + [2020-09-23 18:16:31 -0400] [48258] [INFO] Starting worker [48258] |
| 36 | +
|
| 37 | +After that visit http://127.0.0.1:8000/ in your browser or use CLI command (``curl``, ``httpie``, |
| 38 | +etc). You should see something like: |
| 39 | + |
| 40 | +.. code-block:: json |
| 41 | +
|
| 42 | + { |
| 43 | + "query": "Dependency Injector", |
| 44 | + "limit": 10, |
| 45 | + "gifs": [ |
| 46 | + { |
| 47 | + "url": "https://giphy.com/gifs/boxes-dependent-swbf2-6Eo7KzABxgJMY" |
| 48 | + }, |
| 49 | + { |
| 50 | + "url": "https://giphy.com/gifs/depends-J56qCcOhk6hKE" |
| 51 | + }, |
| 52 | + { |
| 53 | + "url": "https://giphy.com/gifs/web-series-ccstudios-bro-dependent-1lhU8KAVwmVVu" |
| 54 | + }, |
| 55 | + { |
| 56 | + "url": "https://giphy.com/gifs/TheBoysTV-friends-friend-weneedeachother-XxR9qcIwcf5Jq404Sx" |
| 57 | + }, |
| 58 | + { |
| 59 | + "url": "https://giphy.com/gifs/netflix-a-series-of-unfortunate-events-asoue-9rgeQXbwoK53pcxn7f" |
| 60 | + }, |
| 61 | + { |
| 62 | + "url": "https://giphy.com/gifs/black-and-white-sad-skins-Hs4YzLs2zJuLu" |
| 63 | + }, |
| 64 | + { |
| 65 | + "url": "https://giphy.com/gifs/always-there-for-you-i-am-here-PlayjhCco9jHBYrd9w" |
| 66 | + }, |
| 67 | + { |
| 68 | + "url": "https://giphy.com/gifs/stream-famous-dollar-YT2dvOByEwXCdoYiA1" |
| 69 | + }, |
| 70 | + { |
| 71 | + "url": "https://giphy.com/gifs/i-love-you-there-for-am-1BhGzgpZXYWwWMAGB1" |
| 72 | + }, |
| 73 | + { |
| 74 | + "url": "https://giphy.com/gifs/life-like-twerk-9hlnWxjHqmH28" |
| 75 | + } |
| 76 | + ] |
| 77 | + } |
| 78 | +
|
| 79 | +.. note:: |
| 80 | + |
| 81 | + To create your own Giphy API key follow this |
| 82 | + `guide <https://support.giphy.com/hc/en-us/articles/360020283431-Request-A-GIPHY-API-Key>`_. |
| 83 | + |
| 84 | +Test |
| 85 | +---- |
| 86 | + |
| 87 | +This application comes with the unit tests. |
| 88 | + |
| 89 | +To run the tests do: |
| 90 | + |
| 91 | +.. code-block:: bash |
| 92 | +
|
| 93 | + py.test giphynavigator/tests.py --cov=giphynavigator |
| 94 | +
|
| 95 | +The output should be something like: |
| 96 | + |
| 97 | +.. code-block:: |
| 98 | +
|
| 99 | + platform darwin -- Python 3.8.3, pytest-5.4.3, py-1.9.0, pluggy-0.13.1 |
| 100 | + plugins: cov-2.10.0, sanic-1.6.1 |
| 101 | + collected 3 items |
| 102 | +
|
| 103 | + giphynavigator/tests.py ... [100%] |
| 104 | +
|
| 105 | + ---------- coverage: platform darwin, python 3.8.3-final-0 ----------- |
| 106 | + Name Stmts Miss Cover |
| 107 | + --------------------------------------------------- |
| 108 | + giphynavigator/__init__.py 0 0 100% |
| 109 | + giphynavigator/__main__.py 4 4 0% |
| 110 | + giphynavigator/application.py 12 0 100% |
| 111 | + giphynavigator/containers.py 6 0 100% |
| 112 | + giphynavigator/giphy.py 14 9 36% |
| 113 | + giphynavigator/handlers.py 10 0 100% |
| 114 | + giphynavigator/services.py 9 1 89% |
| 115 | + giphynavigator/tests.py 34 0 100% |
| 116 | + --------------------------------------------------- |
| 117 | + TOTAL 89 14 84% |
0 commit comments