def create(args): """Create a user.""" username = args.username.decode("utf8") try: user = User.objects.get(username=username) except User.DoesNotExist: pass else: print("ERROR: There is already an user with that username") return # let's create it user = User(username=username, email=args.email.decode("utf8"), first_name=args.firstname.decode("utf8"), last_name=args.lastname.decode("utf8")) user.set_password(args.password.decode("utf8")) user.save() # refresh the user object to ensure permissions caches are reloaded user = User.objects.get(username=username) # create also the storage user visible_name = "%s %s" % (user.first_name, user.last_name) services.make_storage_user(user.id, username, visible_name, 2**20) print("Success: User created ok")
def create(args): """Create a user.""" username = args.username.decode("utf8") try: user = User.objects.get(username=username) except User.DoesNotExist: pass else: print "ERROR: There is already an user with that username" return # let's create it user = User(username=username, email=args.email.decode("utf8"), first_name=args.firstname.decode("utf8"), last_name=args.lastname.decode("utf8")) user.set_password(args.password.decode("utf8")) user.save() # refresh the user object to ensure permissions caches are reloaded user = User.objects.get(username=username) # create also the storage user visible_name = "%s %s" % (user.first_name, user.last_name) services.make_storage_user(user.id, username, visible_name, 2 ** 20) print "Success: User created ok"
def main(test_filter, repeat=False): """Main function.""" all_tests = get_all_tests(test_filter) prefix = 'main:' timestamp = time.strftime("%Y%m%d%M%H%S") # create user user1 = "integtest" + timestamp user2 = "integotro" + timestamp for u in (user1, user2): services.make_storage_user(username=u) debug(prefix, 'User created:', u) debug(prefix, 'Content blobs created') sd1 = SyncDaemon(user1, 1, timestamp, verbose=True) debug(prefix, 'SyncDaemon 1 created.') sd2 = SyncDaemon(user1, 2, timestamp, verbose=True) debug(prefix, 'SyncDaemon 2 created.') sd3 = SyncDaemon(user2, 3, timestamp, verbose=True) debug(prefix, 'SyncDaemon 2 created.') yield sd1.start() debug(prefix, 'SyncDaemon 1 started.') yield sd2.start() debug(prefix, 'SyncDaemon 2 started.') yield sd3.start() debug(prefix, 'SyncDaemon 3 started.') try: if repeat: i = 0 while True: i += 1 debug(prefix, 'Executing tests, run', i) yield execute_tests(all_tests, sd1, sd2, sd3) else: yield execute_tests(all_tests, sd1, sd2, sd3) debug(prefix, 'Tests executed.') except Exception as e: print('\n', '!' * 20, 'There was a problem. Failure below.', '!' * 20) print(e) print('!' * 20, 'There was a problem. Failure above.', '!' * 20) debug(prefix, 'End.') yield sd1.stop() debug(prefix, 'sd1 stopped.') yield sd2.stop() debug(prefix, 'sd2 stopped.') yield sd3.stop() debug(prefix, 'sd3 stopped.') reactor.stop() debug(prefix, 'reactor stopped.')
def setUp(self): super(DownloadServicesTestCase, self).setUp() self.user = services.make_storage_user("username", 1000) self.volume_id = self.user.root_volume_id self.fpath = "/a/b/c/d/e/file.txt" self.dl_url = "http://downloadme" self.dl_key = "key"
def test_make_storage_user(self): """Test the make_storage_user function.""" storage_user = make_storage_user( username="******", max_storage_bytes=MAX_STORAGE_BYTES, visible_name="Visible Name") self.assert_storage_user( storage_user, MAX_STORAGE_BYTES, visible_name='Visible Name')
def setUp(self): super(RestHelperTestCase, self).setUp() self.user = make_storage_user( username="******", visible_name="bobby boo", max_storage_bytes=2 * (2 ** 30)) self.mapper = ResourceMapper() self.handler = self.add_memento_handler(logger, level=logging.INFO) self.helper = RestHelper(self.mapper)
def create_test_user( username='******', email='*****@*****.**', first_name='Fredrick', last_name='Flintsone', password=None, max_storage_bytes=2 ** 20): """Create a user used for testing.""" return services.make_storage_user( username, max_storage_bytes=max_storage_bytes, password=password, email=email, first_name=first_name, last_name=last_name, is_staff=False, is_active=True, is_superuser=False)
def setUp(self): super(RestHelperTestCase, self).setUp() self.user = make_storage_user(username="******", visible_name="bobby boo", max_storage_bytes=2 * (2**30)) self.mapper = ResourceMapper() self.handler = self.add_memento_handler(logger, level=logging.INFO) self.helper = RestHelper(self.mapper)
def test_get_node(self): """Test the get_node function.""" user1 = make_storage_user("User 1", MAX_STORAGE_BYTES) node = user1.volume().root.make_file("test file") new_node = get_node(node.id) self.assertEqual(node.id, new_node.id) self.assertEqual(node.parent_id, new_node.parent_id) self.assertEqual(node.name, new_node.name) self.assertEqual(node.path, new_node.path)
def create(self, username, password, email, firstname, lastname, **kwargs): """Create a user.""" try: User.objects.get(username=username) except User.DoesNotExist: pass else: raise CommandError('There is already an user with that username') # let's create it services.make_storage_user(username, max_storage_bytes=2**50, password=password, email=email, first_name=firstname, last_name=lastname) self.stdout.write('Success: User created ok')
def main(test_filter, repeat=False): """Main function.""" all_tests = get_all_tests(test_filter) prefix = 'main:' timestamp = time.strftime("%Y%m%d%M%H%S") # create user user1 = "integtest" + timestamp user2 = "integotro" + timestamp for u in (user1, user2): services.make_storage_user(username=u) debug(prefix, 'User created:', u) debug(prefix, 'Content blobs created') sd1 = SyncDaemon(user1, 1, timestamp, verbose=True) debug(prefix, 'SyncDaemon 1 created.') sd2 = SyncDaemon(user1, 2, timestamp, verbose=True) debug(prefix, 'SyncDaemon 2 created.') sd3 = SyncDaemon(user2, 3, timestamp, verbose=True) debug(prefix, 'SyncDaemon 2 created.') yield sd1.start() debug(prefix, 'SyncDaemon 1 started.') yield sd2.start() debug(prefix, 'SyncDaemon 2 started.') yield sd3.start() debug(prefix, 'SyncDaemon 3 started.') try: if repeat: i = 0 while True: i += 1 debug(prefix, 'Executing tests, run', i) yield execute_tests(all_tests, sd1, sd2, sd3) else: yield execute_tests(all_tests, sd1, sd2, sd3) debug(prefix, 'Tests executed.') except Exception, e: print '\n', '!' * 20, 'There was a problem. Failure below.', '!' * 20 print e print '!' * 20, 'There was a problem. Failure above.', '!' * 20
def test_get_public_file(self): """Test the get_public_file function.""" user = make_storage_user("Cool UserName", 10) a_file = user.volume().root.make_file_with_content( "file.txt", self.factory.get_fake_hash(), 123, 1, 1, uuid.uuid4()) a_file.change_public_access(True) public_key = a_file.public_key f1 = get_public_file(public_key) self.assertEqual(f1, a_file) a_file.change_public_access(False) self.assertRaises(errors.DoesNotExist, get_public_file, public_key)
def create(self, username, password, email, firstname, lastname, **kwargs): """Create a user.""" try: User.objects.get(username=username) except User.DoesNotExist: pass else: raise CommandError("There is already an user with that username") # let's create it services.make_storage_user( username, max_storage_bytes=2 ** 20, password=password, email=email, first_name=firstname, last_name=lastname, ) self.stdout.write("Success: User created ok")
def test_get_storage_user(self): """Test the get_storage_user function.""" user = make_storage_user( "Cool UserName", MAX_STORAGE_BYTES, visible_name='Visible Name') user = get_storage_user(user.id) self.assertTrue(isinstance(user, DAOStorageUser)) # now check a locked user. StorageUser.objects.filter(id=user.id).update(locked=True) self.assertRaises(errors.LockedUserError, get_storage_user, user.id) # and ignore the lock too user = get_storage_user(user.id, readonly=True) self.assertTrue(isinstance(user, DAOStorageUser))
def test_get_public_directory(self): """Test the get_public_directory function.""" user = make_storage_user("Cool UserName", 10) a_dir = user.volume().root.make_subdirectory('test_dir') a_dir.make_file_with_content( "file.txt", self.factory.get_fake_hash(), 123, 1, 1, uuid.uuid4()) a_dir.change_public_access(True, allow_directory=True) public_key = a_dir.public_key pub_dir = get_public_directory(public_key) self.assertEqual(pub_dir, a_dir) a_dir.change_public_access(False, allow_directory=True) self.assertRaises(errors.DoesNotExist, get_public_directory, public_key)
def create_test_user(username='******', email='*****@*****.**', first_name='Fredrick', last_name='Flintsone', password=None, max_storage_bytes=2**20): """Create a user used for testing.""" return services.make_storage_user(username, max_storage_bytes=max_storage_bytes, password=password, email=email, first_name=first_name, last_name=last_name, is_staff=False, is_active=True, is_superuser=False)
def test_quota(self): """Test quota info.""" usr2 = services.make_storage_user( u"otheruser", visible_name=u"Other User", max_storage_bytes=self.usr0.max_storage_bytes * 10) share = usr2.root.share(self.usr0.id, u"a share", readonly=True) @defer.inlineCallbacks def do_test(client): """Do the actual test.""" yield client.dummy_authenticate("open sesame") result = yield client.get_free_space(request.ROOT) self.assertEqual(self.usr0.free_bytes, result.free_bytes) self.assertEqual(request.ROOT, result.share_id) result = yield client.get_free_space(str(share.id)) self.assertEqual(usr2.free_bytes, result.free_bytes) self.assertEqual(str(share.id), result.share_id) return self.callback_test(do_test, add_default_callbacks=True)
def test_get_failed_downloads(self): """Test the get_failed_downloads() function.""" # Create downloads udf1 = self.user.make_udf("~/path/name") d1 = downloadservices.make_download(self.user.id, udf1.id, "path/file", "http://example.com") downloadservices.download_error(self.user.id, d1.id, "download failed") user2 = services.make_storage_user("user2", 10 * 23) udf2 = user2.make_udf("~/path/name") d2 = downloadservices.make_download(user2.id, udf2.id, "path/file", "http://example.com") downloadservices.download_error(user2.id, d2.id, "download failed") # Finally, a failed download that will be outside the time window. d3 = downloadservices.make_download(user2.id, udf2.id, "path/file2", "http://example.com") downloadservices.download_error(user2.id, d3.id, "download failed") result = downloadservices.get_failed_downloads( start_date=d1.status_change_date, end_date=d3.status_change_date) download_ids = [download.id for download in result] self.assertTrue(d1.id in download_ids) self.assertTrue(d2.id in download_ids) self.assertFalse(d3.id in download_ids)
def test_get_failed_downloads(self): """Test the get_failed_downloads() function.""" # Create downloads udf1 = self.user.make_udf("~/path/name") d1 = downloadservices.make_download( self.user.id, udf1.id, "path/file", "http://example.com") downloadservices.download_error( self.user.id, d1.id, "download failed") user2 = services.make_storage_user("user2", 10 * 23) udf2 = user2.make_udf("~/path/name") d2 = downloadservices.make_download( user2.id, udf2.id, "path/file", "http://example.com") downloadservices.download_error(user2.id, d2.id, "download failed") # Finally, a failed download that will be outside the time window. d3 = downloadservices.make_download( user2.id, udf2.id, "path/file2", "http://example.com") downloadservices.download_error(user2.id, d3.id, "download failed") result = downloadservices.get_failed_downloads( start_date=d1.status_change_date, end_date=d3.status_change_date) download_ids = [download.id for download in result] self.assertTrue(d1.id in download_ids) self.assertTrue(d2.id in download_ids) self.assertFalse(d3.id in download_ids)
def make_user(self, username=None, **kwargs): if username is None: username = self.factory.get_unique_string() return services.make_storage_user(username=username, **kwargs)
def _make_users(self): """Create users for tests.""" usernames = ['bob', 'bobby', 'inez', 'juan', 'tim'] for name in usernames: services.make_storage_user( username=name, max_storage_bytes=2 ** 30)
def _make_users(self): """Create users for tests.""" usernames = ['bob', 'bobby', 'inez', 'juan', 'tim'] for name in usernames: services.make_storage_user(username=name, max_storage_bytes=2**30)
def setUp(self): """Setup for testing.""" # make sure we start with clean state yield super(TestShutdown, self).setUp() # since storageusers are not automatically created, we need to create self.usr0 = make_storage_user(u"dummy", 2 ** 20)
def setUp(self): """Setup for testing.""" # make sure we start with clean state yield super(TestShutdown, self).setUp() # since storageusers are not automatically created, we need to create self.usr0 = make_storage_user(u"dummy", 2**20)