Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test coverage #88

Merged
merged 5 commits into from
Jan 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions loklak.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ def getBaseUrl(self):
"""Return the string value of baseUrl."""
return self.baseUrl

def status(self):
def status(self, status_application='api/status.json'):
"""Retrieve a json response about the status of the server."""
status_application = 'api/status.json'
url_to_give = self.baseUrl+status_application
url_to_give = self.baseUrl + status_application
return_to_user = requests.get(url_to_give)
if return_to_user.status_code == 200:
return return_to_user.json()
Expand Down Expand Up @@ -421,7 +420,7 @@ def aggregations(self, query=None, since=None, until=None,
return json.dumps(return_to_user)
else:
return_to_user = {}
return_to_user['error'] = ('No Query string has been given to run'
return_to_user['error'] = ('No Query string has been given to run '
'query for aggregations')
return json.dumps(return_to_user)

Expand Down
24 changes: 23 additions & 1 deletion tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,19 @@ def test_status(self):
msg='{} not found in index'.format(prop)
)

result = self.loklak.status("nonexisturl")
self.assertEqual(result, "{}")

def test_hello(self):
"""Test hello instance."""
result = self.loklak.hello()
self.assertEqual(result['status'], u'ok')

def test_getBaseUrl(self):
"""Test base url."""
result = self.loklak.getBaseUrl()
self.assertEqual(result, self.baseUrl)

def test_geocode(self):
"""Test geological features."""
result = self.loklak.geocode()
Expand Down Expand Up @@ -92,10 +100,15 @@ def test_push(self):
def test_user(self):
"""Test user."""
result = self.loklak.user('dhruvRamani98')
self.assertTrue('error' in self.loklak.user())
self.assertTrue('user' in result)
self.assertTrue('name' in result['user'])
self.assertTrue('screen_name' in result['user'])
result = self.loklak.user("fossasia", 1500, 330)
self.assertTrue('user' in result)
self.assertTrue('name' in result['user'])
result = self.loklak.user()
self.assertTrue('error' in self.loklak.user())
self.assertEqual(result, '{"error": "No user name given to query. Please check and try again"}')

def test_search(self):
"""Test search result."""
Expand All @@ -107,13 +120,22 @@ def test_search(self):
int(result['search_metadata']['maximumRecords']))
self.assertEqual(int(result['search_metadata']['maximumRecords']), 18)

result = self.loklak.search('FOSSASIA', since='2000-01-01', until='2017-12-31_12:24', from_user='fossasia', count=20)
self.assertTrue('statuses' in result)

result = self.loklak.search()
self.assertEqual(result, '{"error": "No Query string has been given to query for an account"}')

def test_aggregations(self):
"""Test aggregations."""
result = self.loklak.aggregations('fossasia', '2017-01-10',
'2018-01-10', 10)
data = result.json()
self.assertEqual(result.status_code, 200)
self.assertTrue('aggregations' in data)

result = self.loklak.aggregations()
self.assertEqual(result, '{"error": "No Query string has been given to run query for aggregations"}')
# self.assertTrue('hashtags' in data['aggregations'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you found solution to include fields? Please see this #75 (comment) for more info

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet, but I will check it out soon.

# self.assertTrue('mentions' in data['aggregations'])

Expand Down