Skip to content

Commit

Permalink
fix deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
hpk42 committed Nov 12, 2018
1 parent c15436f commit 06e54bb
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
16 changes: 10 additions & 6 deletions ccfilestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,13 @@ def writer(self, user):

def delete_user(self, user):
user_fn = self._get_userlist_path(user)
for key in open(user_fn):
key = key.strip()
if not key:
continue
os.remove(self._get_keypath(key))
os.remove(user_fn)
try:
for key in open(user_fn):
key = key.strip()
if not key:
continue
os.remove(self._get_keypath(key))
except IOError:
pass
else:
os.remove(user_fn)
13 changes: 7 additions & 6 deletions cchttpserver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.6.0.dev1"
__version__ = "0.6.0"

from flask import Flask, request
from flask_httpauth import HTTPBasicAuth
Expand All @@ -11,14 +11,15 @@ def create_app(test_config=None):

if test_config is None:
# load the instance config, if it exists, when not testing
app.config.from_pyfile('config_cchttpserver.py')
app.config.from_pyfile('config.py')
print (app.config)
else:
# load the test config if passed in
app.config['users'] = test_config['users']
app.config['dbdir'] = test_config['dbdir']
app.config['USERS'] = test_config['users']
app.config['DBDIR'] = test_config['dbdir']

users = app.config['users']
dbdir = app.config['dbdir']
users = app.config['USERS']
dbdir = app.config['DBDIR']
store = CCFileStore(dbdir)

@auth.get_password
Expand Down
4 changes: 2 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

# users is a mapping of login-usernames to cleartext-passwords
users = {
USERS = {
'test1': 'password1',
}

# dbdir is the directory where all blockserver state is stored
dbdir = '/tmp/cchttpserver_dir'
DBDIR = '/tmp/cchttpserver_dir'
2 changes: 2 additions & 0 deletions test_ccfilestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ def test_delete_user(self, ds):
ds.delete_user('user1')
assert ds.get('a1') is None
assert ds.get_user_keys('user1') == []
ds.delete_user("user1")
assert ds.get_user_keys('user1') == []
5 changes: 4 additions & 1 deletion test_cchttpserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_put_invalid_login(app):
assert r.status_code == 401


def test_put_and_get(app):
def test_put_and_get_and_delete(app):
for data in (b"123", b"456"):
creds = base64.b64encode(b'a:pass').decode('utf-8')
key = base64.b64encode(data).decode('utf-8')
Expand All @@ -49,6 +49,9 @@ def test_put_and_get(app):
r = app.get('/' + key)
assert r.status_code == 404

r = app.delete('/a/', headers={'Authorization': 'Basic ' + creds})
assert r.status_code == 200


def test_indicate_repetition(app):
data = b"123"
Expand Down

0 comments on commit 06e54bb

Please sign in to comment.