-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from gwu-libraries/t96-add-new-collection
👍
- Loading branch information
Showing
6 changed files
with
118 additions
and
24 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
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 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 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 |
---|---|---|
@@ -1,16 +1,26 @@ | ||
{% extends 'base.html' %} | ||
{% load crispy_forms_tags %} | ||
{% block title %} | ||
Create Collection | ||
Add New Collection | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<h1><a href={% url "collection_list" %}>Collection</a></h1> | ||
<h2>Create Collection</h2> | ||
|
||
<form action="" method="post">{% csrf_token %} | ||
{{ form|crispy }} | ||
<input type="submit" value="Create" /> | ||
</form> | ||
<a href={% url "collection_list" %}>Cancel</a> | ||
<div class="row"> | ||
<div class="col-md-12"> | ||
<ol class="breadcrumb"> | ||
<li><a href={% url "collection_list" %}>My Collections</a></li> | ||
<li class="active">Add New Collection</li> | ||
</ol> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="col-md-12"> | ||
<h2>Add New Collection</h2> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="col-md-12"> | ||
{% crispy form %} | ||
</div> | ||
</div> | ||
{% endblock %} |
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,60 @@ | ||
from django.contrib.auth.models import Group | ||
from django.test import TestCase, RequestFactory | ||
|
||
from .forms import CollectionForm | ||
from .views import CollectionCreateView | ||
from .models import User | ||
|
||
|
||
def create_group(name): | ||
return Group.objects.create(name=name) | ||
|
||
|
||
class CollectionFormTest(TestCase): | ||
|
||
def setUp(self): | ||
self.factory = RequestFactory() | ||
self.user = User.objects.create_user(username='testuser', | ||
email='testuser@example.com', password='password') | ||
group = create_group(name='testgroup1') | ||
self.user.groups.add(group) | ||
create_group(name='testgroup2') | ||
|
||
def test_form_has_correct_groups(self): | ||
request = self.factory.get('/ui/collections/create/') | ||
request.user = self.user | ||
response = CollectionCreateView.as_view()(request) | ||
self.assertContains(response, 'testgroup') | ||
self.assertNotContains(response, 'testgroup2') | ||
|
||
def test_valid_data(self): | ||
request = self.factory.get('/ui/collections/create') | ||
request.user = self.user | ||
groupno = Group.objects.filter(name='testgroup1') | ||
form = CollectionForm({ | ||
'name': 'my test collection', | ||
'description': 'my description', | ||
'group': groupno | ||
}, request=request) | ||
self.assertTrue(form.is_valid()) | ||
|
||
def test_invalid_data_blank_name(self): | ||
request = self.factory.get('/ui/collections/create') | ||
request.user = self.user | ||
groupno = Group.objects.filter(name='testgroup1') | ||
form = CollectionForm({ | ||
'name': '', | ||
'description': 'my description', | ||
'group': groupno | ||
}, request=request) | ||
self.assertFalse(form.is_valid()) | ||
|
||
def test_invalid_data_blank_group(self): | ||
request = self.factory.get('/ui/collections/create') | ||
request.user = self.user | ||
form = CollectionForm({ | ||
'name': 'my test collection', | ||
'description': 'my description', | ||
'group': '' | ||
}, request=request) | ||
self.assertFalse(form.is_valid()) |
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