Skip to content

Commit

Permalink
Merge pull request loklak#90 from YJDave/xml
Browse files Browse the repository at this point in the history
Remove bug from xmlToJson method.
  • Loading branch information
daminisatya authored Jan 31, 2018
2 parents 2eda64e + 0213712 commit ea5f8fc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
5 changes: 3 additions & 2 deletions loklak.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import re
import requests
from xmljson import badgerfish as bf
import lxml.etree as et
from json import dumps
import csv

Expand Down Expand Up @@ -72,9 +73,9 @@ def status(self, status_application='api/status.json'):

def xmlToJson(self, xmlData = None):
"""Convert XML to JSON as the service."""
jsonData = ''
jsonData = '[]'
if xmlData:
jsonData = dumps(bf.data(fromstring(xmlData)))
jsonData = dumps(bf.data(et.fromstring(xmlData)))
return jsonData

def csvToJson(self, csvData = None, fieldnamesList = None):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
requests==2.16.0
xmljson==0.1.9
lxml==4.1.1
13 changes: 9 additions & 4 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ def test_hello(self):
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_xmlToJson(self):
"""Test xmlToJson method."""
xmlData = "<note>\n<to>Coders</to>\n<from>FOSSASIA</from>\n<heading>FOSSASIA</heading> \
\n<body>Let's code!!</body>\n</note>"
expectedJSONData = '{"note": {"to": {"$": "Coders"}, "from": {"$": "FOSSASIA"}, "heading": {"$": "FOSSASIA"}, "body": {"$": "Let\'s code!!"}}}'
result = self.loklak.xmlToJson(xmlData)
self.assertEqual(result, expectedJSONData)
result = self.loklak.xmlToJson()
self.assertEqual(result, "[]")

def test_geocode(self):
"""Test geological features."""
Expand Down

0 comments on commit ea5f8fc

Please sign in to comment.