def test_nestedSetWithList(self): requestMapObj = RequestMap() requestMapObj.set("user.name[0]", "Naman") self.assertEqual(requestMapObj.getObject(), {'user': { 'name': ['Naman'] }}) requestMapObj.set("user.name[1]", "Kumar") self.assertEqual(requestMapObj.getObject(), {'user': { 'name': ['Naman', 'Kumar'] }}) requestMapObj.set("user.name[2]", "Aggarwal") self.assertEqual(requestMapObj.getObject(), {'user': { 'name': ['Naman', 'Kumar', 'Aggarwal'] }}) requestMapObj.set("user.name[3].class.id", 1233) self.assertEqual( requestMapObj.getObject(), { 'user': { 'name': ['Naman', 'Kumar', 'Aggarwal', { 'class': { 'id': 1233 } }] } })
def test_simpleSet(self): requestMapObj = RequestMap() requestMapObj.set("user", 122132) self.assertEqual(requestMapObj.getObject(), {'user': 122132}) requestMapObj.set("name", "naman") self.assertEqual(requestMapObj.getObject(), { 'user': 122132, 'name': 'naman' }) #Override the value requestMapObj.set("name", "atul") self.assertEqual(requestMapObj.getObject(), { 'user': 122132, 'name': 'atul' })
def test_nestedSet(self): requestMapObj = RequestMap() requestMapObj.set("user.name.first", "Naman") self.assertEqual(requestMapObj.getObject(), {'user': { 'name': { 'first': 'Naman' } }}) requestMapObj.set("user.name.last.middle", "Kumar") self.assertEqual(requestMapObj.getObject(), { 'user': { 'name': { 'first': 'Naman', 'last': { 'middle': 'Kumar' } } } }) requestMapObj.set("user.name.last.last", "Aggarwal") self.assertEqual( requestMapObj.getObject(), { 'user': { 'name': { 'first': 'Naman', 'last': { 'middle': 'Kumar', 'last': 'Aggarwal' } } } })
def test_setInvalidAction(self): requestMapObj = RequestMap() requestMapObj.set("user.name[0]", "Naman") requestMapObj.set("user.name[1]", "Kumar") requestMapObj.set("user.name[2]", "Aggarwal") with self.assertRaises(TypeError): requestMapObj.set("user.name.class.id", 1233) self.assertEqual(requestMapObj.getObject(), {'user': { 'name': ['Naman', 'Kumar', 'Aggarwal'] }})
def test_constructor(self): requestMapObj = RequestMap() self.assertEqual(requestMapObj.getObject(), {})
def test_setAll(self): requestMapObj = RequestMap() requestMapObj.setAll({ 'user.name': ['Naman', 'Kumar', 'Aggarwal', { 'class': { 'id': 1233 } }] }) self.assertEqual( requestMapObj.getObject(), { "user": { 'name': ['Naman', 'Kumar', 'Aggarwal', { 'class': { 'id': 1233 } }] } }) requestMapObj.setAll({'employee.name': 'atul'}) self.assertDictEqual( requestMapObj.getObject(), { "user": { 'name': ['Naman', 'Kumar', 'Aggarwal', { 'class': { 'id': 1233 } }] }, "employee": { "name": "atul" } }) requestMapObj = RequestMap() requestMapObj.setAll([{ "user.name": "Naman", "user.lastname": "Aggarwal" }]) self.assertEqual( requestMapObj.getObject(), {"list": [{ "user": { "name": "Naman", "lastname": "Aggarwal" } }]}) #ARIZZINI: check list bug requestMapObj = RequestMap() requestMapObj.setAll([{ "id": 1, "title": "My Title", "body": "some body text", "userId": 1 }]) self.assertEqual( requestMapObj.getObject(), { "list": [{ "id": 1, "title": "My Title", "body": "some body text", "userId": 1 }] }) self.assertEqual(requestMapObj.get("list[0].id"), 1)
def test_get(self): requestMapObj = RequestMap() requestMapObj.set("user.name[0]", "Naman") requestMapObj.set("user.name[1]", "Kumar") requestMapObj.set("user.name[2]", "Aggarwal") requestMapObj.set("user.name[3].class.id", 1233) requestMapObj.set("employee[0].name", "atul") requestMapObj.set("employee[1].name", "sumit") self.assertEqual( requestMapObj.get("user"), {'name': ['Naman', 'Kumar', 'Aggarwal', { 'class': { 'id': 1233 } }]}) self.assertEqual( requestMapObj.get("user.name"), ['Naman', 'Kumar', 'Aggarwal', { 'class': { 'id': 1233 } }]) self.assertEqual(requestMapObj.get("user.name[3]"), {'class': { 'id': 1233 }}) self.assertEqual(requestMapObj.get("user.name[3].class"), {'id': 1233}) self.assertEqual(requestMapObj.get("user.name[3].class.id"), 1233) self.assertEqual(requestMapObj.get("user.name[3].class.id.value"), None) self.assertEqual(requestMapObj.get("user.name[4].class.id.value"), None) self.assertEqual(requestMapObj.get("employee"), [{ 'name': 'atul' }, { 'name': 'sumit' }]) self.assertEqual(requestMapObj.get("employee[3]"), None) self.assertEqual(requestMapObj.get("user.name[4].class"), None) #check object is still the same self.assertEqual( requestMapObj.getObject(), { "user": { 'name': ['Naman', 'Kumar', 'Aggarwal', { 'class': { 'id': 1233 } }] }, "employee": [{ 'name': 'atul' }, { 'name': 'sumit' }] })