Ejemplo n.º 1
0
    def test_init_2(self):
        """
        Test form checking constructor parameters, unequal lists length
        """
        # Given...
        from shortening.service.models import db, User, Logs, Shortening
        from peewee import IntegrityError

        db.connect()
        if not User.table_exists():
            User.create_table()
        if not Logs.table_exists():
            Logs.create_table()
        if not Shortening.table_exists():
            Shortening.create_table()

        User.proxy = 1

        try:
            u = User(login='******', password='******')
            u.save()
        except IntegrityError:
            print("User already exists")

        users = User.select()
        for user in users:
            print('> %s' % (str(user),))

        db.close()
Ejemplo n.º 2
0
    def test_init_2(self):
        """
        Test form checking constructor parameters, unequal lists length
        """
        # Given...
        from shortening.service.models import db, User, Logs, Shortening
        from peewee import IntegrityError, DoesNotExist

        db.connect()
        if not User.table_exists():
            User.create_table()
        if not Logs.table_exists():
            Logs.create_table()
        if not Shortening.table_exists():
            Shortening.create_table()

        try:
            u = User(login='******', password='******')
            u.save()
        except IntegrityError:
            print("User already exists")

        users = User.select()
        for user in users:
            print('> %s' % (str(user),))

        try:
            s = Shortening(user=User.get(login="******"), short_url="0002", long_url="http://google.com/")
            s.save()
        except IntegrityError:
            print("Shortening already exists")

        shortenings = Shortening.select()
        for shortening in shortenings:
            print('>> %s' % (str(shortening),))

        try:
            s = Shortening.get(Shortening.short_url == "80001")
            print(":" + str(s))
        except DoesNotExist:
            print("Shortening not exists")

        db.close()