home

Web Back-End Microservices Project 3 Notebook

Richard Stanley

Kavit Meghpara

Dependencies:

sudo apt-get install nginx -y;
sudo gem install foreman;
sudo pip3 install . -v;
sudo apt install --yes docker.io;
sudo usermod -aG docker $USER;
sudo pip3 install cassandra-driver; # works with clustering

Log out of user, and back in...

python3 dbManagement/cassandraManagement.py;
# this will take 60 seconds, since there are two other clusters
# that spin up during the process, any connection attempted 
# to the database will fail if you don't wait for the clusters to spin up fully.
foreman start;
In [1]:
!python3 dbManagement/cassandraManagement.py;
# Output:
 Running Database Management... 
 removing skylla containers... 
 spinning up the initial scalla container... 
453998bcbfc5214f2ae0cd25f1063ac744250f973139dcd68934c3efdee23b06
 waiting 60 seconds so that other clusters will be able to connect... 
 connecting clusters... 

 cluster_name
--------------
             

(1 rows)
 spinning up two more clusters... 

 cluster_name
--------------
             

(1 rows)

 cluster_name
--------------
             

(1 rows)
 Finished Database Management... 
In [1]:
!foreman start;
# Output
12:28:56 Articles.1 | started with pid 9601
12:28:56 Users.1    | started with pid 9602
12:28:56 Tags.1     | started with pid 9604
12:28:56 Comments.1 | started with pid 9606
12:28:56 Rss.1      | started with pid 9608
12:28:56 Rss.1      | 12:28:56 rss0.1 | started with pid 9617
12:28:56 Rss.1      | 12:28:56 rss1.1 | started with pid 9618
12:28:56 Rss.1      | 12:28:56 rss2.1 | started with pid 9620
12:28:56 Rss.1      | 12:28:56 rss3.1 | started with pid 9622
12:28:56 Tags.1     | 12:28:56 tags0.1 | started with pid 9626
12:28:56 Tags.1     | 12:28:56 tags1.1 | started with pid 9627
12:28:56 Tags.1     | 12:28:56 tags2.1 | started with pid 9629
12:28:56 Tags.1     | 12:28:56 tags3.1 | started with pid 9631
12:28:56 Articles.1 | 12:28:56 articles0.1 | started with pid 9633
12:28:56 Articles.1 | 12:28:56 articles1.1 | started with pid 9637
12:28:56 Articles.1 | 12:28:56 articles2.1 | started with pid 9638
12:28:56 Articles.1 | 12:28:56 articles3.1 | started with pid 9641
12:28:56 Comments.1 | 12:28:56 comments0.1 | started with pid 9643
12:28:56 Comments.1 | 12:28:56 comments1.1 | started with pid 9648
12:28:56 Comments.1 | 12:28:56 comments2.1 | started with pid 9650
12:28:56 Comments.1 | 12:28:56 comments3.1 | started with pid 9654
12:28:56 Users.1    | 12:28:56 users0.1 | started with pid 9640
12:28:56 Users.1    | 12:28:56 users1.1 | started with pid 9644
12:28:56 Users.1    | 12:28:56 users2.1 | started with pid 9652
12:28:56 Users.1    | 12:28:56 users3.1 | started with pid 9658
12:28:57 Rss.1      | 12:28:57 rss2.1 |  * Serving Flask app "rss" (lazy loading)
12:28:57 Rss.1      | 12:28:57 rss2.1 |  * Environment: development
12:28:57 Rss.1      | 12:28:57 rss2.1 |  * Debug mode: on
12:28:57 Rss.1      | 12:28:57 rss2.1 |  * Running on http://127.0.0.1:9002/ (Press CTRL+C to quit)
12:28:57 Rss.1      | 12:28:57 rss2.1 |  * Restarting with stat
12:28:57 Articles.1 | 12:28:57 articles1.1 |  * Serving Flask app "articles" (lazy loading)
12:28:57 Articles.1 | 12:28:57 articles1.1 |  * Environment: development
12:28:57 Articles.1 | 12:28:57 articles1.1 |  * Debug mode: on
12:28:57 Articles.1 | 12:28:57 articles3.1 |  * Serving Flask app "articles" (lazy loading)
12:28:57 Articles.1 | 12:28:57 articles3.1 |  * Environment: development
12:28:57 Articles.1 | 12:28:57 articles3.1 |  * Debug mode: on
12:28:57 Rss.1      | 12:28:57 rss3.1 |  * Serving Flask app "rss" (lazy loading)
12:28:57 Rss.1      | 12:28:57 rss3.1 |  * Environment: development
12:28:57 Rss.1      | 12:28:57 rss3.1 |  * Debug mode: on
12:28:57 Articles.1 | 12:28:57 articles1.1 |  * Running on http://127.0.0.1:5001/ (Press CTRL+C to quit)
12:28:57 Articles.1 | 12:28:57 articles1.1 |  * Restarting with stat
12:28:57 Articles.1 | 12:28:57 articles3.1 |  * Running on http://127.0.0.1:5003/ (Press CTRL+C to quit)
12:28:57 Articles.1 | 12:28:57 articles3.1 |  * Restarting with stat
12:28:57 Rss.1      | 12:28:57 rss3.1 |  * Running on http://127.0.0.1:9003/ (Press CTRL+C to quit)
12:28:57 Rss.1      | 12:28:57 rss3.1 |  * Restarting with stat
12:28:58 Rss.1      | 12:28:58 rss0.1 |  * Serving Flask app "rss" (lazy loading)
12:28:58 Rss.1      | 12:28:58 rss0.1 |  * Environment: development
12:28:58 Rss.1      | 12:28:58 rss0.1 |  * Debug mode: on
12:28:58 Tags.1     | 12:28:58 tags0.1 |  * Serving Flask app "tags" (lazy loading)
12:28:58 Tags.1     | 12:28:58 tags0.1 |  * Environment: development
12:28:58 Tags.1     | 12:28:58 tags0.1 |  * Debug mode: on
12:28:58 Users.1    | 12:28:58 users1.1 |  * Serving Flask app "users" (lazy loading)
12:28:58 Users.1    | 12:28:58 users1.1 |  * Environment: development
12:28:58 Users.1    | 12:28:58 users1.1 |  * Debug mode: on
12:28:58 Rss.1      | 12:28:58 rss0.1 |  * Running on http://127.0.0.1:9000/ (Press CTRL+C to quit)
12:28:58 Tags.1     | 12:28:58 tags0.1 |  * Running on http://127.0.0.1:7000/ (Press CTRL+C to quit)
12:28:58 Comments.1 | 12:28:58 comments2.1 |  * Serving Flask app "comments" (lazy loading)
12:28:58 Comments.1 | 12:28:58 comments2.1 |  * Environment: development
12:28:58 Comments.1 | 12:28:58 comments2.1 |  * Debug mode: on
12:28:58 Tags.1     | 12:28:58 tags0.1 |  * Restarting with stat
12:28:58 Tags.1     | 12:28:58 tags3.1 |  * Serving Flask app "tags" (lazy loading)
12:28:58 Tags.1     | 12:28:58 tags3.1 |  * Environment: development
12:28:58 Tags.1     | 12:28:58 tags3.1 |  * Debug mode: on
12:28:58 Rss.1      | 12:28:58 rss0.1 |  * Restarting with stat
12:28:58 Articles.1 | 12:28:58 articles0.1 |  * Serving Flask app "articles" (lazy loading)
12:28:58 Articles.1 | 12:28:58 articles0.1 |  * Environment: development
12:28:58 Articles.1 | 12:28:58 articles0.1 |  * Debug mode: on
12:28:58 Tags.1     | 12:28:58 tags2.1 |  * Serving Flask app "tags" (lazy loading)
12:28:58 Tags.1     | 12:28:58 tags2.1 |  * Environment: development
12:28:58 Tags.1     | 12:28:58 tags2.1 |  * Debug mode: on
12:28:58 Users.1    | 12:28:58 users0.1 |  * Serving Flask app "users" (lazy loading)
12:28:58 Users.1    | 12:28:58 users0.1 |  * Environment: development
12:28:58 Users.1    | 12:28:58 users0.1 |  * Debug mode: on
12:28:58 Comments.1 | 12:28:58 comments1.1 |  * Serving Flask app "comments" (lazy loading)
12:28:58 Comments.1 | 12:28:58 comments1.1 |  * Environment: development
12:28:58 Comments.1 | 12:28:58 comments1.1 |  * Debug mode: on
12:28:58 Users.1    | 12:28:58 users1.1 |  * Running on http://127.0.0.1:6001/ (Press CTRL+C to quit)
12:28:58 Users.1    | 12:28:58 users1.1 |  * Restarting with stat
12:28:58 Tags.1     | 12:28:58 tags3.1 |  * Running on http://127.0.0.1:7003/ (Press CTRL+C to quit)
12:28:58 Comments.1 | 12:28:58 comments2.1 |  * Running on http://127.0.0.1:8002/ (Press CTRL+C to quit)
12:28:58 Tags.1     | 12:28:58 tags3.1 |  * Restarting with stat
12:28:58 Tags.1     | 12:28:58 tags2.1 |  * Running on http://127.0.0.1:7002/ (Press CTRL+C to quit)
12:28:58 Tags.1     | 12:28:58 tags2.1 |  * Restarting with stat
12:28:58 Articles.1 | 12:28:58 articles0.1 |  * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
12:28:58 Rss.1      | 12:28:58 rss1.1 |  * Serving Flask app "rss" (lazy loading)
12:28:58 Articles.1 | 12:28:58 articles0.1 |  * Restarting with stat
12:28:58 Comments.1 | 12:28:58 comments2.1 |  * Restarting with stat
12:28:58 Rss.1      | 12:28:58 rss1.1 |  * Environment: development
12:28:58 Rss.1      | 12:28:58 rss1.1 |  * Debug mode: on
12:28:58 Tags.1     | 12:28:58 tags1.1 |  * Serving Flask app "tags" (lazy loading)
12:28:58 Tags.1     | 12:28:58 tags1.1 |  * Environment: development
12:28:58 Tags.1     | 12:28:58 tags1.1 |  * Debug mode: on
12:28:58 Users.1    | 12:28:58 users0.1 |  * Running on http://127.0.0.1:6000/ (Press CTRL+C to quit)
12:28:58 Comments.1 | 12:28:58 comments1.1 |  * Running on http://127.0.0.1:8001/ (Press CTRL+C to quit)
12:28:58 Comments.1 | 12:28:58 comments1.1 |  * Restarting with stat
12:28:58 Users.1    | 12:28:58 users0.1 |  * Restarting with stat
12:28:58 Comments.1 | 12:28:58 comments3.1 |  * Serving Flask app "comments" (lazy loading)
12:28:58 Comments.1 | 12:28:58 comments3.1 |  * Environment: development
12:28:58 Comments.1 | 12:28:58 comments3.1 |  * Debug mode: on
12:28:58 Users.1    | 12:28:58 users3.1 |  * Serving Flask app "users" (lazy loading)
12:28:58 Users.1    | 12:28:58 users3.1 |  * Environment: development
12:28:58 Users.1    | 12:28:58 users3.1 |  * Debug mode: on
12:28:58 Rss.1      | 12:28:58 rss1.1 |  * Running on http://127.0.0.1:9001/ (Press CTRL+C to quit)
12:28:58 Comments.1 | 12:28:58 comments0.1 |  * Serving Flask app "comments" (lazy loading)
12:28:58 Rss.1      | 12:28:58 rss1.1 |  * Restarting with stat
12:28:58 Comments.1 | 12:28:58 comments0.1 |  * Environment: development
12:28:58 Comments.1 | 12:28:58 comments0.1 |  * Debug mode: on
12:28:58 Users.1    | 12:28:58 users2.1 |  * Serving Flask app "users" (lazy loading)
12:28:58 Users.1    | 12:28:58 users3.1 |  * Running on http://127.0.0.1:6003/ (Press CTRL+C to quit)
12:28:58 Users.1    | 12:28:58 users3.1 |  * Restarting with stat
12:28:58 Tags.1     | 12:28:58 tags1.1 |  * Running on http://127.0.0.1:7001/ (Press CTRL+C to quit)
12:28:58 Comments.1 | 12:28:58 comments3.1 |  * Running on http://127.0.0.1:8003/ (Press CTRL+C to quit)
12:28:58 Tags.1     | 12:28:58 tags1.1 |  * Restarting with stat
12:28:58 Comments.1 | 12:28:58 comments3.1 |  * Restarting with stat
12:28:58 Users.1    | 12:28:58 users2.1 |  * Environment: development
12:28:58 Users.1    | 12:28:58 users2.1 |  * Debug mode: on
12:28:58 Comments.1 | 12:28:58 comments0.1 |  * Running on http://127.0.0.1:8000/ (Press CTRL+C to quit)
12:28:58 Comments.1 | 12:28:58 comments0.1 |  * Restarting with stat
12:28:58 Articles.1 | 12:28:58 articles2.1 |  * Serving Flask app "articles" (lazy loading)
12:28:58 Articles.1 | 12:28:58 articles2.1 |  * Environment: development
12:28:58 Articles.1 | 12:28:58 articles2.1 |  * Debug mode: on
12:28:58 Users.1    | 12:28:58 users2.1 |  * Running on http://127.0.0.1:6002/ (Press CTRL+C to quit)
12:28:58 Users.1    | 12:28:58 users2.1 |  * Restarting with stat
12:28:58 Articles.1 | 12:28:58 articles2.1 |  * Running on http://127.0.0.1:5002/ (Press CTRL+C to quit)
12:28:58 Articles.1 | 12:28:58 articles2.1 |  * Restarting with stat
12:28:59 Rss.1      | 12:28:59 rss2.1 |  * Debugger is active!
12:28:59 Rss.1      | 12:28:59 rss2.1 |  * Debugger PIN: 269-117-822
12:28:59 Rss.1      | 12:28:59 rss3.1 |  * Debugger is active!
12:28:59 Rss.1      | 12:28:59 rss3.1 |  * Debugger PIN: 269-117-822
12:28:59 Articles.1 | 12:28:59 articles0.1 |  * Debugger is active!
12:28:59 Articles.1 | 12:28:59 articles0.1 |  * Debugger PIN: 269-117-822
12:28:59 Users.1    | 12:28:59 users2.1 |  * Debugger is active!
12:28:59 Users.1    | 12:28:59 users2.1 |  * Debugger PIN: 269-117-822
12:28:59 Articles.1 | 12:28:59 articles1.1 |  * Debugger is active!
12:28:59 Articles.1 | 12:28:59 articles3.1 |  * Debugger is active!
12:28:59 Articles.1 | 12:28:59 articles3.1 |  * Debugger PIN: 269-117-822
12:28:59 Articles.1 | 12:28:59 articles1.1 |  * Debugger PIN: 269-117-822
12:28:59 Tags.1     | 12:28:59 tags1.1 |  * Debugger is active!
12:29:00 Tags.1     | 12:29:00 tags1.1 |  * Debugger PIN: 269-117-822
12:29:00 Users.1    | 12:29:00 users3.1 |  * Debugger is active!
12:29:00 Users.1    | 12:29:00 users3.1 |  * Debugger PIN: 269-117-822
12:29:00 Users.1    | 12:29:00 users1.1 |  * Debugger is active!
12:29:00 Users.1    | 12:29:00 users1.1 |  * Debugger PIN: 269-117-822
12:29:00 Comments.1 | 12:29:00 comments1.1 |  * Debugger is active!
12:29:00 Tags.1     | 12:29:00 tags0.1 |  * Debugger is active!
12:29:00 Tags.1     | 12:29:00 tags0.1 |  * Debugger PIN: 269-117-822
12:29:00 Comments.1 | 12:29:00 comments1.1 |  * Debugger PIN: 269-117-822
12:29:00 Comments.1 | 12:29:00 comments3.1 |  * Debugger is active!
12:29:00 Comments.1 | 12:29:00 comments3.1 |  * Debugger PIN: 269-117-822
12:29:00 Rss.1      | 12:29:00 rss0.1 |  * Debugger is active!
12:29:00 Rss.1      | 12:29:00 rss0.1 |  * Debugger PIN: 269-117-822
12:29:00 Tags.1     | 12:29:00 tags2.1 |  * Debugger is active!
12:29:00 Tags.1     | 12:29:00 tags2.1 |  * Debugger PIN: 269-117-822
12:29:00 Tags.1     | 12:29:00 tags3.1 |  * Debugger is active!
12:29:00 Comments.1 | 12:29:00 comments0.1 |  * Debugger is active!
12:29:00 Tags.1     | 12:29:00 tags3.1 |  * Debugger PIN: 269-117-822
12:29:00 Users.1    | 12:29:00 users0.1 |  * Debugger is active!
12:29:00 Users.1    | 12:29:00 users0.1 |  * Debugger PIN: 269-117-822
12:29:00 Comments.1 | 12:29:00 comments0.1 |  * Debugger PIN: 269-117-822
12:29:00 Rss.1      | 12:29:00 rss1.1 |  * Debugger is active!
12:29:00 Rss.1      | 12:29:00 rss1.1 |  * Debugger PIN: 269-117-822
12:29:00 Comments.1 | 12:29:00 comments2.1 |  * Debugger is active!
12:29:00 Comments.1 | 12:29:00 comments2.1 |  * Debugger PIN: 269-117-822
12:29:00 Articles.1 | 12:29:00 articles2.1 |  * Debugger is active!
12:29:00 Articles.1 | 12:29:00 articles2.1 |  * Debugger PIN: 269-117-822

In a second terminal, navigate to the /test folder and run:

In [8]:
!py.test tests/.;
============================= test session starts ==============================
platform linux -- Python 3.6.7, pytest-4.4.1, py-1.8.0, pluggy-0.9.0
rootdir: /home/audstanley/python/web-backend/webBackendProject3
plugins: tavern-0.26.3
collected 4 items                                                              

tests/test_articles.tavern.yaml .                                        [ 25%]
tests/test_comments.tavern.yaml .                                        [ 50%]
tests/test_tags.tavern.yaml .                                            [ 75%]
tests/test_users.tavern.yaml .                                           [100%]

=========================== 4 passed in 0.46 seconds ===========================

if you need a username and password for endpoints that require login:

username: audstanley password: password

Endpoints:

Articles:
    GET:
        http://localhost/articles
        http://localhost/articles/n/<int:numberOfTheLatestArticles>
        http://localhost/articles/newest
        http://localhost/articles/n/<int:numOfArticles>
        http://localhost/articles/<string:title>
        http://localhost/articles/by-id/<string:article_id>

    POST/PUT/DELETE
        http://localhost/articles

Users:
    GET:
        http://localhost/users/<string:username>

    POST/PUT/DELETE:
        http://localhost/users

Tags:
    GET:
        http://localhost/tags
        http://localhost/tags/newest
        http://localhost/tags/<string:tag_name>
    POST:
        http://localhost/tags
        http://localhost/tags/articles
    DELETE:
        http://localhost/tags


Comments:
    GET:
        http://localhost/comments
        http://localhost/comments/<string:article_name>
    POST/DELETE:
        http://localhost/comments

Rss:
    GET:
        http://localhost/rss/summary
        http://localhost/rss/feed
        http://localhost/rss/commentFeed

Exmple of Database before running tests: