예제 #1
0
    def setUp(self):
        scarf.app.config['TESTING'] = True
        self.username = generator(12)
        self.domain = generator(12)
        self.password = generator(12)

        with app.test_request_context(''):
            uid = scarf.core.new_user(self.username, self.password, '{}@{}'.format(self.username, self.domain), '0.0.0.0')

        assert uid is not False 
        assert isinstance(uid, (int, long)) is True

        self.siteuser = scarf.core.SiteUser.create(self.username)
예제 #2
0
    def setUp(self):
        scarf.app.config['TESTING'] = True
        self.username = generator(12)
        self.domain = generator(12)
        self.password = generator(12)

        with app.test_request_context(''):
            uid = scarf.core.new_user(
                self.username, self.password,
                '{}@{}'.format(self.username, self.domain), '0.0.0.0')

        assert uid is not False
        assert isinstance(uid, (int, long)) is True

        self.siteuser = scarf.core.SiteUser.create(self.username)
예제 #3
0
def load_tests(loader, tests, pattern):
    test_cases = unittest.TestSuite()

    """
    this_dir = os.path.dirname(__file__)
    package_tests = loader.discover(start_dir=this_dir, pattern=pattern)
    test_cases.addTests(package_tests)
    """

    with open('blns.base64.json', 'r') as f:
        test_cases.addTest(SiteUserNaughtyStringsTestCase('runTest', 'bm9ybWFsIHN0cmluZw==')) # 'normal string'
        for naughty_string in json.load(f):
            with app.test_request_context(''):
                test_cases.addTest(SiteUserNaughtyStringsTestCase('runTest', naughty_string))
                test_cases.addTest(SiteStringsNaughtyStringsTestCase('runTest', naughty_string))
                test_cases.addTest(SiteItemNaughtyStringsTestCase('runTest', naughty_string))

    return test_cases
예제 #4
0
def load_tests(loader, tests, pattern):
    test_cases = unittest.TestSuite()
    """
    this_dir = os.path.dirname(__file__)
    package_tests = loader.discover(start_dir=this_dir, pattern=pattern)
    test_cases.addTests(package_tests)
    """

    with open('blns.base64.json', 'r') as f:
        test_cases.addTest(
            SiteUserNaughtyStringsTestCase(
                'runTest', 'bm9ybWFsIHN0cmluZw=='))  # 'normal string'
        for naughty_string in json.load(f):
            with app.test_request_context(''):
                test_cases.addTest(
                    SiteUserNaughtyStringsTestCase('runTest', naughty_string))
                test_cases.addTest(
                    SiteStringsNaughtyStringsTestCase('runTest',
                                                      naughty_string))
                test_cases.addTest(
                    SiteItemNaughtyStringsTestCase('runTest', naughty_string))

    return test_cases
예제 #5
0
from scarf import app

logging.basicConfig(filename='util.log',level=logging.DEBUG)

try:
    username = sys.argv[1]
    level = int(sys.argv[2])
except IndexError:
    print "No username or accesslevel specified"
    sys.exit(1)
except ValueError:
    level = sys.argv[2]

if level not in scarf.core.accesslevels:
    print "Invalid accesslevel: {}".format(level)
    print "Valid accesslevels:"
    for accesslevel in scarf.core.accesslevels:
        print "  {}\t{}".format(accesslevel, scarf.core.accesslevels[accesslevel])
    sys.exit(2)

with app.test_request_context(''):
    try:
        siteuser = scarf.core.SiteUser.create(username)
    except scarf.core.NoUser:
        print "user {} doesn't exist, have you registered it yet?".format(username)
        sys.exit(3)

    prev = siteuser.accesslevel
    siteuser.newaccesslevel(level)
    print "user {}'s accesslevel is now {}, was previously {}".format(siteuser.username, scarf.core.accesslevels[level], scarf.core.accesslevels[prev])
예제 #6
0
    try:
        filename = random.choice(os.listdir(directory))
    except OSError:
        print "Unable to load test images, skipping image addition for {}\n-----\n{} directory is missing or otherwise inaccessible!!\n-----".format(
            item.name, directory)
        return

    with open(os.path.join(directory, filename), "r") as f:
        img = scarf.core.new_img(f, title, item.uid, userid,
                                 fake.ipv4(network=False))
        print "Added image {} to item {} by userid {}".format(
            title, item.name, userid)


with app.test_request_context(''):
    users = dict()
    items = dict()

    # create some items and users
    for _ in range(0, 10):
        user = make_user()
        users[user.uid] = user
        for _ in range(0, 10):
            item = make_item(user)
            items[item.uid] = item
            add_image(item, user.uid, 'testimgs')

    # give those users a collection
    for user in users:
        for _ in range(0, 100):
예제 #7
0
 def test_siteuser_forgot_pw_reset(self):
     with app.test_request_context(''):
         self.siteuser.forgot_pw_reset('0.0.0.0', admin=True)
예제 #8
0
 def test_siteuser_forgot_pw_reset(self):
     with app.test_request_context(''):
         self.siteuser.forgot_pw_reset('0.0.0.0', admin=True)