Skip to content
This repository was archived by the owner on Sep 19, 2018. It is now read-only.

Commit 5a486f3

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 92ae5e4 + 2809cde commit 5a486f3

File tree

7 files changed

+126
-5
lines changed

7 files changed

+126
-5
lines changed

static/js/events.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ var Codeweek = window.Codeweek || {};
8080
document.getElementById("autocomplete").value = results[0].formatted_address;
8181
// the last item in the geocoder for latLng results array is the country
8282
var country = results.slice(-1)[0].address_components.slice(-1)[0].short_name;
83-
83+
var frenchColonies = ['MQ', 'GF', 'GP'] // Martinique, French Guiana, Guadeloupe
84+
if (frenchColonies.indexOf(country) >= 0) {
85+
country = 'FR';
86+
}
8487
updateCountrySelection(country);
8588
}
8689
});

web/templates/404.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% extends 'base.html' %}
2-
{% block title %}- Whoa, 500!{% endblock title %}
2+
{% block title %}- Whoa, 404!{% endblock title %}
33

44
{% block content %}
55
<div class="container">

web/tests/test_event_views.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,8 @@ def test_edit_event_with_image(admin_user, admin_client, db):
229229
response = admin_client.get(event.get_absolute_url())
230230
assert 'event_picture/ercchy' not in response.content
231231

232+
@pytest.mark.django_db
233+
def test_nonexistent_event(db, client):
234+
response = client.get(reverse('web.view_event', args=[1234, 'shouldnt-exist']))
235+
236+
assert response.status_code == 404

web/tests/test_events_processors.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from py.path import local
99

1010
from geoposition import Geoposition
11+
from web.processors.event import list_countries
1112

1213
from api.models.events import Event
1314
from api.models import UserProfile
@@ -389,11 +390,91 @@ def test_create_event_in_serbia(admin_user, db):
389390

390391
assert "RS" == test_event.country.code
391392

393+
394+
@pytest.mark.django_db
395+
def test_create_event_in_martinique_for_france(admin_user, db):
396+
event_data = {
397+
'audience': [3],
398+
'theme': [1,2],
399+
'contact_person': u'[email protected]',
400+
'country': u'FR',
401+
'description': u'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod\r\ntempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,\r\nquis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo\r\nconsequat. Duis aute irure dolor in reprehenderit in voluptate velit esse\r\ncillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non\r\nproident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
402+
'event_url': u'',
403+
'location': u'1011 Chemin rural No 8 Bis de Clemencin, Le Lamentin, Martinique',
404+
'organizer': u'RailsGirls Martinique',
405+
"creator": admin_user,
406+
'start_date': datetime.datetime.now(),
407+
'end_date': datetime.datetime.now() + datetime.timedelta(days=3, hours=3),
408+
'tags': [u'css', u'html', u'web'],
409+
'title': u'RailsGirls Martinique',
410+
}
411+
412+
test_event = create_or_update_event(event_id=None, **event_data)
413+
414+
assert "FR" == test_event.country.code
415+
416+
417+
@pytest.mark.django_db
418+
def test_create_event_in_each_listed_country(admin_user, db):
419+
all_countries = list_countries()
420+
421+
for country in all_countries[2:]:
422+
country_code = country[1]
423+
country_name = country[0]
424+
425+
event_data = {
426+
'audience': [3],
427+
'theme': [1,2],
428+
'contact_person': u'[email protected]',
429+
'country': country_code,
430+
'description': u'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod\r\ntempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,\r\nquis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo\r\nconsequat. Duis aute irure dolor in reprehenderit in voluptate velit esse\r\ncillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non\r\nproident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
431+
'event_url': u'',
432+
'location': country_name,
433+
'organizer': u'RailsGirls ' + country_name,
434+
"creator": admin_user,
435+
'start_date': datetime.datetime.now(),
436+
'end_date': datetime.datetime.now() + datetime.timedelta(days=3, hours=3),
437+
'tags': [u'css', u'html', u'web'],
438+
'title': u'RailsGirls ' + country_name,
439+
}
440+
441+
test_event = create_or_update_event(event_id=None, **event_data)
442+
443+
assert country_code == test_event.country.code
444+
445+
test_event.delete()
446+
447+
448+
def test_list_countries():
449+
# a function we use a lot to get all countries, so let's check it's returning expected results
450+
all_countries = list_countries()
451+
452+
# Austria should be the first country after two custom entries (All countries)
453+
assert "Austria" == all_countries[2][0]
454+
455+
# checking two random countries - our own and Kosovo, which is a special case
456+
assert ('Slovenia', 'SI') in all_countries
457+
assert ('Kosovo', 'XK') in all_countries
458+
459+
# United Kingdom should be last
460+
assert "United Kingdom" == all_countries[-1][0]
461+
462+
# if listing works, results are tuples ('country_name', 'country_code')
463+
# country_code should be a string with 2 characters
464+
for country in all_countries[2:]:
465+
assert len(country[1]) == 2
466+
467+
392468
@pytest.mark.django_db
393469
def test_scoreboard_counter(admin_user, db):
394470

395471
initial_counter = count_approved_events_for_country()
396472

473+
# extra check to make sure the number of results matches
474+
# the number of listed countries minus two custom entries
475+
all_countries = list_countries()
476+
assert len(initial_counter) == len(all_countries[2:])
477+
397478
counted_events_before = 0
398479

399480
for country in initial_counter:
@@ -437,16 +518,20 @@ def test_scoreboard_counter(admin_user, db):
437518
new_counter = count_approved_events_for_country()
438519

439520
counted_events_after = 0
521+
country_score_after = 0
440522

441523
for country in new_counter:
442524
if country['country_code'] == 'SI':
443525
counted_events_after = country['events']
526+
country_score_after = country['score']
444527

445528
# An extra check with a direct DB query
446529
counted_events_query = Event.objects.filter(status='APPROVED').filter(country='SI').count()
447530

448531
assert counted_events_after == counted_events_before + 1
449532
assert counted_events_after == counted_events_query
450533

534+
assert country_score_after > 0
535+
451536
test_approved_event.delete()
452537
test_pending_event.delete()

web/tests/test_site.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# -*- coding: utf-8 -*-
2+
import pytest
3+
4+
@pytest.mark.django_db
5+
def test_unknown_URL(db, client):
6+
response = client.get('/bar-foo/')
7+
8+
assert response.status_code == 404
9+
10+
@pytest.mark.django_db
11+
def test_country_redirect(db, client):
12+
# Test without a slash in the end
13+
response = client.get('/AB')
14+
15+
assert response.status_code == 301
16+
assert response['Location'][-4:] == '/#AB'
17+
18+
# and with one
19+
response = client.get('/AB/')
20+
21+
assert response.status_code == 301
22+
assert response['Location'][-4:] == '/#AB'

web/urls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from django.conf.urls import url
33
from django.contrib import admin
44
from django.views.generic import TemplateView
5+
from django.views.generic import RedirectView
56

67
admin.autodiscover()
78

@@ -23,6 +24,5 @@
2324
url(r'^scoreboard/$', 'events.scoreboard', name='web.scoreboard'),
2425
url(r'^change_status/(?P<event_id>\d+)/$', 'events.change_status', name='web.change_status'),
2526
url(r'^reject_status/(?P<event_id>\d+)/$', 'events.reject_status', name='web.reject_status'),
26-
# Note: do not place any url after this one of it will not work
27-
url(r'^(?P<country_code>\w+)/$', 'events.index', name='web.index'),
27+
url(r'^(?P<country_code>[A-Z][A-Z])/?$', RedirectView.as_view(url = '/#%(country_code)s')),
2828
)

web/views/events.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
from web.decorators.events import can_moderate_event
3939
from web.decorators.events import is_ambassador
4040

41+
from django.http import Http404
42+
from django.core.exceptions import ObjectDoesNotExist
4143

4244
"""
4345
Do not Query the database directly from te view.
@@ -188,7 +190,11 @@ def view_event_by_country(request, country_code):
188190

189191

190192
def view_event(request, event_id, slug):
191-
event = get_event_by_id(event_id)
193+
try:
194+
event = get_event_by_id(event_id)
195+
except ObjectDoesNotExist as e:
196+
raise Http404
197+
192198
next_event = get_next_or_previous(event, country_code=event.country)
193199
nearby = get_nearby_events(event, limit=4)
194200

0 commit comments

Comments
 (0)