1
+ from __future__ import print_function
1
2
import unittest
2
3
from loklak import Loklak
3
4
import os
@@ -9,6 +10,21 @@ def setUp(self):
9
10
"""test proper setup"""
10
11
self .loklak = Loklak ()
11
12
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
+
12
28
def test_hello (self ):
13
29
"""test hello instance"""
14
30
result = self .loklak .hello ()
@@ -34,6 +50,23 @@ def test_geocode(self):
34
50
isinstance (result ['locations' ]['Moscow' ]['place' ], list )
35
51
)
36
52
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 ] == '\211 PNG\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
+
37
70
def test_peers (self ):
38
71
"""test finding peers"""
39
72
result = self .loklak .peers ()
@@ -42,42 +75,6 @@ def test_peers(self):
42
75
self .assertTrue (len (result ['peers' ]) >= 1 )
43
76
self .assertEqual (len (result ['peers' ]), result ['count' ])
44
77
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
-
81
78
def test_user (self ):
82
79
"""test user"""
83
80
result = self .loklak .user ('dhruvRamani98' )
@@ -86,30 +83,26 @@ def test_user(self):
86
83
self .assertTrue ('name' in result ['user' ])
87
84
self .assertTrue ('screen_name' in result ['user' ])
88
85
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 ] == '\211 PNG\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
+
103
96
def test_aggregations (self ):
104
97
"""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 )
106
101
data = result .json ()
107
- self .assertEqual (result .status_code ,200 )
102
+ self .assertEqual (result .status_code , 200 )
108
103
self .assertTrue ('aggregations' in data )
109
104
self .assertTrue ('hashtags' in data ['aggregations' ])
110
105
self .assertTrue ('mentions' in data ['aggregations' ])
111
106
112
-
113
-
114
107
if __name__ == '__main__' :
115
108
unittest .main ()
0 commit comments