|
18 | 18 | from api.processors import get_approved_events
|
19 | 19 | from api.processors import get_next_or_previous
|
20 | 20 | from api.processors import get_nearby_events
|
21 |
| - |
| 21 | +from web.processors.event import count_approved_events_for_country |
22 | 22 |
|
23 | 23 | class EventTestCase(TestCase):
|
24 | 24 | def get_user(self):
|
@@ -345,3 +345,63 @@ def test_create_event_in_moldova(admin_user, db):
|
345 | 345 |
|
346 | 346 | assert "MD" == test_event.country.code
|
347 | 347 |
|
| 348 | +@pytest.mark.django_db |
| 349 | +def test_scoreboard_counter(admin_user, db): |
| 350 | + |
| 351 | + initial_counter = count_approved_events_for_country() |
| 352 | + |
| 353 | + counted_events_before = 0 |
| 354 | + |
| 355 | + for country in initial_counter: |
| 356 | + if country['country_code'] == 'SI': |
| 357 | + counted_events_before = country['events'] |
| 358 | + |
| 359 | + # Adding one approved and one pending event in same country |
| 360 | + # the count for events for the country should increase by 1 |
| 361 | + event_data = { |
| 362 | + 'audience': [3], |
| 363 | + 'theme': [1,2], |
| 364 | + 'country': u'SI', |
| 365 | + '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.', |
| 366 | + 'location': u'Ljubljana, Slovenia', |
| 367 | + 'organizer': u'testko', |
| 368 | + "creator": admin_user, |
| 369 | + 'start_date': datetime.datetime.now(), |
| 370 | + 'end_date': datetime.datetime.now() + datetime.timedelta(days=3, hours=3), |
| 371 | + 'title': u'Test Approved Event', |
| 372 | + 'status':"APPROVED", |
| 373 | + } |
| 374 | + |
| 375 | + test_approved_event = create_or_update_event(event_id=None, **event_data) |
| 376 | + |
| 377 | + event_data = { |
| 378 | + 'audience': [3], |
| 379 | + 'theme': [1,2], |
| 380 | + 'country': u'SI', |
| 381 | + '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.', |
| 382 | + 'location': u'Ljubljana, Slovenia', |
| 383 | + 'organizer': u'testko', |
| 384 | + "creator": admin_user, |
| 385 | + 'start_date': datetime.datetime.now(), |
| 386 | + 'end_date': datetime.datetime.now() + datetime.timedelta(days=3, hours=3), |
| 387 | + 'title': u'Test Pending Event', |
| 388 | + 'status':"PENDING", |
| 389 | + } |
| 390 | + |
| 391 | + test_pending_event = create_or_update_event(event_id=None, **event_data) |
| 392 | + |
| 393 | + new_counter = count_approved_events_for_country() |
| 394 | + |
| 395 | + counted_events_after = 0 |
| 396 | + |
| 397 | + for country in new_counter: |
| 398 | + if country['country_code'] == 'SI': |
| 399 | + counted_events_after = country['events'] |
| 400 | + |
| 401 | + # An extra check with a direct DB query |
| 402 | + counted_events_query = Event.objects.filter(status='APPROVED').filter(country='SI').count() |
| 403 | + |
| 404 | + assert counted_events_after == counted_events_before + 1 |
| 405 | + assert counted_events_after == counted_events_query |
| 406 | + |
| 407 | + |
0 commit comments