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

Commit cde72c8

Browse files
committed
Merge pull request #366 from ialja/master
Added support for EU French colonies and more country related tests
2 parents 8174e45 + c058a2b commit cde72c8

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
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/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()

0 commit comments

Comments
 (0)