예제 #1
0
    def test_get_news_feed_articles_none_200_response(self):
        self.license_keys = LicenseKeys()
        self.license_keys.load_license_key_file(
            os.path.dirname(__file__) + os.sep + "test.keys")

        mock_api = MockNewsApiApi()

        newsapi = NewsAPI(self.license_keys, mock_api)
        self.assertIsNotNone(newsapi)

        mock_api.response = MockResponse(
            401, {"content-type": "application/json"},
            json.loads("""
        {
            "articles": [
                {
                "title":        "test title",
                "description":  "test description",
                "publishedAt":  "test publishedAt",
                "author":       "test author",
                "url":          "test url",
                "urlToImage":   "test urlToImage"
                }
            ]
        }
        """))
        mock_url = NewsAPI._format_url("testservice", "key")

        articles = newsapi._get_news_feed_articles(mock_url, 10, True, False)
        self.assertIsNotNone(articles)
        self.assertEqual(0, len(articles))
예제 #2
0
    def setUp(self):
        self.license_keys = LicenseKeys()
        self.license_keys.load_license_key_file(
            os.path.dirname(__file__) +
            "/../../../../bots/y-bot/config/license.keys")

        self.lat = 56.0720397
        self.lng = -3.1752001
예제 #3
0
 def test_add_keys(self):
     keys = LicenseKeys()
     self.assertFalse(keys.has_key("KEY1"))
     keys.add_key("KEY1", "VALUE1")
     self.assertTrue(keys.has_key("KEY1"))
     self.assertEqual("VALUE1", keys.get_key("KEY1"))
     keys.add_key("KEY1", "VALUE2")
     self.assertTrue(keys.has_key("KEY1"))
     self.assertEqual("VALUE2", keys.get_key("KEY1"))
예제 #4
0
 def test_load_license_keys_file(self):
     keys = LicenseKeys()
     keys.load_license_key_file(
         os.path.dirname(__file__) + os.sep + "test.keys")
     self.assertTrue(keys.has_key('KEY1'))
     self.assertEquals("Key1Data", keys.get_key("KEY1"))
     self.assertTrue(keys.has_key('KEY2'))
     self.assertEquals("Key2Data", keys.get_key("KEY2"))
     self.assertTrue(keys.has_key('KEY3'))
     self.assertEquals("KEY3 Data With Spaces", keys.get_key("KEY3"))
     with self.assertRaises(Exception):
         keys.get_key("KEY5")
예제 #5
0
    def test_geonames(self):

        license_keys = LicenseKeys()
        license_keys.load_license_key_file(os.path.dirname(__file__)+ os.sep + "test.keys")

        geonames = GeoNamesApi(license_keys)
        self.assertIsNotNone(geonames)

        GeoNamesApi.get_latlong_for_postcode_response_file = os.path.dirname(__file__)+ os.sep + "geonames_latlong.json"

        latlng = geonames.get_latlong_for_postcode('KY39UR')
        self.assertIsNotNone(latlng)
        self.assertEquals(latlng.latitude, 56.07206267570594)
        self.assertEquals(latlng.longitude, -3.175233048730664)
예제 #6
0
 def test_load_license_keys_data(self):
     keys = LicenseKeys()
     keys.load_license_key_data("""
     KEY1=Key1Data
     KEY2=Key2Data
     # This is a comment
     KEY3=KEY3 Data With Spaces
     This is not a key
     """)
     self.assertTrue(keys.has_key('KEY1'))
     self.assertEquals("Key1Data", keys.get_key("KEY1"))
     self.assertTrue(keys.has_key('KEY2'))
     self.assertEquals("Key2Data", keys.get_key("KEY2"))
     self.assertTrue(keys.has_key('KEY3'))
     self.assertEquals("KEY3 Data With Spaces", keys.get_key("KEY3"))
     with self.assertRaises(Exception):
         keys.get_key("KEY5")
예제 #7
0
    def test_get_news_feed_articles_content_not_json(self):
        self.license_keys = LicenseKeys()
        self.license_keys.load_license_key_file(
            os.path.dirname(__file__) + os.sep + "test.keys")

        mock_api = MockNewsApiApi()

        newsapi = NewsAPI(self.license_keys, mock_api)
        self.assertIsNotNone(newsapi)

        mock_api.response = MockResponse(200,
                                         {"content-type": "application/xml"},
                                         None)

        mock_url = NewsAPI._format_url("testservice", "key")

        articles = newsapi._get_news_feed_articles(mock_url, 10, True, False)
        self.assertIsNotNone(articles)
        self.assertEqual(0, len(articles))
예제 #8
0
파일: client.py 프로젝트: LombeC/program-r
    def __init__(self, id, argument_parser=None):
        self._id = id

        self._arguments = self.parse_arguments(argument_parser=argument_parser)
        # print("self._arguments: {}".format(self._arguments))
        self.initiate_logging(self.arguments)

        self._configuration = None
        self.load_configuration(self.arguments)
        self.parse_configuration()

        bot_configurations = self.configuration.client_configuration.configurations
        self._bot_factory = BotFactory(self, bot_configurations)

        self._license_keys = LicenseKeys()
        self.load_license_keys()
        self.get_license_keys()

        self._scheduler = None
        self.load_scheduler()

        self._renderer = self.load_renderer()
예제 #9
0
import os

import metoffer

from programr.utils.weather.metoffice import MetOffice

if __name__ == '__main__':

    # Only to be used to create test data for unit aiml_tests

    from programr.utils.license.keys import LicenseKeys

    license_keys = LicenseKeys()
    license_keys.load_license_key_file(
        os.path.dirname(__file__) +
        '/../../../../bots/y-bot/config/license.keys')

    met_office = MetOffice(license_keys)

    lat = 56.0720397
    lng = -3.1752001

    log_to_file = False

    if log_to_file:
        met_office.nearest_location_observation_to_file(
            lat, lng, "observation.json")
        met_office.nearest_location_forecast_to_file(lat, lng, metoffer.DAILY,
                                                     "forecast_daily.json")
        met_office.nearest_location_forecast_to_file(
            lat, lng, metoffer.THREE_HOURLY, "forecast_threehourly.json")
예제 #10
0
 def test_geonames_with_license_keys(self):
     license_keys = LicenseKeys()
     license_keys.add_key('GEO_NAMES_COUNTRY', "DummyValue")
     license_keys.add_key('GEO_NAMES_ACCOUNTNAME', "DummyValue")
     geonames = GeoNamesApi(license_keys)
예제 #11
0
 def test_geonames_no_country(self):
     license_keys = LicenseKeys()
     license_keys.add_key('GEO_NAMES_ACCOUNTNAME', "DummyValue")
     with self.assertRaises(Exception):
         geonames = GeoNamesApi(license_keys)
예제 #12
0
 def test_geonames_no_license_keys(self):
     license_keys = LicenseKeys()
     with self.assertRaises(Exception):
         geonames = GeoNamesApi(license_keys)
예제 #13
0
 def setUp(self):
     self.license_keys = LicenseKeys()
     self.license_keys.load_license_key_file(
         os.path.dirname(__file__) +
         "/../../../../bots/y-bot/config/license.keys")
예제 #14
0
 def setUp(self):
     self.bot = TestBot()
     self.bot.license_keys = LicenseKeys()
     self.bot.license_keys.load_license_key_file(
         os.path.dirname(__file__) + os.sep + "test.keys")
예제 #15
0
 def test_missing_keys(self):
     self.license_keys = LicenseKeys()
     self.license_keys.load_license_key_file(
         os.path.dirname(__file__) + os.sep + "bad_test.keys")
     with self.assertRaises(Exception):
         newsapi = NewsAPI(self.license_keys)