@@ -0,0 +1,2099 @@
+%22%22%22Unit test module for table preferences logic%22%22%22%0Afrom flask_webtest import SessionScope%0Aimport json%0A%0Afrom portal.extensions import db%0Afrom portal.models.role import ROLE%0Afrom portal.models.table_preference import TablePreference%0Afrom tests import TestCase, TEST_USER_ID%0A%0A%0Aclass TestTablePreference(TestCase):%0A    %22%22%22Table Preference tests%22%22%22%0A%0A    def test_preference_upsert(self):%0A        self.promote_user(role_name=ROLE.ADMIN)%0A        self.login()%0A%0A        filter_json = %7B%22field1%22:%22filter1%22, %22field2%22:%22filter2%22%7D%0A        data = %7B%0A                %22sort_field%22: %22testSort%22,%0A                %22sort_order%22: %22asc%22,%0A                %22filters%22: json.dumps(filter_json),%0A               %7D%0A        resp = self.client.post(%0A            '/api/user/%7B%7D/table_preferences/testTable'.format(TEST_USER_ID),%0A            content_type='application/json',%0A            data=json.dumps(data))%0A%0A        self.assert200(resp)%0A        self.assertEquals(resp.json%5B'user_id'%5D, TEST_USER_ID)%0A        %0A%0A        pref = TablePreference.query.filter_by(user_id=TEST_USER_ID,%0A                                               table_name='testTable').first()%0A%0A        self.assertTrue(pref.updated_at)%0A        self.assertEquals(pref.filters, filter_json)%0A%0A    def test_preference_get(self):%0A        filter_json = %7B%22field1%22:%22filter1%22, %22field2%22:%22filter2%22%7D%0A        pref = TablePreference(user_id=TEST_USER_ID,%0A                                   table_name=%22testTable%22,%0A                                   sort_field=%22testSort%22,%0A                                   sort_order=%22desc%22,%0A                                   filters=filter_json)%0A        with SessionScope(db):%0A            db.session.add(pref)%0A            db.session.commit()%0A            pref = db.session.merge(pref)%0A%0A        self.promote_user(role_name=ROLE.ADMIN)%0A        self.login()%0A%0A        resp = self.client.get('/api/user/%7B%7D/table_preferences/'%0A                               'testTable'.format(TEST_USER_ID))%0A%0A        self.assert200(resp)%0A        self.assertEquals(resp.json%5B'user_id'%5D, TEST_USER_ID)%0A        self.assertEquals(json.loads(resp.json%5B'filters'%5D), filter_json)%0A

add unit tests