|
8 | 8 | from py.path import local
|
9 | 9 |
|
10 | 10 | from geoposition import Geoposition
|
| 11 | +from web.processors.event import list_countries |
11 | 12 |
|
12 | 13 | from api.models.events import Event
|
13 | 14 | from api.models import UserProfile
|
@@ -389,11 +390,91 @@ def test_create_event_in_serbia(admin_user, db):
|
389 | 390 |
|
390 | 391 | assert "RS" == test_event.country.code
|
391 | 392 |
|
| 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 | + |
392 | 468 | @pytest.mark.django_db
|
393 | 469 | def test_scoreboard_counter(admin_user, db):
|
394 | 470 |
|
395 | 471 | initial_counter = count_approved_events_for_country()
|
396 | 472 |
|
| 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 | + |
397 | 478 | counted_events_before = 0
|
398 | 479 |
|
399 | 480 | for country in initial_counter:
|
@@ -437,16 +518,20 @@ def test_scoreboard_counter(admin_user, db):
|
437 | 518 | new_counter = count_approved_events_for_country()
|
438 | 519 |
|
439 | 520 | counted_events_after = 0
|
| 521 | + country_score_after = 0 |
440 | 522 |
|
441 | 523 | for country in new_counter:
|
442 | 524 | if country['country_code'] == 'SI':
|
443 | 525 | counted_events_after = country['events']
|
| 526 | + country_score_after = country['score'] |
444 | 527 |
|
445 | 528 | # An extra check with a direct DB query
|
446 | 529 | counted_events_query = Event.objects.filter(status='APPROVED').filter(country='SI').count()
|
447 | 530 |
|
448 | 531 | assert counted_events_after == counted_events_before + 1
|
449 | 532 | assert counted_events_after == counted_events_query
|
450 | 533 |
|
| 534 | + assert country_score_after > 0 |
| 535 | + |
451 | 536 | test_approved_event.delete()
|
452 | 537 | test_pending_event.delete()
|
0 commit comments