From 32e6d2f47fc887a41f15634b1728240c1169b031 Mon Sep 17 00:00:00 2001 From: Alja Isakovic Date: Wed, 1 Oct 2014 21:33:41 +0200 Subject: [PATCH 1/2] Making sure Martinique, French Guiana, Guadeloupe count as France --- static/js/events.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/static/js/events.js b/static/js/events.js index 5e8a7e05..e678d63d 100644 --- a/static/js/events.js +++ b/static/js/events.js @@ -80,7 +80,10 @@ var Codeweek = window.Codeweek || {}; document.getElementById("autocomplete").value = results[0].formatted_address; // the last item in the geocoder for latLng results array is the country var country = results.slice(-1)[0].address_components.slice(-1)[0].short_name; - + var frenchColonies = ['MQ', 'GF', 'GP'] // Martinique, French Guiana, Guadeloupe + if (frenchColonies.indexOf(country) >= 0) { + country = 'FR'; + } updateCountrySelection(country); } }); From c058a2b66a7b4c3247c264c87f9f8ea25afb9d9b Mon Sep 17 00:00:00 2001 From: Alja Isakovic Date: Wed, 1 Oct 2014 21:34:38 +0200 Subject: [PATCH 2/2] more tests for events in countries, scoreboard and listing countries --- web/tests/test_events_processors.py | 85 +++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/web/tests/test_events_processors.py b/web/tests/test_events_processors.py index 0ea90353..1dc28b7a 100644 --- a/web/tests/test_events_processors.py +++ b/web/tests/test_events_processors.py @@ -8,6 +8,7 @@ from py.path import local from geoposition import Geoposition +from web.processors.event import list_countries from api.models.events import Event from api.models import UserProfile @@ -389,11 +390,91 @@ def test_create_event_in_serbia(admin_user, db): assert "RS" == test_event.country.code + +@pytest.mark.django_db +def test_create_event_in_martinique_for_france(admin_user, db): + event_data = { + 'audience': [3], + 'theme': [1,2], + 'contact_person': u'test@example.com', + 'country': u'FR', + '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.', + 'event_url': u'', + 'location': u'1011 Chemin rural No 8 Bis de Clemencin, Le Lamentin, Martinique', + 'organizer': u'RailsGirls Martinique', + "creator": admin_user, + 'start_date': datetime.datetime.now(), + 'end_date': datetime.datetime.now() + datetime.timedelta(days=3, hours=3), + 'tags': [u'css', u'html', u'web'], + 'title': u'RailsGirls Martinique', + } + + test_event = create_or_update_event(event_id=None, **event_data) + + assert "FR" == test_event.country.code + + +@pytest.mark.django_db +def test_create_event_in_each_listed_country(admin_user, db): + all_countries = list_countries() + + for country in all_countries[2:]: + country_code = country[1] + country_name = country[0] + + event_data = { + 'audience': [3], + 'theme': [1,2], + 'contact_person': u'test@example.com', + 'country': country_code, + '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.', + 'event_url': u'', + 'location': country_name, + 'organizer': u'RailsGirls ' + country_name, + "creator": admin_user, + 'start_date': datetime.datetime.now(), + 'end_date': datetime.datetime.now() + datetime.timedelta(days=3, hours=3), + 'tags': [u'css', u'html', u'web'], + 'title': u'RailsGirls ' + country_name, + } + + test_event = create_or_update_event(event_id=None, **event_data) + + assert country_code == test_event.country.code + + test_event.delete() + + +def test_list_countries(): + # a function we use a lot to get all countries, so let's check it's returning expected results + all_countries = list_countries() + + # Austria should be the first country after two custom entries (All countries) + assert "Austria" == all_countries[2][0] + + # checking two random countries - our own and Kosovo, which is a special case + assert ('Slovenia', 'SI') in all_countries + assert ('Kosovo', 'XK') in all_countries + + # United Kingdom should be last + assert "United Kingdom" == all_countries[-1][0] + + # if listing works, results are tuples ('country_name', 'country_code') + # country_code should be a string with 2 characters + for country in all_countries[2:]: + assert len(country[1]) == 2 + + @pytest.mark.django_db def test_scoreboard_counter(admin_user, db): initial_counter = count_approved_events_for_country() + # extra check to make sure the number of results matches + # the number of listed countries minus two custom entries + all_countries = list_countries() + assert len(initial_counter) == len(all_countries[2:]) + counted_events_before = 0 for country in initial_counter: @@ -437,10 +518,12 @@ def test_scoreboard_counter(admin_user, db): new_counter = count_approved_events_for_country() counted_events_after = 0 + country_score_after = 0 for country in new_counter: if country['country_code'] == 'SI': counted_events_after = country['events'] + country_score_after = country['score'] # An extra check with a direct DB query counted_events_query = Event.objects.filter(status='APPROVED').filter(country='SI').count() @@ -448,5 +531,7 @@ def test_scoreboard_counter(admin_user, db): assert counted_events_after == counted_events_before + 1 assert counted_events_after == counted_events_query + assert country_score_after > 0 + test_approved_event.delete() test_pending_event.delete()