Skip to content

Commit df000ce

Browse files
committed
Added negative testcases for all the IPNS APIs
1 parent 27a8c86 commit df000ce

File tree

4 files changed

+122
-19
lines changed

4 files changed

+122
-19
lines changed

tests/test_get_ipns_record.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,12 @@ def test_get_ipns_records(self):
1818
self.assertIsInstance(res.get("data")[0].get("ipnsId"), str , "ipnsId is a str")
1919
self.assertIsInstance(res.get("data")[0].get("publicKey"), str , "publicKey is a str")
2020
self.assertIsInstance(res.get("data")[0].get("cid"), str , "cid is a str")
21-
self.assertIsInstance(res.get("data")[0].get("lastUpdate"), int , "lastUpdate is a int")
21+
self.assertIsInstance(res.get("data")[0].get("lastUpdate"), int , "lastUpdate is a int")
22+
23+
def test_get_ipns_records_invalid_token(self):
24+
"""test get_ipns_records with invalid token"""
25+
parse_env()
26+
l = Lighthouse("invalid_token")
27+
with self.assertRaises(Exception) as context:
28+
l.generateKey()
29+
self.assertIn("authentication failed", str(context.exception).lower())

tests/test_ipns_generate_key.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,14 @@ def test_ipns_generate_key(self):
1515
self.assertIsInstance(res, dict, "result is a dict")
1616
self.assertIsInstance(res.get("data"), dict , "data is a dict")
1717
self.assertIsInstance(res.get("data").get("ipnsName"), str , "ipnsName is a str")
18-
self.assertIsInstance(res.get("data").get("ipnsId"), str , "ipnsId is a dict")
18+
self.assertIsInstance(res.get("data").get("ipnsId"), str , "ipnsId is a dict")
19+
20+
def test_ipns_generate_key_invalid_token(self):
21+
"""test ipns_generate_key with invalid token"""
22+
parse_env()
23+
l = Lighthouse("invalid_token")
24+
with self.assertRaises(Exception) as context:
25+
l.generateKey()
26+
self.assertIn("authentication failed", str(context.exception).lower())
27+
28+

tests/test_ipns_publish_record.py

Lines changed: 71 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,81 @@
88
class TestIPNSPublishRecord(unittest.TestCase):
99

1010
def test_ipns_publish_record(self):
11-
"""test ipns_publish_record function"""
12-
parse_env()
11+
"""test ipns_publish_record function"""
12+
parse_env()
1313

14-
l = Lighthouse(os.environ.get("LIGHTHOUSE_TOKEN"))
15-
res = l.generateKey()
14+
l = Lighthouse(os.environ.get("LIGHTHOUSE_TOKEN"))
15+
res = l.generateKey()
1616

17-
self.assertIsInstance(res, dict, "result is a dict")
18-
self.assertIsInstance(res.get("data"), dict , "data is a dict")
19-
self.assertIsInstance(res.get("data").get("ipnsName"), str , "ipnsName is a str")
20-
self.assertIsInstance(res.get("data").get("ipnsId"), str , "ipnsId is a dict")
17+
self.assertIsInstance(res, dict, "result is a dict")
18+
self.assertIsInstance(res.get("data"), dict , "data is a dict")
19+
self.assertIsInstance(res.get("data").get("ipnsName"), str , "ipnsName is a str")
20+
self.assertIsInstance(res.get("data").get("ipnsId"), str , "ipnsId is a dict")
2121

22-
record = l.publishRecord(
22+
record = l.publishRecord(
23+
'QmeMsykMDyD76zpAbinCy1cjb1KL6CVNBfB44am15U1XHh',
24+
res.get('data').get('ipnsName')
25+
)
26+
27+
self.assertIsInstance(record, dict, "record is a dict")
28+
self.assertIsInstance(record.get("data"), dict, "data is a dict")
29+
self.assertIsInstance(record.get("data").get("Name"), str, "name is a str")
30+
self.assertIsInstance(record.get("data").get("Value"), str, "value is a str")
31+
self.assertEqual(record.get("data").get("Value"), "/ipfs/QmeMsykMDyD76zpAbinCy1cjb1KL6CVNBfB44am15U1XHh")
32+
33+
def test_ipns_publish_record_invalid_token(self):
34+
"""test ipns_generate_key with invalid token"""
35+
parse_env()
36+
l = Lighthouse(os.environ.get("LIGHTHOUSE_TOKEN"))
37+
res = l.generateKey()
38+
39+
self.assertIsInstance(res, dict, "result is a dict")
40+
self.assertIsInstance(res.get("data"), dict , "data is a dict")
41+
self.assertIsInstance(res.get("data").get("ipnsName"), str , "ipnsName is a str")
42+
self.assertIsInstance(res.get("data").get("ipnsId"), str , "ipnsId is a dict")
43+
44+
l = Lighthouse("invalid_token")
45+
with self.assertRaises(Exception) as context:
46+
l.publishRecord(
2347
'QmeMsykMDyD76zpAbinCy1cjb1KL6CVNBfB44am15U1XHh',
2448
res.get('data').get('ipnsName')
2549
)
50+
self.assertIn("authentication failed", str(context.exception).lower())
51+
52+
def test_ipns_publish_record_invalid_cid(self):
53+
"""test ipns_generate_key with invalid cid"""
54+
l = Lighthouse(os.environ.get("LIGHTHOUSE_TOKEN"))
55+
res = l.generateKey()
56+
57+
self.assertIsInstance(res, dict, "result is a dict")
58+
self.assertIsInstance(res.get("data"), dict , "data is a dict")
59+
self.assertIsInstance(res.get("data").get("ipnsName"), str , "ipnsName is a str")
60+
self.assertIsInstance(res.get("data").get("ipnsId"), str , "ipnsId is a dict")
61+
62+
record = l.publishRecord(
63+
'invalid_cid',
64+
res.get('data').get('ipnsName')
65+
)
66+
self.assertIsInstance(record, dict, "record is a dict")
67+
self.assertIsInstance(record.get("error"), list, "error is a list")
68+
self.assertEqual(record.get("error")[0]['message'], 'Something went wrong.' )
69+
70+
def test_ipns_publish_record_invalid_key_name(self):
71+
"""test ipns_generate_key with invalid key name"""
72+
parse_env()
73+
74+
l = Lighthouse(os.environ.get("LIGHTHOUSE_TOKEN"))
75+
res = l.generateKey()
76+
77+
self.assertIsInstance(res, dict, "result is a dict")
78+
self.assertIsInstance(res.get("data"), dict , "data is a dict")
79+
self.assertIsInstance(res.get("data").get("ipnsName"), str , "ipnsName is a str")
80+
self.assertIsInstance(res.get("data").get("ipnsId"), str , "ipnsId is a dict")
2681

27-
self.assertIsInstance(record, dict, "record is a dict")
28-
self.assertIsInstance(record.get("data"), dict, "data is a dict")
29-
self.assertIsInstance(record.get("data").get("Name"), str, "name is a str")
30-
self.assertIsInstance(record.get("data").get("Value"), str, "value is a str")
31-
self.assertEqual(record.get("data").get("Value"), "/ipfs/QmeMsykMDyD76zpAbinCy1cjb1KL6CVNBfB44am15U1XHh")
82+
record = l.publishRecord(
83+
'QmeMsykMDyD76zpAbinCy1cjb1KL6CVNBfB44am15U1XHh',
84+
'invalid_key_name'
85+
)
86+
self.assertIsInstance(record, dict, "record is a dict")
87+
self.assertIsInstance(record.get("error"), list, "error is a list")
88+
self.assertEqual(record.get("error")[0]['message'], 'Something went wrong.' )

tests/test_remove_ipns_record.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
class TestRemoveIPNSRecord(unittest.TestCase):
99

10-
def test_ipns_generate_key(self):
11-
"""test ipns_generate_key function"""
10+
def test_ipns_remove_key(self):
11+
"""test ipns_remove_key function"""
1212
parse_env()
1313
l = Lighthouse(os.environ.get("LIGHTHOUSE_TOKEN"))
1414

@@ -25,4 +25,32 @@ def test_ipns_generate_key(self):
2525
self.assertIsInstance(res.get("data"), dict , "data is a dict")
2626
self.assertIsInstance(res.get("data").get("Keys"), list , "Keys is a list")
2727
self.assertEqual(res.get("data").get("Keys")[0].get('Name'), key.get('data').get('ipnsName'))
28-
self.assertEqual(res.get("data").get("Keys")[0].get('Id'), key.get('data').get('ipnsId'))
28+
self.assertEqual(res.get("data").get("Keys")[0].get('Id'), key.get('data').get('ipnsId'))
29+
30+
def test_ipns_remove_key_invalid_token(self):
31+
"""test ipns_remove_key with invalid token"""
32+
parse_env()
33+
l = Lighthouse(os.environ.get("LIGHTHOUSE_TOKEN"))
34+
35+
key = l.generateKey()
36+
37+
self.assertIsInstance(key, dict, "result is a dict")
38+
self.assertIsInstance(key.get("data"), dict , "data is a dict")
39+
self.assertIsInstance(key.get("data").get("ipnsName"), str , "ipnsName is a str")
40+
self.assertIsInstance(key.get("data").get("ipnsId"), str , "ipnsId is a dict")
41+
42+
l = Lighthouse("invalid_token")
43+
key_name = key.get('data').get('ipnsName')
44+
with self.assertRaises(Exception) as context:
45+
l.removeKey(key_name)
46+
self.assertIn("authentication failed", str(context.exception).lower())
47+
48+
def test_ipns_remove_key_invalid_key_name(self):
49+
"""test ipns_remove_key with invalid key name"""
50+
parse_env()
51+
52+
l = Lighthouse(os.environ.get("LIGHTHOUSE_TOKEN"))
53+
res = l.removeKey('invalid_key_name')
54+
self.assertIsInstance(res, dict, "record is a dict")
55+
self.assertIsInstance(res.get("error"), list, "error is a list")
56+
self.assertEqual(res.get("error")[0]['message'], 'Something went wrong.' )

0 commit comments

Comments
 (0)