def test_update(self):
        store = SQLiteDataStore(
            {"name": "test.db", "table": "address"},
            ApiModel)

        for i in range(100):
            store.create({"name": "bob", "age": 34})

        self.assertEqual(
            store.update(
                {"name": "bob", "age": 34, "id": 34},
                {"name": "boby mc gee"}
                ), {"name": "boby mc gee", "age": 34, "id": 34})

        self.assertEqual(
            store.update(
                {"name": "bob", "age": 35, "id": 35},
                {"name": "boby mc gee", "age": 67}
                ), {"name": "boby mc gee", "age": 67, "id": 35})

        # adress is not part of the ressource description, it should
        # raise
        self.assertRaises(BadRequest,
                          store.update,
                          {"name": "bob", "age": "35", "id": 35},
                          {"adress": "1, main street"}
                          )

        self.assertRaises(NotFound,
                          store.update,
                          {"name": "bob", "age": "100", "id": 400},
                          {"name": "boby mc gee"}
                          )
        os.remove("test.db")
    def test_get(self):
        store = SQLiteDataStore({"name": ":memory:", "table": "address"}, ApiModel)

        for i in range(100):
            store.create({"name": "bob", "age": 34})

        self.assertEqual(store.get(10)["id"], 10)
        self.assertRaises(NotFound, store.get, 101)
Esempio n. 3
0
    def test_create(self):
        data = {"name": ":memory:", "table": "address"}
        store = SQLiteDataStore(data, ApiModel)

        self.assertRaises(NotFound, store.get, 1)
        self.assertEqual(store.create({"name": "bob", "age": 34}), 1)
        self.assertEqual(store.create({"name": "bob", "age": 35}), 2)
        self.assertEqual(store.create({"name": "bob", "age": 34}), 3)
        self.assertEqual(store.get(3)["id"], 3)
    def test_create(self):
        data = {"name": ":memory:", "table": "address"}
        store = SQLiteDataStore(data, ApiModel)

        self.assertRaises(NotFound, store.get, 1)
        self.assertEqual(store.create({"name": "bob", "age": 34}), 1)
        self.assertEqual(store.create({"name": "bob", "age": 35}), 2)
        self.assertEqual(store.create({"name": "bob", "age": 34}), 3)
        self.assertEqual(store.get(3)["id"], 3)
Esempio n. 5
0
    def test_get(self):
        store = SQLiteDataStore({
            "name": ":memory:",
            "table": "address"
        }, ApiModel)

        for i in range(100):
            store.create({"name": "bob", "age": 34})

        self.assertEqual(store.get(10)["id"], 10)
        self.assertRaises(NotFound, store.get, 101)
    def test_foreign_keys(self):
        data = {"name": "test.db", "table": "address"}
        store = SQLiteDataStore(data, ApiModel)
        self.assertEqual(store.create({"name": "bob", "age": 34}), 1)

        data = {"name": "test.db", "table": "user"}
        store2 = SQLiteDataStore(data, UserModel)
        self.assertEqual(store2.create({"last_name": "bob", "first_name": "Dick", "address": 1}), 1)

        self.assertRaises(BadRequest, store2.create, {"last_name": "moby", "first_name": "Dick", "address": 2})
        self.assertRaises(BadRequest, store.delete, 1)
        os.remove("test.db")
 def test_pagination(self):
     store = SQLiteDataStore(
         {"name": "test.db", "table": "address"},
         ApiModel)
     for i in range(100):
         store.create({"name": "bob", "age": 34})
     self.assertEqual(len(store.get_list(count=10)), 10)
     self.assertEqual(store.get_list(count=10)[-1]["id"], 10)
     self.assertEqual(store.get_list(offset=15)[0]["id"], 15)
     req = store.get_list(offset=15, count=2)
     self.assertEqual(len(req), 2)
     self.assertEqual(req[0]['id'], 15)
     os.remove("test.db")
    def test_delete(self):
        store = SQLiteDataStore({"name": ":memory:", "table": "address"}, ApiModel)

        for i in range(100):
            store.create({"name": "bob", "age": 34})

        # the object exists
        self.assertEqual(store.get(10)["id"], 10)

        # is delete
        self.assertEqual(store.delete(10), None)

        # does not exist anymore
        self.assertRaises(NotFound, store.get, 10)
Esempio n. 9
0
    def test_update(self):
        store = SQLiteDataStore({
            "name": "test.db",
            "table": "address"
        }, ApiModel)

        for i in range(100):
            store.create({"name": "bob", "age": 34})

        self.assertEqual(
            store.update({
                "name": "bob",
                "age": 34,
                "id": 34
            }, {"name": "boby mc gee"}), {
                "name": "boby mc gee",
                "age": 34,
                "id": 34
            })

        self.assertEqual(
            store.update({
                "name": "bob",
                "age": 35,
                "id": 35
            }, {
                "name": "boby mc gee",
                "age": 67
            }), {
                "name": "boby mc gee",
                "age": 67,
                "id": 35
            })

        # adress is not part of the ressource description, it should
        # raise
        self.assertRaises(BadRequest, store.update, {
            "name": "bob",
            "age": "35",
            "id": 35
        }, {"adress": "1, main street"})

        self.assertRaises(NotFound, store.update, {
            "name": "bob",
            "age": "100",
            "id": 400
        }, {"name": "boby mc gee"})
        os.remove("test.db")
Esempio n. 10
0
    def test_delete(self):
        store = SQLiteDataStore({
            "name": ":memory:",
            "table": "address"
        }, ApiModel)

        for i in range(100):
            store.create({"name": "bob", "age": 34})

        # the object exists
        self.assertEqual(store.get(10)["id"], 10)

        # is delete
        self.assertEqual(store.delete(10), None)

        # does not exist anymore
        self.assertRaises(NotFound, store.get, 10)
Esempio n. 11
0
    def test_pagination(self):
        store = SQLiteDataStore({
            "name": ":memory:",
            "table": "address"
        }, ApiModel)

        for i in range(100):
            store.create({"name": "bob", "age": 34})

        self.assertEqual(len(store.get_list(count=10)), 10)
        self.assertEqual(store.get_list(count=10)[-1]["id"], 10)
        self.assertEqual(store.get_list(offset=15)[0]["id"], 15)

        req = store.get_list(offset=15, count=2)

        self.assertEqual(len(req), 2)
        self.assertEqual(req[0]['id'], 15)
Esempio n. 12
0
    def test_foreign_keys(self):
        data = {"name": "test.db", "table": "address"}
        store = SQLiteDataStore(data, ApiModel)
        self.assertEqual(store.create({"name": "bob", "age": 34}), 1)

        data = {"name": "test.db", "table": "user"}
        store2 = SQLiteDataStore(data, UserModel)
        self.assertEqual(
            store2.create({
                "last_name": "bob",
                "first_name": "Dick",
                "address": 1
            }), 1)

        self.assertRaises(BadRequest, store2.create, {
            "last_name": "moby",
            "first_name": "Dick",
            "address": 2
        })
        self.assertRaises(BadRequest, store.delete, 1)
        os.remove("test.db")