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

144 pasikeitusių nuorodų peradresavimas #280

Open
wants to merge 5 commits into
base: devel
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
196 changes: 195 additions & 1 deletion tests/compat/test_redirections.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from django_webtest import DjangoTestApp
from django.contrib.redirects.models import Redirect

from vitrina.users.models import User

@pytest.mark.django_db
def test_redirection_doesnt_exist(app: DjangoTestApp):
Expand All @@ -28,3 +28,197 @@ def test_redirection_exists_no_new_path(app: DjangoTestApp):
)
response = app.get('/labas/', expect_errors=True)
assert response.status_code == 410


@pytest.mark.django_db
def test_dataset_has_new_path(app: DjangoTestApp):
Redirect.objects.create(
site_id=1,
old_path='/dataset/1/',
new_path='/datasets/1/',
)
response = app.get('/dataset/1/')
assert response.status_code == 301 and response.location == '/datasets/1/'

@pytest.mark.django_db
def test_usecases_examples_has_new_path(app: DjangoTestApp):
Redirect.objects.create(
site_id=1,
old_path='/usecases/examples/',
new_path='/projects/',
)
response = app.get('/usecases/examples/')
assert response.status_code == 301 and response.location == '/projects/'

@pytest.mark.django_db
def test_usecases_applications_has_new_path(app: DjangoTestApp):
Redirect.objects.create(
site_id=1,
old_path='/usecases/applications/',
new_path='/projects/',
)
response = app.get('/usecases/applications/')
assert response.status_code == 301 and response.location == '/projects/'

@pytest.mark.django_db
def test_usecase_has_new_path(app: DjangoTestApp):
user1 = User.objects.create_user(email='user1@test.com', password='12345')
app.set_user(user1)
Redirect.objects.create(
site_id=1,
old_path='/usecase/',
new_path='/projects/add/',
)
response = app.get('/usecase/')
assert response.status_code == 301 and response.location == '/projects/add/'

@pytest.mark.django_db
def test_policy_has_new_path(app: DjangoTestApp):
Redirect.objects.create(
site_id=1,
old_path='/page/regulation',
new_path='/more/regulation/',
)
response = app.get('/page/regulation/')
assert response.status_code == 301 and response.location == '/more/regulation/'


@pytest.mark.django_db
def test_links_have_new_path(app: DjangoTestApp):
Redirect.objects.create(
site_id=1,
old_path='/page/nuorodos',
new_path='/more/nuorodos/',
)
response = app.get('/page/nuorodos/')
assert response.status_code == 301 and response.location == '/more/nuorodos/'

@pytest.mark.django_db
def test_notions_have_new_path(app: DjangoTestApp):
Redirect.objects.create(
site_id=1,
old_path='/page/savokos',
new_path='/more/savokos/',
)
response = app.get('/page/savokos/')
assert response.status_code == 301 and response.location == '/more/savokos/'

@pytest.mark.django_db
def test_about_has_new_path(app: DjangoTestApp):
Redirect.objects.create(
site_id=1,
old_path='/page/apie',
new_path='/more/apie/',
)
response = app.get('/page/apie/')
assert response.status_code == 301 and response.location == '/more/apie/'

@pytest.mark.django_db
def test_contacts_has_new_path(app: DjangoTestApp):
Redirect.objects.create(
site_id=1,
old_path='/page/contacts',
new_path='/more/contacts/',
)
response = app.get('/page/contacts/')
assert response.status_code == 301 and response.location == '/more/contacts/'

@pytest.mark.django_db
def test_other_has_new_path(app: DjangoTestApp):
Redirect.objects.create(
site_id=1,
old_path='/other',
new_path='/more/other/',
)
response = app.get('/other/')
assert response.status_code == 301 and response.location == '/more/other/'

@pytest.mark.django_db
def test_reports_has_new_path(app: DjangoTestApp):
Redirect.objects.create(
site_id=1,
old_path='/reports',
new_path='/more/reports/',
)
response = app.get('/reports/')
assert response.status_code == 301 and response.location == '/more/reports/'

@pytest.mark.django_db
def test_templates_has_new_path(app: DjangoTestApp):
Redirect.objects.create(
site_id=1,
old_path='/page/templates',
new_path='/more/templates/',
)
response = app.get('/page/templates/')
assert response.status_code == 301 and response.location == '/more/templates/'

@pytest.mark.django_db
def test_storage_has_new_path(app: DjangoTestApp):
Redirect.objects.create(
site_id=1,
old_path='/page/saugykla',
new_path='/opening-tips/saugykla/',
)
response = app.get('/page/saugykla/')
assert response.status_code == 301 and response.location == '/opening-tips/saugykla/'

@pytest.mark.django_db
def test_guide_has_new_path(app: DjangoTestApp):
Redirect.objects.create(
site_id=1,
old_path='/page/vadovas',
new_path='/opening-tips/vadovas/',
)
response = app.get('/page/vadovas/')
assert response.status_code == 301 and response.location == '/opening-tips/vadovas/'

@pytest.mark.django_db
def test_guide_has_new_path(app: DjangoTestApp):
Redirect.objects.create(
site_id=1,
old_path='/page/vadovas',
new_path='/opening-tips/vadovas/',
)
response = app.get('/page/vadovas/')
assert response.status_code == 301 and response.location == '/opening-tips/vadovas/'

@pytest.mark.django_db
def test_summary_has_new_path(app: DjangoTestApp):
Redirect.objects.create(
site_id=1,
old_path='/page/aprasas',
new_path='/opening-tips/aprasas/',
)
response = app.get('/page/aprasas/')
assert response.status_code == 301 and response.location == '/opening-tips/aprasas/'

@pytest.mark.django_db
def test_data_opening_tools_have_new_path(app: DjangoTestApp):
Redirect.objects.create(
site_id=1,
old_path='/page/data-opening-tools',
new_path='/opening-tips/data-opening-tools/',
)
response = app.get('/page/data-opening-tools/')
assert response.status_code == 301 and response.location == '/opening-tips/data-opening-tools/'

@pytest.mark.django_db
def test_learning_material_has_new_path(app: DjangoTestApp):
Redirect.objects.create(
site_id=1,
old_path='/opening/learningmaterial',
new_path='/opening-tips/opening/learningmaterial/',
)
response = app.get('/opening/learningmaterial/')
assert response.status_code == 301 and response.location == '/opening-tips/opening/learningmaterial/'

@pytest.mark.django_db
def test_faq_has_new_path(app: DjangoTestApp):
Redirect.objects.create(
site_id=1,
old_path='/page/opening_faq',
new_path='/opening-tips/opening_faq/',
)
response = app.get('/page/opening_faq/')
assert response.status_code == 301 and response.location == '/opening-tips/opening_faq/'
10 changes: 5 additions & 5 deletions tests/datasets/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ def test_public_manager_filtering(app: DjangoTestApp):
def test_change_form_no_login(app: DjangoTestApp):
org = OrganizationFactory()
dataset = DatasetFactory(organization=org)
response = app.get(reverse('dataset-change', kwargs={'pk': dataset.id}))
response = app.get(reverse('dataset-update', kwargs={'pk': dataset.id}))
assert response.status_code == 302
assert settings.LOGIN_URL in response.location

Expand All @@ -565,7 +565,7 @@ def test_change_form_wrong_login(app: DjangoTestApp):
dataset = DatasetFactory(organization=org)
user = User.objects.create_user(email="test@test.com", password="test123")
app.set_user(user)
response = app.get(reverse('dataset-change', kwargs={'pk': dataset.id}))
response = app.get(reverse('dataset-update', kwargs={'pk': dataset.id}))
assert response.status_code == 302
assert str(dataset.id) in response.location

Expand All @@ -588,7 +588,7 @@ def test_change_form_correct_login(app: DjangoTestApp):
user = UserFactory(is_staff=True)
app.set_user(user)
dataset.manager = user
form = app.get(reverse('dataset-change', kwargs={'pk': dataset.id})).forms['dataset-form']
form = app.get(reverse('dataset-update', kwargs={'pk': dataset.id})).forms['dataset-form']
form['title'] = 'Edited title'
form['description'] = 'edited dataset description'
resp = form.submit()
Expand All @@ -607,7 +607,7 @@ def test_group_change_form_correct_login(app: DjangoTestApp):
dataset = DatasetFactory()
user = UserFactory(is_staff=True)
app.set_user(user)
form = app.get(reverse('dataset-change', kwargs={'pk': dataset.id})).forms['dataset-form']
form = app.get(reverse('dataset-update', kwargs={'pk': dataset.id})).forms['dataset-form']
form['groups'] = ['1']
resp = form.submit()
dataset.refresh_from_db()
Expand Down Expand Up @@ -748,7 +748,7 @@ def test_dataset_history_view_with_permission(app: DjangoTestApp):
dataset = DatasetFactory(organization=user.organization)
app.set_user(user)

form = app.get(reverse("dataset-change", args=[dataset.pk])).forms['dataset-form']
form = app.get(reverse("dataset-update", args=[dataset.pk])).forms['dataset-form']
form['title'] = "Updated title"
form['description'] = "Updated description"
resp = form.submit().follow()
Expand Down
10 changes: 5 additions & 5 deletions tests/resources/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_change_form_wrong_login(app: DjangoTestApp):
resource = DatasetDistributionFactory()
user = User.objects.create_user(email="test@test.com", password="test123")
app.set_user(user)
response = app.get(reverse('resource-change', kwargs={'pk': resource.id}))
response = app.get(reverse('resource-update', kwargs={'pk': resource.id}))
assert response.status_code == 302
assert str(resource.dataset_id) in response.location

Expand All @@ -25,7 +25,7 @@ def test_change_form_correct_login(app: DjangoTestApp):
resource = DatasetDistributionFactory(title='base title', description='base description')
user = UserFactory(is_staff=True, organization=resource.dataset.organization)
app.set_user(user)
form = app.get(reverse('resource-change', kwargs={'pk': resource.id})).forms['resource-form']
form = app.get(reverse('resource-update', kwargs={'pk': resource.id})).forms['resource-form']
form['title'] = "Edited title"
form['description'] = "edited resource description"
resp = form.submit()
Expand Down Expand Up @@ -95,7 +95,7 @@ def test_click_add_button(app: DjangoTestApp):
@pytest.mark.django_db
def test_delete_no_login(app: DjangoTestApp):
resource = DatasetDistributionFactory()
response = app.get(reverse('resource-delete', kwargs={'pk': resource.id}))
response = app.get(reverse('resource-remove', kwargs={'pk': resource.id}))
assert response.status_code == 302
assert settings.LOGIN_URL in response.location

Expand All @@ -105,7 +105,7 @@ def test_delete_wrong_login(app: DjangoTestApp):
user = UserFactory()
app.set_user(user)
resource = DatasetDistributionFactory()
response = app.get(reverse('resource-delete', kwargs={'pk': resource.id}))
response = app.get(reverse('resource-remove', kwargs={'pk': resource.id}))
assert response.status_code == 302
assert str(resource.dataset_id) in response.location

Expand All @@ -115,7 +115,7 @@ def test_delete_correct_login(app: DjangoTestApp):
resource = DatasetDistributionFactory(title='base title', description='base description')
user = UserFactory(is_staff=True, organization=resource.dataset.organization)
app.set_user(user)
resp = app.get(reverse('resource-delete', kwargs={'pk': resource.pk}))
resp = app.get(reverse('resource-remove', kwargs={'pk': resource.pk}))
assert resp.status_code == 302
assert DatasetDistribution.objects.filter().count() == 0

Expand Down
6 changes: 3 additions & 3 deletions tests/users/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def test_profile_view_wrong_login(app: DjangoTestApp, user: User):

@pytest.mark.django_db
def test_profile_edit_form_no_login(app: DjangoTestApp, user: User):
resp = app.get(reverse('user-profile-change', kwargs={'pk': '1'}))
resp = app.get(reverse('user-profile-update', kwargs={'pk': '1'}))
assert resp.status_code == 302
assert resp.location == settings.LOGIN_URL

Expand All @@ -158,7 +158,7 @@ def test_profile_edit_form_no_login(app: DjangoTestApp, user: User):
def test_profile_edit_form_wrong_login(app: DjangoTestApp, user: User):
app.set_user(user)
temp_user = User.objects.create_user(email="testas@testas.com", password="testas123")
resp = app.get(reverse('user-profile-change', kwargs={'pk': temp_user.pk}))
resp = app.get(reverse('user-profile-update', kwargs={'pk': temp_user.pk}))
assert resp.status_code == 302
assert str(user.pk) in resp.location

Expand All @@ -167,7 +167,7 @@ def test_profile_edit_form_wrong_login(app: DjangoTestApp, user: User):
def test_profile_edit_form_correct_login(app: DjangoTestApp):
user = User.objects.create_user(email="testas@testas.com", password="testas123")
app.set_user(user)
form = app.get(reverse('user-profile-change', kwargs={'pk': user.pk})).forms['user-profile-form']
form = app.get(reverse('user-profile-update', kwargs={'pk': user.pk})).forms['user-profile-form']
form['phone'] = '12341234'
resp = form.submit()
user.refresh_from_db()
Expand Down
15 changes: 15 additions & 0 deletions vitrina/cms/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.urls import path, include
from djangocms_blog.settings import get_setting
from django.http.response import HttpResponsePermanentRedirect

from vitrina.cms.views import PolicyView, PostDetailView, LearningMaterialDetailView, SparqlView, ReportDetailView

Expand Down Expand Up @@ -27,6 +28,20 @@ def get_urls():
path('opening/learningmaterial/<int:pk>/', LearningMaterialDetailView.as_view(), name='learning-material-detail'),
path('reports/<int:pk>/', ReportDetailView.as_view(), name='report-detail'),
path('sparql/', SparqlView.as_view(), name='sparql'),
path('page/regulation/', lambda request: HttpResponsePermanentRedirect('/more/regulation/')),
path('page/nuorodos/', lambda request: HttpResponsePermanentRedirect('/more/nuorodos/')),
path('page/savokos/', lambda request: HttpResponsePermanentRedirect('/more/savokos/')),
path('page/apie/', lambda request: HttpResponsePermanentRedirect('/more/apie/')),
path('page/contacts/', lambda request: HttpResponsePermanentRedirect('/more/contacts/')),
path('other/', lambda request: HttpResponsePermanentRedirect('/more/other/')),
path('reports/', lambda request: HttpResponsePermanentRedirect('/more/reports/')),
path('page/templates/', lambda request: HttpResponsePermanentRedirect('/more/templates/')),
path('page/saugykla/', lambda request: HttpResponsePermanentRedirect('/opening-tips/saugykla/')),
path('page/vadovas/', lambda request: HttpResponsePermanentRedirect('/opening-tips/vadovas/')),
path('page/aprasas/', lambda request: HttpResponsePermanentRedirect('/opening-tips/aprasas/')),
path('page/data-opening-tools/', lambda request: HttpResponsePermanentRedirect('/opening-tips/data-opening-tools/')),
path('opening/learningmaterial/', lambda request: HttpResponsePermanentRedirect('/opening-tips/opening/learningmaterial/')),
path('page/opening_faq/', lambda request: HttpResponsePermanentRedirect('/opening-tips/opening_faq/')),
# @GetMapping("/other")
# @GetMapping("/opening")
# @GetMapping("/opening/tips")
Expand Down
4 changes: 2 additions & 2 deletions vitrina/datasets/templates/vitrina/datasets/datatable.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@
{% endif %}
{% if can_add_resource %}
<td>
<a href="{%url 'resource-change' pk=r.id %}"
<a href="{%url 'resource-update' pk=r.id %}"
class="button is-link is-small is-pulled-right"
id="change_resource">{% translate "Redaguoti" %}</a>
</div>
</td>
<td>
<a href="{%url 'resource-delete' pk=r.id %}"
<a href="{%url 'resource-remove' pk=r.id %}"
onclick="return confirm('Ar jūs tikrai norite trinti šį šaltinį?')"
class="button is-link is-small is-pulled-right"
id="delete_resource">{% translate "Trinti" %}</a>
Expand Down
2 changes: 1 addition & 1 deletion vitrina/datasets/templates/vitrina/datasets/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ <h3 class="custom-title is-size-4-mobile no-margin-bottom">
</p>
{% if can_update_dataset %}
<div class="buttons is-right">
<a href="{%url 'dataset-change' pk=dataset.id %}" class="button is-primary is-normal m-t-md is-size-6-mobile" id="change_dataset">
<a href="{%url 'dataset-update' pk=dataset.id %}" class="button is-primary is-normal m-t-md is-size-6-mobile" id="change_dataset">
{% translate "Redaguoti rinkinį" %}
</a>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
{% translate "Redaguoti" %}
</a>
<a id="delete-member-{{ m.pk }}-btn" class="button is-danger is-small"
href="{% url 'dataset-representative-delete' dataset_id=dataset.pk pk=m.pk %}">
href="{% url 'dataset-representative-remove' dataset_id=dataset.pk pk=m.pk %}">
{% translate "Pašalinti" %}
</a>
</div>
Expand Down
Loading