Skip to content

Commit

Permalink
Merge ac1ded8 into d35dd21
Browse files Browse the repository at this point in the history
  • Loading branch information
YJDave committed Jan 30, 2018
2 parents d35dd21 + ac1ded8 commit d6923f9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 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 @@ -73,9 +74,9 @@ def status(self):

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
10 changes: 10 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ def test_hello(self):
result = self.loklak.hello()
self.assertEqual(result['status'], u'ok')

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."""
result = self.loklak.geocode()
Expand Down

0 comments on commit d6923f9

Please sign in to comment.