예제 #1
0
    def test_alpha2(self):
        obj = wrapper()
        result = obj.getalpha('Moo')
        fake_json = {'status': 404, 'message': 'Not Found'}


        self.assertEqual(result,fake_json)
예제 #2
0
 def test_alpha1(self):
     obj = wrapper()
     result=obj.getalpha('EG')
     print(result)
     fake_json={'alpha2Code':'EGY'}
     self.assertTrue('alpha2Code' in result)
     self.assertEqual(result['alpha2Code'], 'EG')
예제 #3
0
    def test_getByName1(self):

        fake_json = [{'name': 'Egypt', 'topLevelDomain': ['.eg'], 'alpha2Code': 'EG', 'alpha3Code': 'EGY', 'callingCodes': ['20'], 'capital': 'Cairo', 'altSpellings': ['EG', 'Arab Republic of Egypt'], 'region': 'Africa', 'subregion': 'Northern Africa', 'population': 91290000, 'latlng': [27.0, 30.0], 'demonym': 'Egyptian', 'area': 1002450.0, 'gini': 30.8, 'timezones': ['UTC+02:00'], 'borders': ['ISR', 'LBY', 'SDN'], 'nativeName': 'مصر\u200e', 'numericCode': '818', 'currencies': [{'code': 'EGP', 'name': 'Egyptian pound', 'symbol': '£'}], 'languages': [{'iso639_1': 'ar', 'iso639_2': 'ara', 'name': 'Arabic', 'nativeName': 'العربية'}], 'translations': {'de': 'Ägypten', 'es': 'Egipto', 'fr': 'Égypte', 'ja': 'エジプト', 'it': 'Egitto', 'br': 'Egito', 'pt': 'Egipto', 'nl': 'Egypte', 'hr': 'Egipat', 'fa': 'مصر'}, 'flag': 'https://restcountries.eu/data/egy.svg', 'regionalBlocs': [{'acronym': 'AU', 'name': 'African Union', 'otherAcronyms': [], 'otherNames': ['الاتحاد الأفريقي', 'Union africaine', 'União Africana', 'Unión Africana', 'Umoja wa Afrika']}, {'acronym': 'AL', 'name': 'Arab League', 'otherAcronyms': [], 'otherNames': ['جامعة الدول العربية', 'Jāmiʻat ad-Duwal al-ʻArabīyah', 'League of Arab States']}], 'cioc': 'EGY'}]

        obj = wrapper()
        result = obj.getName('Egypt')
        print(result)

        self.assertEqual(result, fake_json)
예제 #4
0
    def test_name2(self):

        obj = wrapper()
        result = obj.getName('nowhere')

        fake_json={'status': 404, 'message': 'Not Found'}


        print(result)

        self.assertEqual(result, fake_json)
예제 #5
0
 def test_callingCode2(self):
     obj = wrapper()
     result = obj.getcallingcode('804')
     expected = {'status': 404, 'message': 'Not Found'}
     self.assertEqual(result,expected)
예제 #6
0
 def test_getSpecific2(self):
     obj = wrapper()
     result=obj.getSpecific('Egypt','alpha3Code')
     expected='alpha3Code= EGY'
     self.assertEqual(result,expected)
예제 #7
0
 def test_currency3(self):
     obj = wrapper()
     result = obj.getcurrency('haha')
     fake_json = {'message': 'Bad Request', 'status': 400}
     self.assertEquals(result,fake_json)
예제 #8
0
    def test_currency2(self):
        obj = wrapper()
        result=obj.getcurrency('haha')
        fake_json =  {'status': 400, 'message': 'Bad Request'}

        self.assertEqual(fake_json,result)
예제 #9
0
 def test_region2(self):
     obj = wrapper()
     result=obj.getregion('malala')
     expected = {'status': 404, 'message': 'Not Found'}
     self.assertEqual(result,expected)
예제 #10
0
 def test_capital2(self):
     obj=wrapper()
     result=obj.getcapital('hahaha')
     expected = {'status': 404, 'message': 'Not Found'}
     self.assertEqual(result,expected)
예제 #11
0
import flask

from APIwrap.API import wrapper

app = flask.Flask(__name__)
app.config["DEBUG"] = True

wrap = wrapper()


class HTTP:
    @app.route('/', methods=["GET"])
    def home(self):
        return "Welcome to Our simple API  "

    @app.route('/<country>')
    def getByName(self, country):
        countryInfo = wrap.getName(country)
        if countryInfo is not None:
            return countryInfo
        else:
            return ("Not Found")

    @app.route('/all')
    def getall(self, country):
        countryInfo = wrap.getall()
        if countryInfo is not None:
            return str(countryInfo)
        else:
            return ("Not Found")