Browse Source

Replace conn var by constant

master
juga 1 year ago
parent
commit
14f40531aa
1 changed files with 31 additions and 43 deletions
  1. +31
    -43
      tests/test_gnunet.py

+ 31
- 43
tests/test_gnunet.py View File

@ -1,86 +1,78 @@
# Examples for the Python GNUnet REST Connector
import os
from pygnunetrest import gnunetrest
# To be able to test against gnunet running in other machine or container.
HOST = os.environ.get('HOST', 'localhost')
PORT = os.environ.get('PORT', 7776)
REST_CLIENT = gnunetrest.GNUnetRest(HOST, PORT)
def test_connect():
# make instance of connector,
# without arguments it defaults to localhost, port 7776
conn = gnunetrest.GNUnetRest()
# it is also possible to specify host and port, for example:
# conn=gnunetrest.GNUnetRest("localhost","7771")
def test_connect():
# test if connection is possible
print("\nTesting Connector")
assert conn
assert REST_CLIENT
# IDENTITIES#
# ==========#
def test_create_identity():
print("\nCreating some identities")
conn = gnunetrest.GNUnetRest()
# The request works, but doesn't create the identity
assert conn.create_identity("alice")
assert REST_CLIENT.create_identity("alice")
def test_list_identities():
conn = gnunetrest.GNUnetRest()
conn.create_identity("alice")
conn.create_identity("bob")
identities = conn.identity_list()
REST_CLIENT.create_identity("alice")
REST_CLIENT.create_identity("bob")
identities = REST_CLIENT.identity_list()
print(identities)
# This fail!
assert 2 == len(identities)
def test_fetch_identity_hash():
conn = gnunetrest.GNUnetRest()
conn.create_identity("alice")
r = conn.fetch_identity_name("alice")
REST_CLIENT.create_identity("alice")
r = REST_CLIENT.fetch_identity_name("alice")
assert 52 == len(r)
# def test_fetch_identity_name():
# conn = gnunetrest.GNUnetRest()
# conn.create_identity("alice")
# r = conn.fetch_identity_keyhash("alice")
# REST_CLIENT = gnunetrest.GNUnetRest(HOST, PORT)
# REST_CLIENT.create_identity("alice")
# r = REST_CLIENT.fetch_identity_keyhash("alice")
def test_change_identity_name():
conn = gnunetrest.GNUnetRest()
conn.create_identity("alice")
assert conn.change_identity_name("alice", "carol")
r = conn.fetch_identity_name("carol")
REST_CLIENT.create_identity("alice")
assert REST_CLIENT.change_identity_name("alice", "carol")
r = REST_CLIENT.fetch_identity_name("carol")
assert 52 == len(r)
def test_delete_identity():
conn = gnunetrest.GNUnetRest()
conn.create_identity("alice")
assert conn.delete_identity("alice")
assert not conn.fetch_identity_name("alice")[0]
REST_CLIENT.create_identity("alice")
assert REST_CLIENT.delete_identity("alice")
assert not REST_CLIENT.fetch_identity_name("alice")[0]
# # NAMESTORE#
# # =========#
def test_set_namestore_identity():
conn = gnunetrest.GNUnetRest()
conn.create_identity("alice")
assert conn.set_namestore_identity("alice")
REST_CLIENT.create_identity("alice")
assert REST_CLIENT.set_namestore_identity("alice")
def test_list_namestore_entry():
conn = gnunetrest.GNUnetRest()
assert conn.set_namestore_identity("alice")
r = conn.list_namestore_entries("alice")
assert REST_CLIENT.set_namestore_identity("alice")
r = REST_CLIENT.list_namestore_entries("alice")
print(r)
def test_add_namestore_entry():
conn = gnunetrest.GNUnetRest()
assert conn.add_namestore_entry(
assert REST_CLIENT.add_namestore_entry(
"alice",
"pepfoundation",
"95.128.36.146",
@ -89,8 +81,7 @@ def test_add_namestore_entry():
def test_change_namestore_entry():
conn = gnunetrest.GNUnetRest()
assert conn.change_namestore_entry(
assert REST_CLIENT.change_namestore_entry(
"alice",
"pepfoundation",
"6.6.6.6",
@ -99,16 +90,14 @@ def test_change_namestore_entry():
def test_delete_namestore_entry():
conn = gnunetrest.GNUnetRest()
assert conn.delete_namestore_entry("alice", "pepfoundation")
assert REST_CLIENT.delete_namestore_entry("alice", "pepfoundation")
# # GNS#
# # ===#
def test_list_gns_record():
conn = gnunetrest.GNUnetRest()
r = conn.list_gns_record("alice", "pepfoundation")
r = REST_CLIENT.list_gns_record("alice", "pepfoundation")
print(r)
assert r[0]
assert r['record_name'] == 'pepfoundation.alice'
@ -116,8 +105,7 @@ def test_list_gns_record():
def test_list_gns_record_type():
conn = gnunetrest.GNUnetRest()
r = conn.list_gns_record_type("alice", "pepfoundation", "A")
r = REST_CLIENT.list_gns_record_type("alice", "pepfoundation", "A")
print(r)
assert r[0]
assert r['record_name'] == 'pepfoundation.alice'


Loading…
Cancel
Save