From 7f5fd62a3d2326c242033702d3f516400ed9f9dd Mon Sep 17 00:00:00 2001 From: Ole Laursen Date: Mon, 5 Sep 2011 17:14:47 +0000 Subject: [PATCH] Add simple test for ID submission, needs more extensive checking - Legacy-Id: 3416 --- ietf/submit/test_submission.txt | 113 ++++++++++++++++++++++++++++++++ ietf/submit/tests.py | 71 ++++++++++++++++++++ ietf/utils/test_data.py | 13 ++++ 3 files changed, 197 insertions(+) create mode 100644 ietf/submit/test_submission.txt create mode 100644 ietf/submit/tests.py diff --git a/ietf/submit/test_submission.txt b/ietf/submit/test_submission.txt new file mode 100644 index 000000000..8cab388a9 --- /dev/null +++ b/ietf/submit/test_submission.txt @@ -0,0 +1,113 @@ +Informational Test Name +Internet-Draft Test Center Inc. +Intended status: Informational +Expires: %(expire)s %(date)s + + + Testing tests + %(filename)s + + +Abstract + + This document describes how to test tests. + +Status of this Memo + + This Internet-Draft is submitted in full conformance with the + provisions of BCP 78 and BCP 79. This document may not be modified, + and derivative works of it may not be created, and it may not be + published except as an Internet-Draft. + + Internet-Drafts are working documents of the Internet Engineering + Task Force (IETF). Note that other groups may also distribute + working documents as Internet-Drafts. The list of current Internet- + Drafts is at http://datatracker.ietf.org/drafts/current/. + + Internet-Drafts are draft documents valid for a maximum of six months + and may be updated, replaced, or obsoleted by other documents at any + time. It is inappropriate to use Internet-Drafts as reference + material or to cite them other than as "work in progress." + + This Internet-Draft will expire on %(expire)s. + +Copyright Notice + + Copyright (c) %(year)s IETF Trust and the persons identified as the + document authors. All rights reserved. + + This document is subject to BCP 78 and the IETF Trust's Legal + Provisions Relating to IETF Documents + (http://trustee.ietf.org/license-info) in effect on the date of + publication of this document. Please review these documents + carefully, as they describe your rights and restrictions with respect + to this document. + + This Informational Internet Draft is submitted as an RFC Editor + + + +Name Expires %(expire)s [Page 1] + +Internet-Draft Testing tests %(month_year)s + + Contribution and/or non-IETF Document (not as a Contribution, IETF + Contribution, nor IETF Document) in accordance with BCP 78 and BCP + 79. + + +Table of Contents + + 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 4 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Name Expires %(expire)s [Page 2] + +Internet-Draft Testing tests %(month_year)s + +1. Introduction + + This document describes a protocol for testing tests. + diff --git a/ietf/submit/tests.py b/ietf/submit/tests.py new file mode 100644 index 000000000..90ba31671 --- /dev/null +++ b/ietf/submit/tests.py @@ -0,0 +1,71 @@ +import datetime, os, shutil + +from django.conf import settings +from django.contrib.auth.models import User +from django.core.urlresolvers import reverse as urlreverse +import django.test +from StringIO import StringIO +from pyquery import PyQuery + +from ietf.utils.test_utils import login_testing_unauthorized +from ietf.utils.test_runner import mail_outbox +from ietf.utils.test_data import make_test_data + +if settings.USE_DB_REDESIGN_PROXY_CLASSES: + from redesign.person.models import Person, Email + from redesign.group.models import Group, Role + from redesign.doc.models import Document + +class SubmitTestCase(django.test.TestCase): + fixtures = ['names'] + + def setUp(self): + self.staging_dir = os.path.abspath("tmp-submit-staging-dir") + os.mkdir(self.staging_dir) + + settings.IDSUBMIT_STAGING_PATH = self.staging_dir + + def tearDown(self): + shutil.rmtree(self.staging_dir) + + def test_submit(self): + # break early in case of missing configuration + self.assertTrue(os.path.exists(settings.IDSUBMIT_IDNITS_BINARY)) + + draft = make_test_data() + + url = urlreverse('submit_index') + + # get + r = self.client.get(url) + self.assertEquals(r.status_code, 200) + q = PyQuery(r.content) + self.assertEquals(len(q('input[type=file][name=txt]')), 1) + + # submit text draft + filename = "draft-mars-testing-tests-00" + + # construct appropriate text file + f = open(os.path.join(settings.BASE_DIR, "submit", "test_submission.txt")) + template = f.read() + f.close() + submission_text = template % dict( + date=datetime.date.today().strftime("%Y-%m-%d"), + expire=(datetime.date.today() + datetime.timedelta(days=100)).strftime("%Y-%m-%d"), + year=datetime.date.today().strftime("%Y"), + month_year=datetime.date.today().strftime("%B, %Y"), + filename=filename, + ) + + test_file = StringIO(submission_text) + test_file.name = "somename.txt" + + r = self.client.post(url, + dict(txt=test_file)) + self.assertEquals(r.status_code, 302) + self.assertTrue(os.path.exists(os.path.join(self.staging_dir, filename + ".txt"))) + + +if not settings.USE_DB_REDESIGN_PROXY_CLASSES: + # the above tests only work with the new schema + del SubmitTestCase diff --git a/ietf/utils/test_data.py b/ietf/utils/test_data.py index e31017813..c5725ffb0 100644 --- a/ietf/utils/test_data.py +++ b/ietf/utils/test_data.py @@ -2,6 +2,7 @@ from django.contrib.auth.models import User from ietf.iesg.models import TelechatDates, WGAction from ietf.ipr.models import IprDetail, IprDocAlias +from ietf.meeting.models import Meeting from redesign.doc.models import * from redesign.name.models import * from redesign.group.models import * @@ -221,5 +222,17 @@ def make_test_data(): category=13, telechat_date=dates.date2 ) + + # Meeting + Meeting.objects.create( + number="42", + type_id="ietf", + date=datetime.date.today() + datetime.timedelta(days=180), + city="New York", + country="United States", + time_zone="US/Eastern", + break_area="Lounge", + reg_area="Lobby", + ) return draft