create account

How to execute automated tests on hivemind by howo

View this thread on: hive.blogpeakd.comecency.com
· @howo · (edited)
$125.80
How to execute automated tests on hivemind
Hey,

If you're working on hivemind like me you will most likely test your change locally by fiddling with the mocks and then realize that that you've broken all the automated tests upon pushing your code on the repository.


![image.png](https://files.peakd.com/file/peakd-hive/howo/23tSzWXZGULETnqZEDqeU3FHxNqftm4c4a95XWMio4F5fS1WcVh4Ad9SAgYYo4NEuZMo9.png)

So obviously it's not optimal to wait for the pipeline to run, but understanding how the test runs can be a little tricky because everything is made to run with the pipeline, so it takes a while to read through all the scripts and steps. I'm here to save you the trouble.

This guide assumes that you have managed to sync hivemind at least once, if you didn't follow this guide: https://peakd.com/hivemind/@howo/hivemind-dev-environment-setup-guide-according-to-my-findings-it-may-or-may-not-be-the-best-way

You also need to install some dependencies:

```
pip install pytest
pip install pytest-parallel
pip install tavern
pip install deepdiff
```

Before running the tests, you need to sync your local hivemind database with all the mocks (there's a similar command on the other guide, if you don't understand how to run this command, follow the other guide):

```
hive sync --log-mask-sensitive-data --test-max-block=5000026 --test-profile=False --database-url postgresql://postgres:root@localhost:5532/hive --mock-block-data-path /home/howo/projects/hivemind/mock_data/block_data/follow_op/mock_block_data_follow.json /home/howo/projects/hivemind/mock_data/block_data/follow_op/mock_block_data_follow_tests.json /home/howo/projects/hivemind/mock_data/block_data/community_op/mock_block_data_community.json /home/howo/projects/hivemind/mock_data/block_data/reblog_op/mock_block_data_reblog.json /home/howo/projects/hivemind/mock_data/block_data/reblog_op/mock_block_data_reblog_delete.json /home/howo/projects/hivemind/mock_data/block_data/payments_op/mock_block_data_payments.json /home/howo/projects/hivemind/mock_data/block_data/notify_op/mock_block_data.json --mock-vops-data-path /home/howo/projects/hivemind/mock_data/block_data/community_op/mock_vops_data_community.json --community-start-block 4998000
```

Once that's done it's time to execute the tests.

some disclaimer: I tried and tried to use tox and other venvs like the pipeline, nothing works for 500 different reasons so I just gave up and run everything natively.

First run hivemind as a server to test scripts against:

```
hive --database-url postgresql://postgres:root@localhost:5532/hive server
```

then download this repository:

```
git clone https://gitlab.syncad.com/hive/tests_api
```

Now we need to define a bunch of env variables:
```
export TAVERN_DIR=/home/howo/projects/hivemind/tests/api_tests/hivemind/tavern # change it to whatever location hivemind is on your computer
export HIVEMIND_ADDRESS=localhost
export HIVEMIND_PORT=8080
export PYTHONPATH="${PYTHONPATH}:/home/howo/projects/test-tools/package:/home/howo/projects/tests_api/scripts/" # change this to where you downloaded tests_api
```

and finally you're ready !

you can execute a single test by passing the full path to the tavern yaml file:

`pytest /home/howo/projects/hivemind/tests/api_tests/hivemind/tavern/bridge_api_patterns/get_trending_topics/empty.tavern.yaml`

or test everything at once:

```
cd ~/projects/hivemind/tests/api_tests/hivemind/tavern # change it to whatever location hivemind is on your computer
find $directory -type f -name "*.tavern.yaml" | pytest --workers auto
```

note that this command requires https://pypi.org/project/pytest-parallel/ to be installed, it **drastically** speeds up testing by running it on multiple cores.

you will get an output like this (with ideally no Fs, each F means a test failed):


![image.png](https://files.peakd.com/file/peakd-hive/howo/23swbmpAe2zsopS73xha4DVSEgxsx7vE88PQFiWZoAcHU5Xj72z4pUts297GB1hwih4nu.png)


and for every failed case, the output will be stored next to the tavern file:

![image.png](https://files.peakd.com/file/peakd-hive/howo/23t7Di1BtRUAwTgnNk4E4Q5QV6ZaJhnPWp19QAkvYHiEwEgL4t81ZFbTHNafbuNJk34YH.png)

so you can compare it with the `.pat.json` (the expected output)

thanks for reading ! If you have any questions feel free to ask them in the comments.

@howo

![](https://i.imgur.com/oPJ63jA.png)
<center><sup>You can vote for our witness directly using Hivesigner <a href="https://hivesigner.com/sign/account-witness-vote?witness=steempress&approve=1">here</a>.</sup></center>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 241 others
👎  ,
properties (23)
authorhowo
permlinkhow-to-execute-automated-tests-on-hivemind
categoryhivemind
json_metadata{"app":"peakd/2022.04.5","format":"markdown","image":["https://files.peakd.com/file/peakd-hive/howo/23tSzWXZGULETnqZEDqeU3FHxNqftm4c4a95XWMio4F5fS1WcVh4Ad9SAgYYo4NEuZMo9.png","https://files.peakd.com/file/peakd-hive/howo/23swbmpAe2zsopS73xha4DVSEgxsx7vE88PQFiWZoAcHU5Xj72z4pUts297GB1hwih4nu.png","https://files.peakd.com/file/peakd-hive/howo/23t7Di1BtRUAwTgnNk4E4Q5QV6ZaJhnPWp19QAkvYHiEwEgL4t81ZFbTHNafbuNJk34YH.png","https://i.imgur.com/oPJ63jA.png"],"tags":["hivemind","automated","tests","hive"],"users":["howo","localhost"]}
created2022-04-24 20:08:48
last_update2023-06-02 14:27:09
depth0
children7
last_payout2022-05-01 20:08:48
cashout_time1969-12-31 23:59:59
total_payout_value62.966 HBD
curator_payout_value62.837 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length4,482
author_reputation515,737,941,459,006
root_title"How to execute automated tests on hivemind "
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id112,606,506
net_rshares117,738,254,369,597
author_curate_reward""
vote details (307)
@cal02 ·
Gracias por tu apoyo, es un gran incentivo para nuestra participación.
properties (22)
authorcal02
permlinkrb8isi
categoryhivemind
json_metadata{"app":"hiveblog/0.1"}
created2022-05-02 02:55:48
last_update2022-05-02 02:55:48
depth1
children0
last_payout2022-05-09 02:55:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length70
author_reputation13,554,613,243,080
root_title"How to execute automated tests on hivemind "
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id112,826,181
net_rshares0
@cal02 ·
Leí tu publicación pero aún no entiendo😅 estoy aprendiendo.
properties (22)
authorcal02
permlinkrb8ivy
categoryhivemind
json_metadata{"app":"hiveblog/0.1"}
created2022-05-02 02:57:45
last_update2022-05-02 02:57:45
depth1
children0
last_payout2022-05-09 02:57:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length59
author_reputation13,554,613,243,080
root_title"How to execute automated tests on hivemind "
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id112,826,222
net_rshares0
@ismaelrd04 ·
Thanks for explaining that, I appreciate so much 
properties (22)
authorismaelrd04
permlinkre-howo-2022424t224210763z
categoryhivemind
json_metadata{"tags":["hivemind","automated","tests","hive"],"app":"ecency/3.0.22-vision","format":"markdown+html"}
created2022-04-25 02:42:12
last_update2022-04-25 02:42:12
depth1
children0
last_payout2022-05-02 02:42:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length49
author_reputation165,928,193,232,007
root_title"How to execute automated tests on hivemind "
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id112,614,567
net_rshares0
@nkechi ·
Please what's "Hivemind"?
What is it used for?

This is my first time hearing of it🙈🙈
properties (22)
authornkechi
permlinkre-howo-raw57z
categoryhivemind
json_metadata{"tags":["hivemind"],"app":"peakd/2022.04.5"}
created2022-04-25 10:31:15
last_update2022-04-25 10:31:15
depth1
children2
last_payout2022-05-02 10:31:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length85
author_reputation6,183,721,709,496
root_title"How to execute automated tests on hivemind "
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id112,622,606
net_rshares0
@blocktrades ·
Hivemind is a 2nd layer app on Hive that keep track of a lot of "social" data for blogging. Most frontend web sites(hive.blog, peakd, ecency, etc) use Hivemind to get most of the blockchain information they display (e.g. all the posts, comments, communities, etc).
properties (22)
authorblocktrades
permlinkrax11a
categoryhivemind
json_metadata{"app":"hiveblog/0.1"}
created2022-04-25 21:58:24
last_update2022-04-25 21:58:24
depth2
children1
last_payout2022-05-02 21:58:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length264
author_reputation1,291,098,880,469,400
root_title"How to execute automated tests on hivemind "
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id112,641,245
net_rshares0
@nkechi ·
Ohh Okay.. I get it now.
Thanks you! @blocktrades 
properties (22)
authornkechi
permlinkre-blocktrades-raxvub
categoryhivemind
json_metadata{"tags":["hivemind"],"app":"peakd/2022.04.5"}
created2022-04-26 09:06:03
last_update2022-04-26 09:06:03
depth3
children0
last_payout2022-05-03 09:06:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length50
author_reputation6,183,721,709,496
root_title"How to execute automated tests on hivemind "
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id112,653,717
net_rshares0
@tanzil2024 ·
Inspiring for the newbies
expect more from you
properties (22)
authortanzil2024
permlinkravkri
categoryhivemind
json_metadata{"app":"hiveblog/0.1"}
created2022-04-25 03:09:18
last_update2022-04-25 03:09:18
depth1
children0
last_payout2022-05-02 03:09:18
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length46
author_reputation423,566,246,665,950
root_title"How to execute automated tests on hivemind "
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id112,615,036
net_rshares0