Commit 6ab096bc authored by Nicolas Joyard's avatar Nicolas Joyard

Add position creation tests

parent 0731c495
<div class="modal fade" id="add-position-success" role="dialog" tabindex="-1">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button aria-label="Close" class="close" data-dismiss="modal" type="button"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Add a representative public position</h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<div class="row">
<div class="col-sm-12">
<div class="alert alert-success text-justify" role="alert">Thanks! The position was submitted and will be reviewed shortly.</div>
</div>
</div>
<button class="btn btn-default" data-dismiss="modal" type="button">Close</button>
</div>
</div>
</div>
</div>
\ No newline at end of file
<div class="form-group has-error"><label class="col-md-3 control-label" for="id_position-datetime">Datetime</label><div class="col-md-9">
<div class="input-group date" id="id_position-datetime">
<input class="form-control" id="id_position-datetime" name="position-datetime" placeholder="Datetime" readonly="" required="required" title="" type="text"/>
<span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
</div>
<script type="text/javascript">
$("#id_position-datetime").datetimepicker({minView: 2,
autoclose: true,
language: 'en',
startView: 2,
format: 'yyyy-mm-dd'}).find('input').addClass("form-control");
</script>
<span class="help-block">This field is required.
</span></div></div>
\ No newline at end of file
<div class="form-group has-error"><label class="col-md-3 control-label" for="id_position-link">Link</label><div class="col-md-9"><input class="form-control" id="id_position-link" maxlength="500" name="position-link" placeholder="Link" required="required" title="" type="url"/><span class="help-block">This field is required.
</span></div></div>
\ No newline at end of file
import copy
import datetime
from .base import BaseTest, RepresentativeBaseTest, ThemeBaseTest
from representatives_positions.models import Position
class PositionFormTest(BaseTest):
url = '/'
create_url = RepresentativeBaseTest.base_url % 'none'
position_fixture = {
'position-representative': 1,
'position-datetime': '2016-09-01',
'position-link': 'http://example.com/test',
'position-text': 'position test text',
'position-themes': '1'
}
def test_position_form(self):
self.client.cookies['csrftoken'] = 'csrftoken'
......@@ -19,3 +32,40 @@ class PositionFormTest(BaseTest):
'#add-position-form #id_position-themes input[checked]',
ThemeBaseTest.base_url % 'none'
)
def test_create_position(self):
response = self.client.post(self.create_url, self.position_fixture)
self.assertResponseDiffEmpty(response, '#add-position-success')
position = Position.objects.get(text='position test text')
assert position.datetime == datetime.date(2016, 9, 1)
assert position.representative.pk == \
self.position_fixture['position-representative']
assert position.link == self.position_fixture['position-link']
assert ''.join(['%s' % t.pk for t in position.themes.all()]) == '1'
assert position.published is False
def test_create_position_without_representative(self):
fixture = copy.copy(self.position_fixture)
fixture.pop('position-representative')
response = self.client.post(self.create_url, fixture)
self.assertResponseDiffEmpty(response, '#add-position-form .has-error')
assert response.context['position_form'].is_valid() is False
def test_create_position_without_datetime(self):
fixture = copy.copy(self.position_fixture)
fixture.pop('position-datetime')
response = self.client.post(self.create_url, fixture)
self.assertResponseDiffEmpty(response, '#add-position-form .has-error')
assert response.context['position_form'].is_valid() is False
def test_create_position_without_link(self):
fixture = copy.copy(self.position_fixture)
fixture.pop('position-link')
response = self.client.post(self.create_url, fixture)
self.assertResponseDiffEmpty(response, '#add-position-form .has-error')
assert response.context['position_form'].is_valid() is False
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment