Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added tests for example app configuration
- Loading branch information
Amirouche Boubekki
committed
May 3, 2012
1 parent
37c888c
commit 8f914a1
Showing
27 changed files
with
508 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ | |
*.sqlite | ||
*~ | ||
example_project/tmp/* | ||
example_project/medias | ||
example_project/data.db |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from sequential.zip_packer import * | ||
from sequential.flat_packer import * | ||
from mass.zip_packer import * | ||
from mass.flat_packer import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import os | ||
import shutil | ||
|
||
from django.conf import settings | ||
from django.test import TestCase | ||
|
||
from carrier_pigeon.registry import REGISTRY | ||
|
||
|
||
REGISTRY_COPY = dict(REGISTRY) | ||
|
||
class ImplementationBaseTests(TestCase): | ||
|
||
@property | ||
def outbox(self): | ||
path = os.path.join( | ||
settings.SITE_ROOT, | ||
'tmp', | ||
'export', | ||
self.tested_configuration_name, | ||
'outbox', | ||
) | ||
return path | ||
|
||
def clean_outbox(self): | ||
path = self.outbox | ||
if os.path.exists(path): | ||
shutil.rmtree(path) | ||
|
||
def data(self, filename): | ||
path = os.path.join( | ||
os.path.dirname(__file__), | ||
'data', | ||
self.tested_configuration_name, | ||
filename | ||
) | ||
return path | ||
|
||
def setUp(self): | ||
# remove from registred configuration | ||
# configuration that we do no test in current test class | ||
REGISTRY.clear() | ||
for key, item in REGISTRY_COPY.iteritems(): | ||
print key, item | ||
if key == self.tested_configuration_name: | ||
REGISTRY[key] = item | ||
self.clean_outbox() | ||
|
||
def tearDown(self): | ||
self.clean_outbox() | ||
|
||
# clean media content | ||
path = os.path.join( | ||
settings.SITE_ROOT, | ||
'medias', | ||
'photo', | ||
) | ||
shutil.rmtree(path) |
2 changes: 2 additions & 0 deletions
2
example_project/example_app/tests/data/anotherbelovedpartner/NEWS_example_app_1.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<doc><title>An egg & and a chicken</title><updating_date>May 2, 2012</updating_date><content><p>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p></content><photo>/medias/1.jpg</photo><linkeds><linked><title>An egg & and a chicken</title><id>1</id></linked><linked><title>The dear and the fawn </title><id>2</id></linked><linked><title>Tazmania devil dog</title><id>3</id></linked></linkeds></doc> |
2 changes: 2 additions & 0 deletions
2
example_project/example_app/tests/data/anotherbelovedpartner/NEWS_example_app_2.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<doc><title>The dear and the fawn </title><updating_date>May 2, 2012</updating_date><content><p>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p></content><photo>/medias/1.jpg</photo><linkeds><linked><title>An egg & and a chicken</title><id>1</id></linked><linked><title>The dear and the fawn </title><id>2</id></linked><linked><title>Tazmania devil dog</title><id>3</id></linked></linkeds></doc> |
2 changes: 2 additions & 0 deletions
2
example_project/example_app/tests/data/belovedpartner/NEWS_example_app_1.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<doc><title>An egg & and a chicken</title><updating_date>May 2, 2012</updating_date><content><p>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p></content><photo>/medias/1.jpg</photo><linkeds><linked><title>An egg & and a chicken</title><id>1</id></linked><linked><title>The dear and the fawn </title><id>2</id></linked><linked><title>Tazmania devil dog</title><id>3</id></linked></linkeds></doc> |
2 changes: 2 additions & 0 deletions
2
example_project/example_app/tests/data/belovedpartner/NEWS_example_app_2.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<doc><title>The dear and the fawn </title><updating_date>May 2, 2012</updating_date><content><p>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p></content><photo>/medias/1.jpg</photo><linkeds><linked><title>An egg & and a chicken</title><id>1</id></linked><linked><title>The dear and the fawn </title><id>2</id></linked><linked><title>Tazmania devil dog</title><id>3</id></linked></linkeds></doc> |
2 changes: 2 additions & 0 deletions
2
example_project/example_app/tests/data/flatmassexport/example_app_story_1.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<doc type="flatmassexport"><title>An egg & and a chicken</title><updating_date>May 3, 2012</updating_date><content><p>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p></content><photo>/photos/1.jpg</photo></doc> |
2 changes: 2 additions & 0 deletions
2
example_project/example_app/tests/data/flatmassexport/example_app_story_2.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<doc type="flatmassexport"><title>The dear and the fawn </title><updating_date>May 3, 2012</updating_date><content><p>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p></content><photo>/photos/1.jpg</photo></doc> |
1 change: 1 addition & 0 deletions
1
example_project/example_app/tests/data/flatmassexport/photos/1.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions
2
example_project/example_app/tests/data/weeklydigest/example_app_story_1.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<doc><title>An egg & and a chicken</title><updating_date>May 2, 2012</updating_date><content><p>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p></content><photo>/medias/1.jpg</photo></doc> |
2 changes: 2 additions & 0 deletions
2
example_project/example_app/tests/data/weeklydigest/example_app_story_2.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<doc><title>The dear and the fawn </title><updating_date>May 2, 2012</updating_date><content><p>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p></content><photo>/medias/1.jpg</photo></doc> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import os | ||
import shutil | ||
import hashlib | ||
import zipfile | ||
from StringIO import StringIO | ||
from datetime import datetime | ||
from datetime import timedelta | ||
|
||
from django.conf import settings | ||
from django.core.files import File | ||
from django.core.management import call_command | ||
|
||
from carrier_pigeon.models import ItemToPush | ||
|
||
from example_app.models import Photo | ||
from example_app.models import Story | ||
from example_app.tests.base import ImplementationBaseTests | ||
|
||
|
||
class FlatMassExportTest(ImplementationBaseTests): | ||
"""Check proper behavior of WeeklyDigest mass zip export configuration""" | ||
|
||
tested_configuration_name = 'flatmassexport' | ||
|
||
def setUp(self): | ||
super(FlatMassExportTest, self).setUp() | ||
|
||
settings.CARRIER_PIGEON_PUSH_URLS = { | ||
self.tested_configuration_name: ( | ||
"dummy://user:pwd@ftp.weeklydigest.tld", | ||
), | ||
} | ||
|
||
# create Photo instance | ||
|
||
# build a random filename | ||
m = hashlib.sha1() | ||
m.update(os.urandom(24)) | ||
filepath = '/tmp/%s.jpeg' % m.hexdigest() | ||
# open and write photo filename with data | ||
fd = open(filepath, 'w') | ||
fd.write('coucou') | ||
fd.close() | ||
fd = open(filepath) | ||
# create Photo object | ||
photo = Photo( | ||
title='Egg', | ||
credits='Chicken', | ||
caption='An egg created by a chicken', | ||
original_file=File(fd), | ||
) | ||
photo.save() | ||
|
||
# don't forget to clean | ||
os.remove(filepath) | ||
|
||
# build story objects | ||
self.stories = [] | ||
|
||
# the following two stories will be selected | ||
# by the configuration | ||
story = Story( | ||
title='An egg & and a chicken', | ||
workflow_state=Story.WORKFLOW_STATE.ONLINE, | ||
content='a'*500, | ||
photo=photo, | ||
updating_date=datetime.now() | ||
) | ||
story.save() | ||
self.stories.append(story) | ||
story = Story( | ||
title='The dear and the fawn ', | ||
workflow_state=Story.WORKFLOW_STATE.ONLINE, | ||
content='a'*500, | ||
photo=photo, | ||
updating_date=datetime.now() | ||
) | ||
story.save() | ||
self.stories.append(story) | ||
|
||
# This story is not selected | ||
story = Story( | ||
title='Tazmania devil dog', | ||
workflow_state=Story.WORKFLOW_STATE.OFFLINE, | ||
content='a'*500, | ||
photo=photo, | ||
updating_date=datetime.now() - timedelta(days=99) | ||
) | ||
story.save() | ||
|
||
def _test_content(self): | ||
for story in self.stories: | ||
filename = 'example_app_story_%s.xml' % story.pk | ||
filepath = os.path.join( | ||
self.outbox, | ||
filename, | ||
) | ||
with open(filepath) as f: | ||
with open(self.data(filename)) as d: | ||
self.assertEqual( | ||
f.read(), | ||
d.read(), | ||
) | ||
|
||
photopath = os.path.join( | ||
self.outbox, | ||
'photos', | ||
'1.jpg', | ||
) | ||
self.assertTrue(os.path.exists(photopath)) | ||
with open(photopath) as f: | ||
self.assertEqual(f.read(), 'coucou') | ||
|
||
def test_pigeon_push(self): | ||
call_command('pigeon_mass_push', 'flatmassexport') | ||
self._test_content() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import os | ||
import shutil | ||
import hashlib | ||
import zipfile | ||
from StringIO import StringIO | ||
from datetime import date | ||
from datetime import datetime | ||
from datetime import timedelta | ||
|
||
from django.conf import settings | ||
from django.core.files import File | ||
from django.core.management import call_command | ||
|
||
from carrier_pigeon.models import ItemToPush | ||
|
||
from example_app.models import Photo | ||
from example_app.models import Story | ||
from example_app.tests.base import ImplementationBaseTests | ||
|
||
|
||
class WeeklyDigestTests(ImplementationBaseTests): | ||
"""Check proper behavior of WeeklyDigest mass zip export configuration""" | ||
|
||
tested_configuration_name = 'weeklydigest' | ||
|
||
def setUp(self): | ||
super(WeeklyDigestTests, self).setUp() | ||
|
||
settings.CARRIER_PIGEON_PUSH_URLS = { | ||
self.tested_configuration_name: ( | ||
"dummy://user:pwd@ftp.weeklydigest.tld", | ||
), | ||
} | ||
|
||
# create Photo instance | ||
|
||
# build a random filename | ||
m = hashlib.sha1() | ||
m.update(os.urandom(24)) | ||
filepath = '/tmp/%s.jpeg' % m.hexdigest() | ||
# open and write photo filename with data | ||
fd = open(filepath, 'w') | ||
fd.write('coucou') | ||
fd.close() | ||
fd = open(filepath) | ||
# create Photo object | ||
photo = Photo( | ||
title='Egg', | ||
credits='Chicken', | ||
caption='An egg created by a chicken', | ||
original_file=File(fd), | ||
) | ||
photo.save() | ||
|
||
# don't forget to clean | ||
os.remove(filepath) | ||
|
||
# build story objects | ||
self.stories = [] | ||
|
||
# the following two stories will be selected | ||
# by the configuration | ||
story = Story( | ||
title='An egg & and a chicken', | ||
workflow_state=Story.WORKFLOW_STATE.ONLINE, | ||
content='a'*500, | ||
photo=photo, | ||
updating_date=date(2012, 5, 2) | ||
) | ||
story.save() | ||
self.stories.append(story) | ||
story = Story( | ||
title='The dear and the fawn ', | ||
workflow_state=Story.WORKFLOW_STATE.ONLINE, | ||
content='a'*500, | ||
photo=photo, | ||
updating_date=date(2012, 5, 2) | ||
) | ||
story.save() | ||
self.stories.append(story) | ||
|
||
# This story is not selected | ||
story = Story( | ||
title='Tazmania devil dog', | ||
workflow_state=Story.WORKFLOW_STATE.OFFLINE, | ||
content='a'*500, | ||
photo=photo, | ||
updating_date=date(2012, 5, 2) | ||
) | ||
story.save() | ||
|
||
def _test_content(self): | ||
for story in self.stories: | ||
filename = 'example_app_story_%s.xml' % story.pk | ||
filepath = os.path.join( | ||
self.outbox, | ||
filename, | ||
) | ||
with open(filepath) as f: | ||
with open(self.data(filename)) as d: | ||
self.assertEqual( | ||
f.read(), | ||
d.read(), | ||
) | ||
|
||
photopath = os.path.join( | ||
self.outbox, | ||
'photos', | ||
'1.jpg', | ||
) | ||
self.assertTrue(os.path.exists(photopath)) | ||
with open(photopath) as f: | ||
self.assertEqual(f.read(), 'coucou') | ||
|
||
def test_pigeon_push(self): | ||
call_command('pigeon_mass_push', 'weeklydigest') | ||
listdir = os.listdir(self.outbox) | ||
self.assertEqual(len(listdir), 1) | ||
filename = listdir[0] | ||
self.assertEqual(filename, 'weeklydigest.zip') | ||
path = os.path.join( | ||
self.outbox, | ||
filename, | ||
) | ||
zzz = zipfile.ZipFile(path) | ||
zzz.extractall(self.outbox) | ||
self._test_content() |
Empty file.
Oops, something went wrong.