def test_toJSON_diffto(self): """Test LanguageDict.toJSON method.""" ld = LanguageDict({'de': 'foo', 'zh': 'bar'}) diffto = { 'de': { 'language': 'de', 'value': 'bar' }, 'en': { 'language': 'en', 'value': 'foo' } } self.assertEqual( ld.toJSON(diffto=diffto), { 'de': { 'language': 'de', 'value': 'foo' }, 'en': { 'language': 'en', 'value': '' }, 'zh': { 'language': 'zh', 'value': 'bar' } })
def test_fromJSON(self): """Test LanguageDict.fromJSON method.""" ld = LanguageDict.fromJSON( {'en': {'language': 'en', 'value': 'foo'}, 'zh': {'language': 'zh', 'value': 'bar'}}) self.assertIsInstance(ld, LanguageDict) self.assertEqual(ld, LanguageDict(self.lang_out))
def test_normalizeData(self): """Test LanguageDict.normalizeData method.""" self.assertEqual( LanguageDict.normalizeData(self.lang_out), { 'en': { 'language': 'en', 'value': 'foo' }, 'zh': { 'language': 'zh', 'value': 'bar' } })
def test_toJSON(self): """Test LanguageDict.toJSON method.""" ld = LanguageDict() self.assertEqual(ld.toJSON(), {}) ld = LanguageDict(self.lang_out) self.assertEqual( ld.toJSON(), {'en': {'language': 'en', 'value': 'foo'}, 'zh': {'language': 'zh', 'value': 'bar'}})
def test_delitem(self): """Test LanguageDict.__delitem__ metamethod.""" ld = LanguageDict(self.lang_out) ld.pop(self.site) ld.pop('zh') self.assertNotIn('en', ld) self.assertNotIn('zh', ld) self.assertLength(ld, 0)
def test_getitem(self): """Test LanguageDict.__getitem__ metamethod.""" ld = LanguageDict(self.lang_out) self.assertEqual(ld['en'], 'foo') self.assertEqual(ld[self.site], 'foo') self.assertIsNone(ld.get('de'))
def test_setitem(self): """Test LanguageDict.__setitem__ metamethod.""" ld = LanguageDict(self.lang_out) self.assertIn('en', ld) ld[self.site] = 'bar' self.assertIn('en', ld)
def test_init(self): """Test LanguageDict initializer.""" ld = LanguageDict() self.assertLength(ld, 0) ld = LanguageDict(self.lang_out) self.assertLength(ld, 2)