|
10 | 10 | from django.test import Client |
11 | 11 | from django.core.urlresolvers import reverse |
12 | 12 | from django.core.files.uploadedfile import InMemoryUploadedFile |
13 | | -from django.contrib.auth.models import User |
| 13 | +from django.contrib.auth.models import User, Group |
14 | 14 |
|
15 | 15 | from api.models.events import Event |
16 | 16 | from api.models import UserProfile |
17 | 17 |
|
| 18 | +from avatar.models import Avatar |
| 19 | +from avatar.util import get_primary_avatar |
| 20 | + |
18 | 21 | from web.processors.event import create_or_update_event |
19 | 22 | from web.processors.event import count_approved_events_for_country |
20 | 23 |
|
@@ -52,7 +55,7 @@ def test_index_view_without_approved_events(self): |
52 | 55 | def test_index_view_changing_remote_in_request(self): |
53 | 56 | #setup |
54 | 57 | response = self.client.get(reverse('web.index'), {}, |
55 | | - HTTP_X_FORWARDED_FOR='93.103.53.11, 93.103.53.11') |
| 58 | + HTTP_X_FORWARDED_FOR='93.103.53.11, 93.103.53.11') |
56 | 59 |
|
57 | 60 | #assert |
58 | 61 | self.assertEquals(200, response.status_code) |
@@ -285,6 +288,60 @@ def test_scoreboard_links_and_results(admin_user, db, client): |
285 | 288 | test_approved_event.delete() |
286 | 289 |
|
287 | 290 |
|
| 291 | +@pytest.mark.django_db |
| 292 | +def test_ambassadors_list(db, client): |
| 293 | + test_country_name = "Austria" |
| 294 | + test_country_code = "AT" |
| 295 | + |
| 296 | + test_username = 'test-amb' |
| 297 | + |
| 298 | + test_first_name = 'Testko' |
| 299 | + test_last_name = 'Test' |
| 300 | + test_full_name = test_first_name + " " + test_last_name |
| 301 | + |
| 302 | + test_ambassador = User.objects.create(username=test_username, |
| 303 | + email=test_email, |
| 304 | + first_name=test_first_name, |
| 305 | + last_name=test_last_name) |
| 306 | + test_ambassador_profile = UserProfile.objects.create(user=test_ambassador, |
| 307 | + country=test_country_code) |
| 308 | + |
| 309 | + group = Group.objects.get(name="ambassadors") |
| 310 | + group.user_set.add(test_ambassador) |
| 311 | + |
| 312 | + with open(local(__file__).dirname + '/../../static/img/team/alja.jpg') as fp: |
| 313 | + io = StringIO.StringIO() |
| 314 | + io.write(fp.read()) |
| 315 | + uploaded_picture = InMemoryUploadedFile(io, None, "alja17.jpg", "jpeg", io.len, None) |
| 316 | + uploaded_picture.seek(0) |
| 317 | + |
| 318 | + avatar = Avatar(user=test_ambassador, primary=True) |
| 319 | + avatar.avatar.save(uploaded_picture.name, uploaded_picture) |
| 320 | + avatar.save() |
| 321 | + |
| 322 | + new_avatar = get_primary_avatar(test_ambassador, size=80) |
| 323 | + test_amb_avatar = new_avatar.avatar_url(80) |
| 324 | + |
| 325 | + response = client.get(reverse('web.ambassadors')) |
| 326 | + |
| 327 | + # We're expecting to the Ambassador under the right country, |
| 328 | + # with the right avatar and the right email contact |
| 329 | + expected_result = ''' |
| 330 | + <h2 class="clearfix" id="%s">%s</h2> |
| 331 | + <div class="ambassador clearfix"> |
| 332 | + <img src="%s" alt="%s" width="80" height="80" class="img-circle" /> |
| 333 | + <h4>%s <span> <a href="mailto:%s" alt="Send me an email"><i class="fa fa-envelope"></i></a> |
| 334 | + ''' % (test_country_name, test_country_name, test_amb_avatar, test_username, test_full_name, test_email) |
| 335 | + |
| 336 | + expected_result = expected_result.replace('\t', '').replace('\n', '') |
| 337 | + ambassadors_content = response.content.replace('\t', '').replace('\n', '') |
| 338 | + |
| 339 | + assert expected_result in ambassadors_content |
| 340 | + |
| 341 | + test_ambassador.delete() |
| 342 | + avatar.delete() |
| 343 | + |
| 344 | + |
288 | 345 | @pytest.mark.django_db |
289 | 346 | def test_nonexistent_event(db, client): |
290 | 347 | response = client.get(reverse('web.view_event', args=[1234, 'shouldnt-exist'])) |
|
0 commit comments