Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write a test for function create() of BankViewSet class to verify a bank detail using node identifier #103

Open
pgeorge2 opened this issue Nov 26, 2020 · 3 comments
Assignees

Comments

@pgeorge2
Copy link

pgeorge2 commented Nov 26, 2020

Create a test called test_bank_detail by taking reference of test_bank_patch method.

Write the test at following location.
https://github.com/thenewboston-developers/Validator/blob/master/v1/banks/tests/bank.py

Hint: as mentioned, to create a test, you can take reference of test_banks_patch method and pass the dummy data in generate_signed_request method with expected status code as 200 and verify the response by comparing response and bank_fake_data

@pgeorge2 pgeorge2 added the 500 label Nov 26, 2020
@pgeorge2 pgeorge2 changed the title Create a test to verify a bank detail using node identifier Write a test for function create () of BankViewSet class to verify a bank detail using node identifier Nov 26, 2020
@pgeorge2 pgeorge2 changed the title Write a test for function create () of BankViewSet class to verify a bank detail using node identifier Write a test for function create() of BankViewSet class to verify a bank detail using node identifier Nov 26, 2020
@YashovardhanSingh
Copy link

@pgeorge2 Please explain it more.

@pgeorge2
Copy link
Author

@YashovardhanSingh sure.
In this test, we need to verify the bank details using node_identifier. we need to prepare a test for url /bank/<node_identifier>.
For example, if we have a bank with d5356888dc9303e44ce52b1e06c3165a7759b9df1e6a6dfbd33ee1c3df1ab4d1 node identifier, then use bank/d5356888dc9303e44ce52b1e06c3165a7759b9df1e6a6dfbd33ee1c3df1ab4d1 and verify the response.

Let me know if you need more information or clarification.

@Duke123-tech
Copy link

from rest_framework.reverse import reverse
from rest_framework.status import HTTP_200_OK
from thenewboston.third_party.pytest.asserts import assert_objects_vs_dicts
from thenewboston.utils.signed_requests import generate_signed_request
from v1.self_configurations.helpers.signing_key import get_signing_key

//these are necessary imports for tests

//and next, test assertions. First ones:
def test_banks_list(client, banks, django_assert_max_num_queries):
with django_assert_max_num_queries(2):
response = client.get_json(
reverse('bank-list'),
{'limit': 0},
expected=HTTP_200_OK,
)
assert_objects_vs_dicts(banks, response, key='node_identifier')
assert response;

//Second one:
def test_banks_patch(client, primary_validator_configuration, bank, bank_fake_data):
response = client.patch_json(
reverse(
'bank-detail',
args=[bank.node_identifier]
),
generate_signed_request(
data=bank_fake_data,
nid_signing_key=get_signing_key(),
),
expected=HTTP_200_OK,
)
assert float(response['trust']) == bank_fake_data['trust'];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants