Skip to content

Commit ea4165a

Browse files
committed
Merge pull request #30 from yasoob/patch-1
updated the code. Pylint rating is at 9.8 from 7.7.
2 parents e7ac88e + 62583df commit ea4165a

File tree

3 files changed

+54
-60
lines changed

3 files changed

+54
-60
lines changed

loklak.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Loklak(object):
2525
limit = None
2626
action = None
2727
data = {}
28-
28+
2929
def status(self):
3030
"""Returns the status of the server"""
3131
status_application = 'api/status.json'

setup.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import re, uuid
1+
import re
2+
import uuid
23

34
try:
45
from setuptools import setup
56
except ImportError:
67
from distutils.core import setup
78

89
setup(name='python-loklak-api',
9-
version='1.0',
10-
description="Python API for loklak, Anonymous distributed P2P Systems.",
10+
version='1.0',
11+
description="Python API for loklak, Anonymous distributed P2P Systems.",
1112
author='Sudheesh Singanamalla',
1213
author_email='[email protected]',
1314
url='https://github.com/sudheesh001/python-loklak-api',
@@ -23,12 +24,12 @@
2324
'Topic :: Internet',
2425
],
2526
keywords="Twitter Loklak Anonymous API",
26-
install_requires = [
27+
install_requires=[
2728
"asyncoro==3.5",
2829
"requests==2.8.1",
2930
"wsgiref==0.1.2"
3031
],
3132
zip_safe=False,
32-
download_url = 'https://github.com/sudheesh001/python-loklak-api',
33+
download_url='https://github.com/sudheesh001/python-loklak-api',
3334
scripts=['bin/loklak']
3435
)

test.py

Lines changed: 47 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
import unittest
23
from loklak import Loklak
34
import os
@@ -9,6 +10,21 @@ def setUp(self):
910
"""test proper setup"""
1011
self.loklak = Loklak()
1112

13+
def test_status(self):
14+
"""test status"""
15+
result = self.loklak.status()
16+
17+
self.assertTrue('index_sizes' in result)
18+
result_properties = [
19+
'messages', 'mps', 'users', 'queries',
20+
'accounts', 'user', 'followers', 'following'
21+
]
22+
for prop in result_properties:
23+
self.assertTrue(
24+
prop in result['index_sizes'],
25+
msg='{} not found in index_sizes'.format(prop)
26+
)
27+
1228
def test_hello(self):
1329
"""test hello instance"""
1430
result = self.loklak.hello()
@@ -34,6 +50,23 @@ def test_geocode(self):
3450
isinstance(result['locations']['Moscow']['place'], list)
3551
)
3652

53+
def test_get_map(self):
54+
"""Tests the get_map method"""
55+
map_file = os.path.join(os.getcwd(), 'markdown.png')
56+
data = self.loklak.get_map(17.582729, 79.118320)
57+
self.assertTrue(data[:8] == '\211PNG\r\n\032\n' and
58+
(data[12:16] == 'IHDR'))
59+
with open(map_file, 'wb') as file_handle:
60+
file_handle.write(data)
61+
with open(map_file, 'rb') as file_handle:
62+
file_contents = file_handle.read()
63+
self.assertTrue(os.path.exists(map_file))
64+
self.assertEqual(data, file_contents)
65+
try:
66+
os.remove(map_file)
67+
except OSError as error:
68+
print(error)
69+
3770
def test_peers(self):
3871
"""test finding peers"""
3972
result = self.loklak.peers()
@@ -42,42 +75,6 @@ def test_peers(self):
4275
self.assertTrue(len(result['peers']) >= 1)
4376
self.assertEqual(len(result['peers']), result['count'])
4477

45-
def test_search(self):
46-
"""test search result"""
47-
result = self.loklak.search('doctor who')
48-
self.assertTrue('error' in self.loklak.search())
49-
self.assertTrue('statuses' in result)
50-
self.assertTrue(isinstance(result['statuses'], list))
51-
self.assertTrue(len(result['statuses']) >= 1)
52-
self.assertEqual(len(result['statuses']), int(result['search_metadata']['count']))
53-
54-
def test_status(self):
55-
"""test status"""
56-
result = self.loklak.status()
57-
58-
self.assertTrue('index_sizes' in result)
59-
result_properties = [
60-
'messages', 'mps', 'users', 'queries',
61-
'accounts', 'user', 'followers', 'following'
62-
]
63-
for prop in result_properties:
64-
self.assertTrue(
65-
prop in result['index_sizes'],
66-
msg='{} not found in index_sizes'.format(prop)
67-
)
68-
69-
self.assertTrue('client_info' in result)
70-
client_properties = [
71-
'RemoteHost', 'IsLocalhost', 'Host',
72-
'Accept-Encoding', 'X-Forwarded-For', 'X-Real-IP',
73-
'User-Agent', 'Accept', 'Connection',
74-
]
75-
for prop in client_properties:
76-
self.assertTrue(
77-
prop in result['client_info'],
78-
msg='{} not found in client info'.format(prop)
79-
)
80-
8178
def test_user(self):
8279
"""test user"""
8380
result = self.loklak.user('dhruvRamani98')
@@ -86,30 +83,26 @@ def test_user(self):
8683
self.assertTrue('name' in result['user'])
8784
self.assertTrue('screen_name' in result['user'])
8885

89-
def test_get_map(self):
90-
self.map_file = os.path.join(os.getcwd(), 'markdown.png')
91-
data = self.loklak.get_map(17.582729, 79.118320)
92-
self.assertTrue(data[:8] == '\211PNG\r\n\032\n'and (data[12:16] == 'IHDR'))
93-
with open(self.map_file, 'wb') as f:
94-
f.write(data)
95-
with open(self.map_file, 'rb') as f:
96-
file_contents = f.read()
97-
self.assertTrue(os.path.exists(self.map_file))
98-
self.assertEqual(data, file_contents)
99-
try:
100-
os.remove(self.map_file)
101-
except OSError as error:
102-
print(error)
86+
def test_search(self):
87+
"""test search result"""
88+
result = self.loklak.search('doctor who')
89+
self.assertTrue('error' in self.loklak.search())
90+
self.assertTrue('statuses' in result)
91+
self.assertTrue(isinstance(result['statuses'], list))
92+
self.assertTrue(len(result['statuses']) >= 1)
93+
self.assertEqual(len(result['statuses']),
94+
int(result['search_metadata']['count']))
95+
10396
def test_aggregations(self):
10497
"""test aggregations"""
105-
result = self.loklak.aggregations('sudheesh001','2015-01-10','2015-10-21',['mentions','hashtags'],10)
98+
result = self.loklak.aggregations('sudheesh001', '2015-01-10',
99+
'2015-10-21', ['mentions',
100+
'hashtags'], 10)
106101
data = result.json()
107-
self.assertEqual(result.status_code,200)
102+
self.assertEqual(result.status_code, 200)
108103
self.assertTrue('aggregations' in data)
109104
self.assertTrue('hashtags' in data['aggregations'])
110105
self.assertTrue('mentions' in data['aggregations'])
111106

112-
113-
114107
if __name__ == '__main__':
115108
unittest.main()

0 commit comments

Comments
 (0)