Skip to content

Commit 996f4b7

Browse files
committed
BC-72 Add and configure drf-spectacular module.
1 parent bca2dc4 commit 996f4b7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+547
-159
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ nosetests.xml
5353

5454
# pytest
5555
.pytest_cache
56+
node/blockchain/tests/examples/testing.json
5657

5758
# mypy
5859
.mypy_cache

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ repos:
4242
rev: 'v0.910'
4343
hooks:
4444
- id: mypy
45-
additional_dependencies: [types-requests, types-PyYAML]
45+
additional_dependencies: [types-requests, types-PyYAML, types-toml]

node/blockchain/admin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ class BlockAdmin(admin.ModelAdmin):
1212

1313
@admin.register(AccountState)
1414
class AccountStateAdmin(admin.ModelAdmin):
15-
pass
15+
list_display = ('_id',)

node/blockchain/constants.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,16 @@
55

66
LAST_BLOCK_ID = 'last'
77
BLOCK_LOCK = 'block'
8+
9+
NODE_DETAILS_EXAMPLE = 'node_details'
10+
NODE_LIST_EXAMPLE = 'node_list'
11+
ACCOUNT_STATE_DETAILS_EXAMPLE = 'account_state_details'
12+
13+
BLOCK_DETAILS_GENESIS_EXAMPLE = 'block_details_genesis'
14+
BLOCK_DETAILS_COIN_TRANSFER_EXAMPLE = 'block_details_coin_transfer'
15+
BLOCK_DETAILS_NODE_DECLARATION_EXAMPLE = 'block_details_node_declaration'
16+
BLOCK_DETAILS_PV_SCHEDULE_UPDATE_EXAMPLE = 'block_details_pv_schedule_update'
17+
BLOCK_LIST_EXAMPLE = 'block_list'
18+
19+
SIGNED_CHANGE_REQUEST_COIN_TRANSFER_EXAMPLE = 'signed_change_request_coin_transfer'
20+
SIGNED_CHANGE_REQUEST_NODE_DECLARATION_EXAMPLE = 'signed_change_request_node_declaration'

node/blockchain/serializers/account_state.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77

88
class AccountStateSerializer(serializers.ModelSerializer):
9+
"""
10+
Account state, which defines a set of attributes about the current account state, such as account balance
11+
(the amount of coins owned by an account). These attributes change over time.
12+
"""
13+
914
_id = serializers.CharField()
1015
balance = serializers.IntegerField()
1116
account_lock = serializers.CharField()

node/blockchain/serializers/block.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111

1212

1313
class BlockSerializer(serializers.ModelSerializer):
14+
"""
15+
Block are structure that store data. These data describe changes to the network and originate
16+
from signed change requests, such as:<br>
17+
* Genesis;<br>
18+
* Transfers of coins between accounts;<br>
19+
* New nodes being added to the network;<br>
20+
* Primary Validator Schedule Updates.
21+
"""
1422

1523
signer = serializers.CharField(min_length=64, max_length=64, write_only=True)
1624
signature = serializers.CharField(min_length=128, max_length=128, write_only=True)

node/blockchain/serializers/node.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55

66
class NodeSerializer(serializers.ModelSerializer):
7+
"""
8+
The network uses multiple nodes, which are servers with several responsibilities.
9+
Nodes connect users or client apps to the network, or enable important processes,
10+
such as transaction validation.
11+
"""
12+
713
# TODO(dmu) HIGH: Instead of redefining serializer fields generate serializer from
814
# Node model metadata
915
identifier = serializers.CharField()

node/blockchain/serializers/signed_change_request.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515

1616

1717
class SignedChangeRequestSerializer(serializers.Serializer, ValidateUnknownFieldsMixin):
18+
"""
19+
Signed change request is a data update request. Next types are allowed:<br>
20+
* Transfers of coins between accounts;<br>
21+
* New nodes being added to the network.<br>
22+
"""
23+
1824
signer = serializers.CharField()
1925
signature = serializers.CharField()
2026
message = PydanticModelBackedJSONField()

node/blockchain/tests/examples.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import functools
2+
import json
3+
import logging
4+
import os
5+
from pathlib import Path
6+
7+
from django.conf import settings
8+
9+
logger = logging.getLogger(__name__)
10+
11+
EXAMPLES_DIR = os.path.join(Path(__file__).resolve().parent, 'examples')
12+
13+
14+
def save_example(file_name, data):
15+
if not settings.IN_DOCKER:
16+
with open(get_example_path(file_name), 'w') as fp:
17+
json.dump(data, fp)
18+
19+
20+
def save_response_as_example(file_name):
21+
22+
def save(func):
23+
24+
@functools.wraps(func)
25+
def wrapper(*args, **kwargs):
26+
data = func(*args, **kwargs)
27+
assert data is not None
28+
29+
save_example(file_name, data)
30+
31+
return data
32+
33+
return wrapper
34+
35+
return save
36+
37+
38+
def load_example(file_name):
39+
path = get_example_path(file_name)
40+
41+
if not os.path.exists(path):
42+
logger.warning("%s example file doesn't exist: %s", file_name, path)
43+
return {}
44+
45+
with open(path) as fp:
46+
return json.load(fp)
47+
48+
49+
def get_example_path(file_name):
50+
return os.path.join(EXAMPLES_DIR, f'{file_name}.json')
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"_id": "b9dc49411424cce606d27eeaa8d74cb84826d8a1001d17603638b73bdc6077f1", "balance": 0, "account_lock": "b9dc49411424cce606d27eeaa8d74cb84826d8a1001d17603638b73bdc6077f1", "node": {"identifier": "b9dc49411424cce606d27eeaa8d74cb84826d8a1001d17603638b73bdc6077f1", "addresses": ["http://not-existing-primary-validator-address-674898923.com:8555/"], "fee": 4}}

0 commit comments

Comments
 (0)