Projet

Général

Profil

0001-fix-pep8-errors-in-testsy.patch

Josué Kouka, 25 octobre 2016 15:36

Télécharger (7,34 ko)

Voir les différences:

Subject: [PATCH 1/2] fix pep8 errors in testsy

 tests/conftest.py      |  1 +
 tests/test_api.py      |  9 ++++-----
 tests/test_emailing.py | 36 +++++++++++++++++-------------------
 3 files changed, 22 insertions(+), 24 deletions(-)
tests/conftest.py
1 1
import pytest
2 2
import django_webtest
3 3

  
4

  
4 5
@pytest.fixture
5 6
def app(request):
6 7
    wtm = django_webtest.WebTestMixin()
tests/test_api.py
1 1
import pytest
2
import json
3 2
from uuid import uuid4
4 3

  
5 4

  
......
22 21
        categories.append(c)
23 22
    return categories
24 23

  
24

  
25 25
@pytest.fixture
26 26
def announces():
27 27
    announces = []
......
55 55
    for identifier, name in channel_choices[:1]:
56 56
        for category in categories:
57 57
            uri = '%s:%s' % (identifier, foo)
58
            subscription = Subscription.objects.create(identifier=uri,
59
                                category=category)
58
            Subscription.objects.create(identifier=uri,
59
                                        category=category)
60 60
            resp = app.get(reverse('subscriptions'), {'email': foo}, status=200)
61 61
            assert 'data' in resp.json
62 62
            data = resp.json['data']
......
79 79
            subscriptions = [{'id': category_id,
80 80
                              'text': category.name,
81 81
                              'transports': transports}]
82
            resp = app.post_json(subscriptions_url , subscriptions)
82
            resp = app.post_json(subscriptions_url, subscriptions)
83 83
            if resp.json['data']:
84 84
                resp = app.get(subscriptions_url, status=200)
85
                print resp.json['data']
86 85
                for cat in resp.json['data']:
87 86
                    if cat['id'] == category_id:
88 87
                        sub_transports = [c['id'] for c in cat['transports']]
tests/test_emailing.py
1
import urlparse
2 1
import pytest
3
import json
4 2
from uuid import uuid4
5 3
import os
6 4
import re
7 5
import urllib
8 6

  
9 7
from django.core.urlresolvers import reverse
10
from django.utils.http import urlencode
11 8
from django.core import mail, signing
12 9
from django.utils import timezone
13 10
from django.core.files.storage import DefaultStorage
14
from django.core.urlresolvers import reverse
15
from django.conf import settings
16 11

  
17
from corbo.models import Category, Announce, Subscription, Broadcast
18
from corbo.models import channel_choices, transform_image_src
12
from corbo.models import Category, Announce, Subscription, Broadcast, transform_image_src
19 13

  
20 14
pytestmark = pytest.mark.django_db
21 15

  
......
30 24
        categories.append(c)
31 25
    return categories
32 26

  
27

  
33 28
@pytest.fixture
34 29
def announces():
35 30
    announces = []
......
46 41
        announces.append(a)
47 42
    return announces
48 43

  
44

  
49 45
def test_emailing_with_no_subscriptions(app, categories, announces):
50 46
    for announce in announces:
51 47
        broadcast = Broadcast.objects.get(announce=announce)
......
53 49
        assert not broadcast.result
54 50
    assert not mail.outbox
55 51

  
52

  
56 53
def test_send_email(app, categories, announces):
57 54
    for category in categories:
58 55
        uuid = uuid4()
59
        s = Subscription.objects.create(category=category,
60
                    identifier='%s@example.net' % uuid, uuid=uuid)
56
        Subscription.objects.create(category=category,
57
                                    identifier='%s@example.net' % uuid, uuid=uuid)
61 58
    for announce in announces:
62
        broadcast= Broadcast.objects.get(announce=announce)
59
        broadcast = Broadcast.objects.get(announce=announce)
63 60
        broadcast.send()
64 61
        assert broadcast.result
65 62
        assert mail.outbox
66 63

  
64

  
67 65
def test_check_inline_css(app, categories, announces):
68 66
    for announce in announces:
69 67
        announce.text = '<style type="text/css">h2 {color: #F00}</style>' + announce.text
70 68
        announce.save()
71 69
        uuid = uuid4()
72
        s = Subscription.objects.create(category=announce.category,
73
                    identifier='%s@example.net' % uuid, uuid=uuid)
70
        Subscription.objects.create(category=announce.category,
71
                                    identifier='%s@example.net' % uuid, uuid=uuid)
74 72
        broadcast = Broadcast.objects.get(announce=announce)
75 73
        broadcast.send()
76 74
        assert broadcast.result
......
78 76
        assert 'h2 style="color:#F00"' in mail.outbox[0].html
79 77
        mail.outbox = []
80 78

  
79

  
81 80
def test_check_inline_images(app, categories, announces):
82 81
    storage = DefaultStorage()
83 82
    media_path = os.path.join(os.path.dirname(__file__), 'media')
......
88 87
        announce.text = announce.text + '<img src="%s" />' % img_src
89 88
        announce.save()
90 89
        uuid = uuid4()
91
        s = Subscription.objects.create(category=announce.category,
92
                    identifier='%s@example.net' % uuid, uuid=uuid)
90
        Subscription.objects.create(category=announce.category,
91
                                    identifier='%s@example.net' % uuid, uuid=uuid)
93 92
        broadcast = Broadcast.objects.get(announce=announce)
94 93
        broadcast.send()
95 94
        assert broadcast.result
......
101 100
        mail.outbox = []
102 101
    storage.delete(image_name)
103 102

  
103

  
104 104
def test_unsubscription_link(app, categories, announces):
105 105
    unsubscription_link_sentinel = ''
106 106
    for category in categories:
107 107
        uuid = uuid4()
108 108
        scheme = 'mailto:'
109 109
        uri = scheme + '%s@example.net' % uuid
110
        s = Subscription.objects.create(category=category,
111
                                identifier=uri,
112
                                uuid=str(uuid))
110
        Subscription.objects.create(category=category, identifier=uri, uuid=str(uuid))
113 111
        for announce in announces:
114 112
            if announce.category != category:
115 113
                continue
116
            broadcast= Broadcast.objects.get(announce=announce)
114
            broadcast = Broadcast.objects.get(announce=announce)
117 115
            broadcast.send()
118 116
            assert broadcast.result
119 117
            assert mail.outbox
......
121 119
            signature = urllib.unquote(re.findall('/unsubscribe/(.*)"', mail.outbox[0].html)[0])
122 120
            unsubscription_link = reverse('unsubscribe', kwargs={'unsubscription_token': signature})
123 121
            assert signing.loads(signature) == {
124
                    'category': announce.category.pk, 'identifier': uri}
122
                'category': announce.category.pk, 'identifier': uri}
125 123
            assert mail.outbox[0].subject == announce.title
126 124
            assert unsubscription_link in mail.outbox[0].html
127 125
            assert unsubscription_link in mail.outbox[0].text
128
-