class DictionaryNamesTestCase(unittest.TestCase): def setUp(self): app.config['TESTING'] = True app.config['MONGODB_DB'] = TEST_DB self.app = app.test_client() self.obj = DictionaryNames() def tearDown(self): db.drop_collection(self.obj.code) def test_get_list(self): with self.assertRaises(ValueError): result = self.obj.get_list() #self.assertEqual(result.count(), 0) #self.assertEqual(list(result), list()) def test_add(self): data = dict(code='test', name=u'Тестовый справочник') _id = self.obj.add(data) self.assertIsNotNone(_id) result = self.obj.get_by_id(_id) data.update(dict(_id=_id)) self.assertDictEqual(data, result) def test_update(self): data = dict(code='test2', name=u'Тестовый справочник2') _id = self.obj.add(data) self.assertIsNotNone(_id) update_data = dict(code='test2', name=u'Тестовый справочник2 (updated)', updated=datetime.now()) self.obj.update(_id, update_data) result = self.obj.get_by_id(_id) update_data.update(dict(_id=_id)) result.pop('updated') update_data.pop('updated') self.assertDictEqual(result, update_data) def test_delete(self): code = 'test3' data = dict(code=code, name=u'Тестовый справочник3') _id = self.obj.add(data) self.assertIsNotNone(_id) self.obj.delete(code) result = self.obj.get_by_code(code) self.assertIsNone(result) def test_update_by_code(self): code = 'test4' data = dict(code=code, name=u'Тестовый справочник4') _id = self.obj.add(data) self.assertIsNotNone(_id) update_data = dict(code=code, name=u'Тестовый справочник4 (updated)', updated=datetime.now()) self.obj.update_by_code(code, update_data) result = self.obj.get_by_code(code) update_data.update(dict(_id=_id)) result.pop('updated') update_data.pop('updated') self.assertDictEqual(result, update_data)
def post(self): """Заведение информации о справочнике""" data = self.parse_request(request) obj = DictionaryNames() try: _id = obj.add(data) except TypeError, e: raise InvalidAPIUsage(e.message, status_code=400)