Esempio n. 1
0
    def test_remove(self):
        manager = Manager(name="Maz")
        manager.save().run_sync()
        self.assertTrue("Maz" in Manager.select(Manager.name).output(
            as_list=True).run_sync())

        manager.remove().run_sync()
        self.assertTrue("Maz" not in Manager.select(Manager.name).output(
            as_list=True).run_sync())
Esempio n. 2
0
    def test_create_new(self):
        """
        Make sure that creating a new instance works.
        """
        Manager.objects().create(name="Maz").run_sync()

        names = [i["name"] for i in Manager.select(Manager.name).run_sync()]
        self.assertTrue("Maz" in names)
Esempio n. 3
0
 async def run_queries():
     return await asyncio.gather(
         Manager.select(),
         Manager.insert(Manager(name="Golangs")),
         Manager.delete().where(Manager.name != "Golangs"),
         Manager.objects(),
         Manager.count(),
         Manager.raw("SELECT * FROM manager"),
     )
Esempio n. 4
0
    def test_unique(self):
        unique_query = Manager.alter().set_unique(Manager.name, True)
        unique_query.run_sync()

        Manager(name="Bob").save().run_sync()

        # Make sure non-unique names work:
        Manager(name="Sally").save().run_sync()

        # Check there's a unique row error ...
        with self.assertRaises(Exception):
            Manager(name="Bob").save().run_sync()

        response = Manager.select().run_sync()
        self.assertEqual(len(response), 2)

        # Now remove the constraint, and add a row.
        not_unique_query = Manager.alter().set_unique(Manager.name, False)
        not_unique_query.run_sync()
        Manager(name="Bob").save().run_sync()

        response = Manager.select().run_sync()
        self.assertTrue(len(response), 2)
Esempio n. 5
0
    def test_save_new(self):
        """
        Make sure that saving a new instance works.
        """
        manager = Manager(name="Maz")

        query = manager.save()
        print(query)
        self.assertTrue("INSERT" in query.__str__())

        query.run_sync()

        names = [i["name"] for i in Manager.select(Manager.name).run_sync()]
        self.assertTrue("Maz" in names)

        manager.name = "Maz2"
        query = manager.save()
        print(query)
        self.assertTrue("UPDATE" in query.__str__())

        query.run_sync()
        names = [i["name"] for i in Manager.select(Manager.name).run_sync()]
        self.assertTrue("Maz2" in names)
        self.assertTrue("Maz" not in names)