Пример #1
0
    def test_valid_postal_code_invalid_country_valid_username(self, mock_get):
        '''

        :param mock_get: mock the object behaviour
        :return:
        '''
        postal_code_information = {'postalcodes': []}

        # Configure the mock to return a response with an OK status code. Also, the mock should have
        # a `json()` method that returns.
        mock_get.return_value = Mock(ok=True)
        mock_get.return_value.json.return_value = postal_code_information

        # assume
        postal_code = '6600'
        country = 'HELLO'
        user_name = 'shirel_biton'

        # expected
        expected = {'postalcodes': []}

        # action
        result = PostalCode.postal_code_places(postal_code, country, user_name)

        # assert
        self.assertEqual(result, expected)
Пример #2
0
    def test_valid_lat_invalid_lng_valid_username(self, mock_get):
        '''

        :param mock_get: mock the object behaviour
        :return:
        '''
        time_zone_information = {
            'status': {
                'message': 'error parsing parameter',
                'value': 14
            }
        }

        # Configure the mock to return a response with an OK status code. Also, the mock should have
        # a `json()` method that returns.
        mock_get.return_value = Mock(ok=True)
        mock_get.return_value.json.return_value = time_zone_information

        # assume
        lat = '47.01'
        lng = 'sdas'
        user_name = 'shirel_biton'

        # expected
        expected = 'error parsing parameter'

        # action
        result = PostalCode.time_zone(lat, lng, user_name)

        # assert
        self.assertEqual(result, expected)
Пример #3
0
    def test_valid_postal_code_valid_country_valid_username(self, mock_get):
        '''
        :param mock_get: mock the object behaviour
        :return:
        '''
        postal_code_information = [
            'Breitenwang', 'Ehenbichl', 'Lechaschau', 'Musau', 'Oberletzen',
            'Oberpinswang', 'Pflach', 'Reutte', 'Unterletzen', 'Unterpinswang'
        ]

        # Configure the mock to return a response with an OK status code. Also, the mock should have
        # a `json()` method that returns.
        mock_get.return_value = Mock(ok=True)
        mock_get.return_value.json.return_value = postal_code_information

        # assume
        postal_code = '6600'
        country = 'AT'
        user_name = 'shirel_biton'

        # expected
        expected = [
            'Breitenwang', 'Ehenbichl', 'Lechaschau', 'Musau', 'Oberletzen',
            'Oberpinswang', 'Pflach', 'Reutte', 'Unterletzen', 'Unterpinswang'
        ]

        # action
        result = PostalCode.postal_code_places(postal_code, country, user_name)

        # assert
        self.assertEqual(result, expected)
Пример #4
0
def main():
    '''
    :return:
    '''
    while True:
        print("""
        1. check places names in a specific postal code 
        2. check sunrise and sunset in a specific lan and lng
        3. exit
        """)

        menu = input()

        switcher = {
            1: lambda x: PostalCode.input_location("p"),
            2: lambda x: PostalCode.input_location("t"),
            3: lambda x: close(),
        }
        switcher.get(int(menu))(0)
Пример #5
0
    def test_invalid_type_user_name(self):
        '''

        :return:
        '''
        # assume
        lat = '47.01'
        lng = '10.2'
        user_name = 1

        # expected
        expected = "Invalid user type"

        # action
        result = PostalCode.time_zone(lat, lng, user_name)

        # assert
        self.assertEqual(result, expected)
Пример #6
0
    def test_invalid_type_lng(self):
        '''

        :return:
        '''
        # assume
        lat = '47.01'
        lng = 10
        user_name = 'shirel_biton'

        # expected
        expected = "Invalid input type"

        # action
        result = PostalCode.time_zone(lat, lng, user_name)

        # assert
        self.assertEqual(result, expected)
Пример #7
0
    def test_invalid_type_user_name(self):
        '''

        :return:
        '''
        # assume
        postal_code = '6600'
        country = 'AT'
        user_name = 1

        # expected
        expected = "Invalid user type"

        # action
        result = PostalCode.postal_code_places(postal_code, country, user_name)

        # assert
        self.assertEqual(result, expected)
Пример #8
0
    def test_invalid_type_country(self):
        '''

        :return:
        '''
        # assume
        postal_code = '6600'
        country = 324
        user_name = 'shirel_biton'

        # expected
        expected = "Invalid input type"

        # action
        result = PostalCode.postal_code_places(postal_code, country, user_name)

        # assert
        self.assertEqual(result, expected)
Пример #9
0
    def test_valid_lat_valid_lng_valid_username(self, mock_get):
        '''

        :param mock_get: mock the object behaviour
        :return:
        '''
        time_zone_information = {
            'sunrise': '2020-03-17 06:27',
            'lng': 10.2,
            'countryCode': 'AT',
            'gmtOffset': 1,
            'rawOffset': 1,
            'sunset': '2020-03-17 18:28',
            'timezoneId': 'Europe/Vienna',
            'dstOffset': 2,
            'countryName': 'Austria',
            'time': '2020-03-17 11:16',
            'lat': 47.01
        }

        # Configure the mock to return a response with an OK status code. Also, the mock should have
        # a `json()` method that returns.
        mock_get.return_value = Mock(ok=True)
        mock_get.return_value.json.return_value = time_zone_information

        # assume
        lat = '47.01'
        lng = '10.02'
        user_name = 'shirel_biton'

        # expected
        expected = 'country name: Austria, sunrise: 2020-03-17 06:27, sunset2020-03-17 18:28'

        # action
        result = PostalCode.time_zone(lat, lng, user_name)

        # assert
        self.assertEqual(result, expected)