Skip to content
This repository has been archived by the owner on Dec 23, 2023. It is now read-only.

Commit

Permalink
Change config name for unnamed location name and write unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianMitchL committed Apr 25, 2018
1 parent e8a5ef9 commit 80fafe2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
18 changes: 15 additions & 3 deletions test.py
Expand Up @@ -615,10 +615,11 @@ def test_config(self):
utils.Time(hour=18, minute=0),
utils.Time(hour=22, minute=0)]
},
'default_location': models.WeatherLocation(-79, 12, 'Just a Test'),
'default_location': models.WeatherLocation(-79.0, 12.0, 'Just a Test'),
'variable_location': {
'enabled': True,
'user': 'test_user'
'user': 'test_user',
'unnamed_location_name': 'Somewhere in deep space'
},
'log': {
'enabled': False,
Expand Down Expand Up @@ -672,7 +673,8 @@ def test_config(self):
}
conf['variable location'] = {
'enabled': 'yes',
'user': 'test_user'
'user': 'test_user',
'unnamed_location_name': 'Somewhere in deep space'
}
conf['log'] = {
'enabled': '0',
Expand Down Expand Up @@ -756,6 +758,16 @@ def test_get_location_from_user_timeline_coordinates(self):
self.assertTrue(type(loc) is models.WeatherLocation)
self.assertEqual(loc, test_loc)

@replace('weatherBot.get_tweepy_api', mocked_get_tweepy_api)
def test_get_location_from_user_timeline_coordinates_no_place_full_name(self):
"""Testing getting a location from twitter account's recent tweets using the coordinates property"""
fallback_loc = models.WeatherLocation(4, 3, 'test')
test_loc = models.WeatherLocation(2.5, 1.5, 'unnamed location')
weatherBot.CONFIG['variable_location']['unnamed_location_name'] = 'unnamed location'
loc = weatherBot.get_location_from_user_timeline('coordsnoplace', fallback_loc)
self.assertTrue(type(loc) is models.WeatherLocation)
self.assertEqual(loc, test_loc)

@replace('weatherBot.get_tweepy_api', mocked_get_tweepy_api)
def test_get_location_from_user_timeline_place(self):
"""Testing getting a location from twitter account's recent tweets using the place bounding box"""
Expand Down
5 changes: 5 additions & 0 deletions test_helpers.py
Expand Up @@ -64,6 +64,11 @@ def __init__(self):
if screen_name == 'nocoords':
self.coordinates = None
self.place = Place('cool place')
elif screen_name == 'coordsnoplace':
self.coordinates = {
'coordinates': [1.5, 2.5]
}
self.place = None
else:
self.coordinates = {
'coordinates': [1, 2]
Expand Down
2 changes: 1 addition & 1 deletion weatherBot.conf
Expand Up @@ -47,7 +47,7 @@
;user = BrianMitchL
# some locations have coordinates but do not contain any Twitter place information
# this will be used as a fallback
;unnamed-location-name = The Wilderness
;unnamed_location_name = The Wilderness

[log]
# write log to file
Expand Down
2 changes: 1 addition & 1 deletion weatherBot.py
Expand Up @@ -66,7 +66,7 @@ def load_config(path):
'variable_location': {
'enabled': conf['variable location'].getboolean('enabled', False),
'user': conf['variable location'].get('user', 'BrianMitchL'),
'unnamed_location_name': conf['variable location'].get('unnamed-location-name', 'The Wilderness')
'unnamed_location_name': conf['variable location'].get('unnamed_location_name', 'The Wilderness')
},
'log': {
'enabled': conf['log'].getboolean('enabled', True),
Expand Down

0 comments on commit 80fafe2

Please sign in to comment.