Skip to content

Commit

Permalink
New unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
tonioo committed Mar 5, 2017
1 parent 91cc4e4 commit 224db26
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ install:
before_script:
- if [[ $DB = 'POSTGRESQL' ]]; then psql -c 'create database modoboa_test;' -U postgres; fi
- if [[ $DB = 'MYSQL' ]]; then mysql -e "create database IF NOT EXISTS modoboa_test;" -uroot; fi
- if [[ $DB = 'MYSQL' ]]; then mysql -e "CREATE USER 'modoboa'@'localhost' IDENTIFIED BY 'modoboa'" -uroot; fi
- if [[ $DB = 'MYSQL' ]]; then mysql -e "GRANT ALL PRIVILEGES ON * . * TO 'modoboa'@'localhost';" -uroot; fi
- if [[ $DB = 'MYSQL' ]]; then mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'modoboa'@'localhost' IDENTIFIED BY 'modoboa';" -uroot; fi

script:
- cd test_project
Expand Down
5 changes: 4 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
modoboa-webmail
===============

|travis| |landscape| |rtfd|
|travis| |codecov| |landscape| |rtfd|

The webmail of Modoboa.

Expand Down Expand Up @@ -45,6 +45,9 @@ apache, whatever).
:target: https://landscape.io/github/modoboa/modoboa-webmail/master
:alt: Code Health

.. |codecov| image:: https://codecov.io/gh/modoboa/modoboa-webmail/branch/master/graph/badge.svg
:target: https://codecov.io/gh/modoboa/modoboa-webmail

.. |rtfd| image:: https://readthedocs.org/projects/modoboa-webmail/badge/?version=latest
:target: https://readthedocs.org/projects/modoboa-webmail/?badge=latest
:alt: Documentation Status
24 changes: 23 additions & 1 deletion modoboa_webmail/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def setUp(self):
"""Connect with a simpler user."""
self.workdir = tempfile.mkdtemp()
os.mkdir("{}/webmail".format(self.workdir))
self.set_global_parameters({"max_attachment_size": "10K"})
url = reverse("core:login")
data = {
"username": self.user.username, "password": "toto"
Expand All @@ -57,6 +56,11 @@ def test_attachments(self):
response = self.client.get(url)
self.assertEqual(response.status_code, 200)

with self.settings(MEDIA_ROOT=self.workdir):
response = self.client.post(url, {"attachment": get_gif()})
self.assertContains(response, "Attachment is too big")

self.set_global_parameters({"max_attachment_size": "10K"})
with self.settings(MEDIA_ROOT=self.workdir):
response = self.client.post(url, {"attachment": get_gif()})
self.assertContains(response, "upload_success")
Expand All @@ -70,3 +74,21 @@ def test_attachments(self):
with self.settings(MEDIA_ROOT=self.workdir):
self.ajax_get("{}?name={}".format(url, name))
self.assertFalse(os.path.exists(path))

def test_delattachment_errors(self):
"""Check error cases."""
url = reverse("modoboa_webmail:index")
response = self.client.get("{}?action=compose".format(url))
self.assertEqual(response.status_code, 200)
self.assertIn("compose_mail", self.client.session)

url = reverse("modoboa_webmail:attachment_delete")
with self.settings(MEDIA_ROOT=self.workdir):
response = self.ajax_get("{}?name=".format(url))
self.assertEqual(response["status"], "ko")
self.assertEqual(response["respmsg"], "Bad query")

with self.settings(MEDIA_ROOT=self.workdir):
response = self.ajax_get("{}?name=test".format(url))
self.assertEqual(response["status"], "ko")
self.assertEqual(response["respmsg"], "Unknown attachment")

0 comments on commit 224db26

Please sign in to comment.