Skip to content
This repository has been archived by the owner on Mar 15, 2021. It is now read-only.

add docker in test #122

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 13 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
services:
- redis-server

language: python

python:
- '3.5'
- '3.6'
- '3.7-dev'


services:
- redis-server
- docker

language: python

addons:
sauce_connect:
username: synhack
Expand All @@ -16,6 +18,12 @@ addons:

cache: pip

before_install:
- docker build -t mercure .
- docker run -d --name redis redis
- docker run -d --name mercure --link=redis:redis -e 'SECRET_KEY=unit_test' mercure
- docker exec -i mercure python manage.py test --exclude-tag selenium

install:
- pip install -r requirements.txt
- pip install coveralls
Expand Down
6 changes: 2 additions & 4 deletions mercure/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,17 @@
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.IsAuthenticated',
],
'PAGE_SIZE': 10,
}

CACHES = {
'default': {
'BACKEND': 'redis_cache.cache.RedisCache',
'LOCATION': '%s:%s' % (os.environ.get('REDIS_HOST', 'localhost'),
os.environ.get('REDIS_PORT', '6379')),
'LOCATION': os.environ.get('REDIS_PORT', 'tcp://localhost:6379'),
},
}

RQ_QUEUES = {
'default': {
'USE_REDIS_CACHE': 'default',
},
}
}
3 changes: 1 addition & 2 deletions mercure/settings/prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
CACHES = {
'default': {
'BACKEND': 'redis_cache.cache.RedisCache',
'LOCATION': '%s:%s' % (os.environ.get('REDIS_HOST', 'redis'),
os.environ.get('REDIS_PORT', '6379')),
'LOCATION': os.environ.get('REDIS_PORT', 'tcp://redis:6379'),
},
}

Expand Down
5 changes: 2 additions & 3 deletions phishing/models/campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ def __str__(self):

@property
def is_launched(self):
if self.send_at < now():
return True
return False
return self.trackers.count() > 0


# TODO: sortir la conf smtp => faire un model
#
Expand Down
1 change: 1 addition & 0 deletions phishing/tests/campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ def test_dashboard_campaign_with_minimize_url(self):
self.run_jobs()

# check minified url
self.assertGreater(len(mail.outbox), 0, mail.outbox)
self.assertIn('click: http://tinyurl.com/',
str(mail.outbox[-1].message()))

Expand Down
3 changes: 3 additions & 0 deletions phishing/tests/landing_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ def test_landing_page_view_invalid_post_id(self):
# We go to the landing page
# The HTTP_HOST is mandatory to generate form "action"
tracker = camp.trackers.filter(key='landing_page_open').first()
self.assertIsNotNone(tracker)
resp = self.client.get(
reverse('landing_page', args=(tracker.uuid,)),
HTTP_HOST='foo.com')
Expand Down Expand Up @@ -474,6 +475,7 @@ def test_landing_page_view_exception(self):
tracker = camp.trackers.filter(key='landing_page_open').first()

# set incorrect value for make crash
self.assertIsNotNone(tracker)
tracker.campaign_id = 99999999
tracker.save()

Expand Down Expand Up @@ -521,6 +523,7 @@ def test_landing_page_post(self):
'mercure_real_action_url': 'http://foo.com',
'mercure_redirect_url': target
}
self.assertIsNotNone(tracker_post)
resp = self.client.post(reverse('landing_page_post',
args=(tracker_post.pk,)), data=data)
self.assertEqual(resp.status_code, 200)
Expand Down
7 changes: 7 additions & 0 deletions phishing/tests/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def handler(request, landing_page, **kwarg):
campaign.target_groups.add(target_group)
self.run_jobs()

self.assertGreater(len(mail.outbox), 0, mail.outbox)
landing_page_url = mail.outbox[-1].body.split('<')[0]

# call landing page ans test result
Expand Down Expand Up @@ -240,6 +241,7 @@ def handler(email_template, **kwarg):
campaign.target_groups.add(target_group)
self.run_jobs()

self.assertGreater(len(mail.outbox), 0, mail.outbox)
self.assertEqual(mail.outbox[-1].body, 'Hello!')
mail_html = mail.outbox[-1].alternatives[0][0]
self.assertEqual(mail_html.split('<')[0], 'Hi!')
Expand Down Expand Up @@ -306,6 +308,7 @@ def handler(instance, **kwarg):

# call tracker
self.send_campaign()
self.assertGreater(len(mail.outbox), 0, mail.outbox)
attachment = json.loads(mail.outbox[-1].attachments[0][1].decode())
tracker_url = attachment['tracker_url']

Expand Down Expand Up @@ -333,6 +336,7 @@ def handler(instance, **kwarg):

# call tracker
self.send_campaign()
self.assertGreater(len(mail.outbox), 0, mail.outbox)
attachment = json.loads(mail.outbox[-1].attachments[0][1].decode())
tracker_url = attachment['tracker_url']

Expand All @@ -359,6 +363,7 @@ def handler(instance, **kwarg):

# call tracker
self.send_campaign()
self.assertGreater(len(mail.outbox), 0, mail.outbox)
mail_html = mail.outbox[-1].alternatives[0][0]
tracker_url = mail_html.split('src="')[-1].split('"')[0]

Expand Down Expand Up @@ -386,6 +391,7 @@ def handler(instance, **kwarg):

# call tracker
self.send_campaign()
self.assertGreater(len(mail.outbox), 0, mail.outbox)
tracker_url = mail.outbox[-1].body

# test if handler has call
Expand Down Expand Up @@ -446,6 +452,7 @@ def handler(instance, **kwarg):

# call tracker
self.send_campaign()
self.assertGreater(len(mail.outbox), 0, mail.outbox)
tracker_url = mail.outbox[-1].body

# call landing page
Expand Down
12 changes: 10 additions & 2 deletions phishing/tests/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
from django.urls import reverse
from django.test import TestCase

from phishing.models import Campaign, EmailTemplate
from phishing.models import Campaign, EmailTemplate, TargetGroup, Target
from .helpers import RQMixin


class PermissionTestCase(TestCase):
class PermissionTestCase(RQMixin, TestCase):
def setUp(self):
super(PermissionTestCase, self).setUp()
self.client.get('not-found') # django fix: first client call is 404

def test_default_permission(self):
Expand Down Expand Up @@ -36,6 +38,12 @@ def test_default_permission(self):
Campaign.objects.create(name='test 2', **campaign_infos)
Campaign.objects.create(name='test 3', **campaign_infos)

# send campaign
target_group = TargetGroup.objects.create(name='targets')
Target.objects.create(email='test@test.com', group=target_group)
campaign.target_groups.add(target_group)
self.run_jobs()

# can list campaign
response = self.client.get(reverse('campaign_list'))
content = response.content.decode()
Expand Down