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

Added support for EU French colonies and more country related tests #366

Merged
merged 2 commits into from
Oct 1, 2014
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
5 changes: 4 additions & 1 deletion static/js/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down
85 changes: 85 additions & 0 deletions web/tests/test_events_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'[email protected]',
'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'[email protected]',
'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:
Expand Down Expand Up @@ -437,16 +518,20 @@ 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()

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()