Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't change directory #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions datadownloader/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ def _get_datadump_bin(self):
return 'datadump'

def _dump_media(self):
return [settings.MEDIA_ROOT.replace("%s/" % os.getcwd(), ''), ]
return [
settings.MEDIA_ROOT,
]

def _dump_db(self):
self._clean_dumps_path()
subprocess.check_output(self._get_datadump_bin())
dump_path = os.path.join(settings.BASE_DIR, 'dumps')
return [dump_path.replace("%s/" % os.getcwd(), ''), ]
return [dump_path]

def _clean_dumps_path(self):
dumps_path = os.path.join(settings.BASE_DIR, 'dumps')
Expand All @@ -84,8 +86,6 @@ def _clean_dumps_path(self):
os.mkdir(dumps_path)

def create(self):
# be sure to be in project root folder
os.chdir(settings.BASE_DIR)
folders = []
if self.data_type == 'db':
folders.extend(self._dump_db())
Expand All @@ -97,7 +97,8 @@ def create(self):

with tarfile.open(self.path, "w:gz") as tar:
for folder in folders:
tar.add(folder)
archive_name = folder.replace(settings.BASE_DIR, '').lstrip('/')
tar.add(folder, archive_name)

def destroy(self):
os.remove(self.path)
13 changes: 8 additions & 5 deletions datadownloader/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,16 @@ def test_create(self):
dump.create()
binary_call = dump._get_datadump_bin()
sp.check_output.assert_called_once_with(binary_call)
media_path = settings.MEDIA_ROOT.replace("%s/" % os.getcwd(), '')
db_path = os.path.join(settings.BASE_DIR,
'dumps').replace("%s/" % os.getcwd(), '')
media_path = settings.MEDIA_ROOT
media_name = 'medias'

db_path = os.path.join(settings.BASE_DIR, 'dumps')
db_name = 'dumps'

tf.assert_has_calls([
mock.call.open(expected_dump_path, 'w:gz'),
mock.call.open().__enter__(),
mock.call.open().__enter__().add(media_path),
mock.call.open().__enter__().add(db_path),
mock.call.open().__enter__().add(media_path, media_name),
mock.call.open().__enter__().add(db_path, db_name),
mock.call.open().__exit__(None, None, None),
])