Ejemplo n.º 1
0
    def test_init_4(self):
        from shortening.service.models import db, User, Shortening
        from peewee import IntegrityError

        # Given...
        db = SqliteDatabase(TEST_DB, check_same_thread=False)
        db.connect()

        # remove all records
        Shortening.delete().execute()

        # Test...
        total = 1000
        t0 = time.time()
        for x in range(total):
            try:
                s = Shortening(user=User.get(login="******"), short_url=Shortening.generate_uniqie_shortening(),
                               long_url="http://google.com/")
                s.save()
            except IntegrityError:
                pass
                # Shortening already exists

        t1 = time.time()

        diff = t1 - t0
        diff_per_row = diff / total
        print("Insert records with random name performance test, method 1, set size: %s, time: %s s, per row: %s s" %
              (total, diff, diff_per_row))
        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

        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.º 3
0
    def test_init_1(self):
        db.connect()
        username = '******'
        password = '******'

        result = BaseHandler.check_credentials(username, password)
        self.assertIsNotNone(result)
        db.close()
Ejemplo n.º 4
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()
Ejemplo n.º 5
0
    def test_insert_existing_performance(self):
        from shortening.service.models import db, User, Shortening
        from peewee import IntegrityError, DoesNotExist

        # Given...
        db = SqliteDatabase(TEST_DB, check_same_thread=False)
        db.connect()

        # remove all records
        Shortening.delete().execute()

        # Test...
        total = 10000
        t0 = time.time()
        for x in range(total):
            try:
                s = Shortening(user=User.get(login="******"), short_url="0002", long_url="http://long_url/")
                s.save()
            except IntegrityError:
                pass
                # Shortening already exists

        t1 = time.time()
        diff = t1 - t0
        diff_per_row = diff / total
        print("Insert of existing record performance test, method 1, set size: %s, time: %s, per row: %s s" %
              (total, diff, diff_per_row))

        # THIS IS FASTEST METHOD
        # remove all records
        Shortening.delete().execute()
        t0 = time.time()
        for x in range(total):
            query = Shortening.select().where(Shortening.short_url == "80001")
            if not query.exists():
                # short_url does not exists exists
                pass

        t1 = time.time()
        diff = t1 - t0
        diff_per_row = diff / total
        print("Insert of existing record performance test, method 2, set size: %s, time: %s, per row: %s s" %
              (total, diff, diff_per_row))

        # remove all records
        Shortening.delete().execute()
        t0 = time.time()
        for x in range(total):
            try:
                s = Shortening.get(Shortening.short_url == "80001")
                print(":" + str(s))
            except DoesNotExist:
                # Shortening not exists
                pass

        t1 = time.time()
        diff = t1 - t0
        diff_per_row = diff / total
        print("Insert of existing record performance test, method 3, set size: %s, time: %s, per row: %s s" %
              (total, diff, diff_per_row))

        db.close()