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

Make BW the default front end #1704

Merged
merged 17 commits into from
Oct 30, 2023
Merged
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
4 changes: 2 additions & 2 deletions accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,8 @@ def get_users(self, username_or_email):
return (u for u in active_users)

def save(self, domain_override=None,
subject_template_name='registration/password_reset_subject.txt',
email_template_name='registration/password_reset_email.html',
subject_template_name='emails/password_reset_subject.txt',
email_template_name='emails/password_reset_email.html',
use_https=False, token_generator=default_token_generator,
from_email=None, request=None, html_email_template_name=None,
extra_email_context=None):
Expand Down
10 changes: 5 additions & 5 deletions accounts/tests/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,19 @@ def test_handle_uploaded_image(self):
def test_edit_user_profile(self):
user = User.objects.create_user("testuser")
self.client.force_login(user)
self.client.post("/home/edit/", {
resp = self.client.post("/home/edit/", {
'profile-home_page': 'http://www.example.com/',
'profile-username': 'testuser',
'profile-about': 'About test text',
'profile-signature': 'Signature test text',
'profile-not_shown_in_online_users_list': True,
'profile-ui_theme_preference': 'd',
})

user = User.objects.select_related('profile').get(username="testuser")
self.assertEqual(user.profile.home_page, 'http://www.example.com/')
self.assertEqual(user.profile.about, 'About test text')
self.assertEqual(user.profile.signature, 'Signature test text')
self.assertEqual(user.profile.not_shown_in_online_users_list, True)
self.assertEqual(user.profile.ui_theme_preference, 'd')

# Now we change the username the maximum allowed times
for i in range(settings.USERNAME_CHANGE_MAX_TIMES):
Expand All @@ -119,7 +119,7 @@ def test_edit_user_profile(self):
'profile-username': 'testuser%d' % i,
'profile-about': 'About test text',
'profile-signature': 'Signature test text',
'profile-not_shown_in_online_users_list': True,
'profile-ui_theme_preference': 'd',
})

user.refresh_from_db()
Expand All @@ -133,7 +133,7 @@ def test_edit_user_profile(self):
'profile-username': 'testuser-error',
'profile-about': 'About test text',
'profile-signature': 'Signature test text',
'profile-not_shown_in_online_users_list': True,
'profile-ui_theme_preference': 'd',
})
user.refresh_from_db()
self.assertEqual(user.old_usernames.count(), settings.USERNAME_CHANGE_MAX_TIMES)
Expand Down
102 changes: 15 additions & 87 deletions accounts/tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from tags.models import Tag
from utils.filesystem import File
from utils.test_helpers import create_test_files, override_uploads_path_with_temp_directory, \
override_csv_path_with_temp_directory, create_user_and_sounds, test_using_bw_ui
override_csv_path_with_temp_directory, create_user_and_sounds


class UserUploadAndDescribeSounds(TestCase):
Expand Down Expand Up @@ -71,110 +71,41 @@ def test_select_uploaded_files_to_describe(self):
create_test_files(filenames, user_upload_path)

# Check that files are displayed in the template
resp = self.client.get('/home/describe/')
resp = self.client.get(reverse('accounts-manage-sounds', args=['pending_description']))
self.assertEqual(resp.status_code, 200)
self.assertListEqual(sorted([os.path.basename(f.full_path) for f in resp.context['file_structure'].children]), sorted(filenames))

# Selecting one file redirects to /home/describe/sounds/
sounds_to_describe_idx = [0]
resp = self.client.post('/home/describe/', {
'describe': ['Describe selected files'],
resp = self.client.post(reverse('accounts-manage-sounds', args=['pending_description']), {
'describe': 'describe',
'sound-files': [f'file{idx}' for idx in sounds_to_describe_idx], # Note this is not the filename but the value of the "select" option
})
self.assertRedirects(resp, '/home/describe/sounds/')
self.assertRedirects(resp, reverse('accounts-describe-sounds'))
self.assertEqual(self.client.session['len_original_describe_edit_sounds'], len(sounds_to_describe_idx))
self.assertListEqual(sorted([os.path.basename(f.full_path) for f in self.client.session['describe_sounds']]), sorted([filenames[idx] for idx in sounds_to_describe_idx]))

# Selecting multiple file redirects to /home/describe/license/
sounds_to_describe_idx = [1, 2, 3]
resp = self.client.post('/home/describe/', {
'describe': ['Describe selected files'],
resp = self.client.post(reverse('accounts-manage-sounds', args=['pending_description']), {
'describe': 'describe',
'sound-files': [f'file{idx}' for idx in sounds_to_describe_idx], # Note this is not the filename but the value of the "select" option
})
self.assertRedirects(resp, '/home/describe/license/')
self.assertRedirects(resp, reverse('accounts-describe-license'))
self.assertEqual(self.client.session['len_original_describe_edit_sounds'], len(sounds_to_describe_idx))
self.assertListEqual(sorted([os.path.basename(f.full_path) for f in self.client.session['describe_sounds']]), sorted([filenames[idx] for idx in sounds_to_describe_idx]))

# Selecting files to delete, redirect to delete confirmation
# Selecting files to delete, delete the files
sounds_to_delete_idx = [1, 2, 3]
resp = self.client.post('/home/describe/', {
'delete': ['Delete selected files'],
resp = self.client.post(reverse('accounts-manage-sounds', args=['pending_description']), {
'delete_confirm': 'delete_confirm',
'sound-files': [f'file{idx}' for idx in sounds_to_delete_idx], # Note this is not the filename but the value of the "select" option,
})
self.assertEqual(resp.status_code, 200)
self.assertListEqual(sorted(resp.context['filenames']), sorted([filenames[idx] for idx in sounds_to_describe_idx]))

# Selecting confirmation of files to delete
resp = self.client.post('/home/describe/', {
'delete_confirm': ['delete_confirm'],
'sound-files': [f'file{idx}' for idx in sounds_to_delete_idx], # Note this is not the filename but the value of the "select" option,
})
self.assertRedirects(resp, '/home/describe/')
self.assertRedirects(resp, reverse('accounts-manage-sounds', args=['pending_description']))
self.assertEqual(len(os.listdir(user_upload_path)), len(filenames) - len(sounds_to_delete_idx))

@override_uploads_path_with_temp_directory
def test_describe_selected_files(self):
# Create audio files
filenames = ['file1.wav', 'filè2.wav']
user = User.objects.create_user("testuser", password="testpass")
existing_pack = Pack.objects.create(user=user, name="existing pack")
# Set is_whitelisted because this will trigger change_moderation_state after creating sound and make
# the test more complete
user.profile.is_whitelisted = True
user.profile.save()
self.client.force_login(user)
user_upload_path = settings.UPLOADS_PATH + '/%i/' % user.id
os.makedirs(user_upload_path, exist_ok=True)
create_test_files(filenames, user_upload_path)

# Set license and pack data in session
session = self.client.session
session['describe_license'] = License.objects.all()[0]
session['describe_pack'] = False
session['describe_sounds'] = [File(1, filenames[0], user_upload_path + filenames[0], False),
File(2, filenames[1], user_upload_path + filenames[1], False)]
session.save()

# Post description information
resp = self.client.post('/home/describe/sounds/', {
'submit': ['Submit and continue'],
'0-lat': ['46.31658418182218'],
'0-lon': ['3.515625'],
'0-zoom': ['16'],
'0-tags': ['testtag1 testtag2 testtag3'],
'0-pack': [f'{existing_pack.id}'],
'0-license': ['3'],
'0-description': ['a test description for the sound file'],
'0-new_pack': [''],
'0-name': [filenames[0]],
'1-license': ['3'],
'1-description': ['another test description'],
'1-lat': [''],
'1-pack': [''],
'1-lon': [''],
'1-name': [filenames[1]],
'1-new_pack': ['Name of a new pack'],
'1-zoom': [''],
'1-tags': ['testtag1 testtag4 testtag5'],
}, follow=True)

# Check that post redirected to first describe page with confirmation message on sounds described
self.assertRedirects(resp, '/home/describe/')
self.assertEqual('You have described all the selected files' in list(resp.context['messages'])[2].message, True)

# Check that sounds have been created along with related tags, geotags and packs
self.assertEqual(user.sounds.all().count(), 2)
self.assertListEqual(
sorted(list(user.sounds.values_list('original_filename', flat=True))),
sorted([f for f in filenames]))
self.assertEqual(Pack.objects.filter(name='Name of a new pack').exists(), True)
self.assertEqual(Tag.objects.filter(name__contains="testtag").count(), 5)
self.assertNotEqual(user.sounds.get(original_filename=filenames[0]).geotag, None)

@override_uploads_path_with_temp_directory
def test_describe_selected_files_bw(self):
# NOTE: because BW ui uses different views/templates for sound description, we write a complementary
# test for it

# Create audio files
filenames = ['file1.wav', 'filè2.wav']
Expand All @@ -196,9 +127,6 @@ def test_describe_selected_files_bw(self):
File(2, filenames[1], user_upload_path + filenames[1], False)]
session.save()

# Set BW frontend in session
test_using_bw_ui(self)

# Post description information
resp = self.client.post('/home/describe/sounds/', {
'0-lat': ['46.31658418182218'],
Expand Down Expand Up @@ -277,7 +205,7 @@ def test_upload_csv(self, submit_job):
# Test successful file upload and redirect
filename = "file.csv"
f = SimpleUploadedFile(filename, b"file_content")
resp = self.client.post(reverse('accounts-describe'), {'bulk-csv_file': f})
resp = self.client.post(reverse('accounts-manage-sounds', args=['pending_description']), {'bulk-csv_file': f})
bulk = BulkUploadProgress.objects.get(user=user)
self.assertRedirects(resp, reverse('accounts-bulk-describe', args=[bulk.id]))

Expand Down Expand Up @@ -310,7 +238,7 @@ def test_bulk_describe_view_permissions(self):
# Now user is not allowed to load the page as user.profile.can_do_bulk_upload() returns False
self.client.force_login(user)
resp = self.client.get(reverse('accounts-bulk-describe', args=[bulk.id]), follow=True)
self.assertRedirects(resp, reverse('accounts-home'))
self.assertRedirects(resp, reverse('accounts-manage-sounds', args=['pending_description']))
self.assertContains(resp, 'Your user does not have permission to use the bulk describe')

@override_settings(BULK_UPLOAD_MIN_SOUNDS=0)
Expand All @@ -334,7 +262,7 @@ def test_bulk_describe_state_finished_validation(self, submit_job):

# Test that chosing option to delete existing BulkUploadProgress really does it
resp = self.client.post(reverse('accounts-bulk-describe', args=[bulk.id]), data={'delete': True})
self.assertRedirects(resp, reverse('accounts-describe')) # Redirects to describe page after delete
self.assertRedirects(resp, reverse('accounts-manage-sounds', args=['pending_description'])) # Redirects to describe page after delete
self.assertEqual(BulkUploadProgress.objects.filter(user=user).count(), 0)

# Test that chosing option to start describing files triggers bulk describe gearmnan job
Expand Down
Loading
Loading