-
Notifications
You must be signed in to change notification settings - Fork 997
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into 'master' to keep it up to date with the m…
…ost recent changes, mainly to address in a minor way #47, #66 and #105. Now the UI has a slightly different aspect, but the UX remains. I'll work on it in the future, adding things like django-channels support for a better realtime/asynchronous workflow. I guess I'll have to learn how to do it.
- Loading branch information
Showing
7 changed files
with
162 additions
and
38 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 |
---|---|---|
@@ -1,4 +1,13 @@ | ||
# PostgreSQL conf | ||
POSTGRES_PASSWORD=mysecretpass | ||
POSTGRES_USER=my_super_user | ||
POSTGRES_DB=bootcamp | ||
DATABASE_URL=postgresql://my_super_user:mysecretpass@127.0.0.1:5432/bootcamp | ||
|
||
# Main environmental variables | ||
DEBUG=True | ||
SECRET_KEY=s3cr3t_key | ||
DATABASE_URL=sqlite:////tmp/db.sqlite3 | ||
ALLOWED_HOSTS=* | ||
# Different URL to have sqlite example | ||
# DATABASE_URL=sqlite:////path/to/workspace/dir/db.sqlite3 | ||
ALLOWED_HOSTS=* | ||
REDIS_URL=redis://redis_ip_address:port |
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
File renamed without changes.
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,108 @@ | ||
from django.contrib.auth import get_user_model | ||
from django.http import HttpResponseBadRequest | ||
from django.core.urlresolvers import reverse | ||
from django.test import Client, TestCase | ||
|
||
from bootcamp.questions.models import Question, Answer | ||
|
||
|
||
class TestViews(TestCase): | ||
""" | ||
Includes tests for all the functionality | ||
associated with Views | ||
""" | ||
def setUp(self): | ||
self.client = Client() | ||
self.other_client = Client() | ||
self.user = get_user_model().objects.create_user( | ||
username='test_user', | ||
email='test@gmail.com', | ||
password='top_secret' | ||
) | ||
self.other_user = get_user_model().objects.create_user( | ||
username='other_test_user', | ||
email='other_test@gmail.com', | ||
password='top_secret' | ||
) | ||
self.client.login(username='test_user', password='top_secret') | ||
self.other_client.login( | ||
username='other_test_user', password='top_secret') | ||
self.question_one = Question.objects.create( | ||
user=self.user, title='This is a sample question', | ||
description='This is a sample question description', | ||
tags='test1,test2') | ||
self.question_two = Question.objects.create( | ||
user=self.user, | ||
title='A Short Title', | ||
description='''This is a really good content, just if somebody | ||
published it, that would be awesome, but no, nobody wants to | ||
publish it, because they know this is just a test, and you | ||
know than nobody wants to publish a test, just a test; | ||
everybody always wants the real deal.''', | ||
favorites=0, | ||
has_accepted_answer=True | ||
) | ||
self.answer = Answer.objects.create( | ||
user=self.user, | ||
question=self.question_two, | ||
description='A reaaaaally loooong content', | ||
votes=0, | ||
is_accepted=True | ||
) | ||
|
||
def test_index_questions(self): | ||
response = self.client.get(reverse('questions')) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertTrue( | ||
'This is a sample question' in str(response.context['question'])) | ||
|
||
def test_create_question_view(self): | ||
""" | ||
""" | ||
current_question_count = Question.objects.count() | ||
response = self.client.post(reverse('ask'), | ||
{'title': 'Not much of a title', | ||
'description': 'babla', | ||
'tags': 'test, tag'}) | ||
self.assertEqual(response.status_code, 302) | ||
new_question = Question.objects.first() | ||
self.assertEqual(new_question.title, 'Not much of a title') | ||
self.assertEqual(Question.objects.count(), | ||
current_question_count + 1) | ||
|
||
def test_answered_questions(self): | ||
response = self.client.get(reverse('answered')) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertTrue('A Short Title' in str(response.context['question'])) | ||
|
||
def test_all_questions_view(self): | ||
response = self.client.get(reverse('all')) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertTrue('A Short Title' in str(response.context['question'])) | ||
|
||
def test_individual_question(self): | ||
response = self.client.get( | ||
'/questions/{}/'.format(self.question_one.id)) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertTrue( | ||
'This is a sample question' in str(response.context['question'])) | ||
|
||
def test_answer_question(self): | ||
current_answer_count = Answer.objects.count() | ||
response = self.client.post( | ||
reverse('answer'), | ||
{'question': self.question_one.id, | ||
'description': 'A reaaaaally loooong content'}) | ||
self.assertEqual(response.status_code, 302) | ||
self.assertEqual(Answer.objects.count(), current_answer_count + 1) | ||
|
||
def test_empty_answer(self): | ||
current_answer_count = Answer.objects.count() | ||
response = self.client.post(reverse('answer'), | ||
{'question': self.question_one.id}) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(Answer.objects.count(), current_answer_count) | ||
|
||
def test_answer_redirects(self): | ||
response = self.other_client.get(reverse('answer')) | ||
self.assertRedirects(response, reverse('questions'), status_code=302) |
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,19 @@ | ||
postgres: | ||
image: postgres | ||
volumes: | ||
# If you are using boot2docker, postgres data has to live in the VM for now until #581 is fixed | ||
# for more info see here: https://github.com/boot2docker/boot2docker/issues/581 | ||
- /data/bootcamp/postgres:/var/lib/postgresql/data | ||
version: '2' | ||
|
||
django: | ||
build: . | ||
command: python /bootcamp/manage.py runserver 0.0.0.0:8000 | ||
volumes: | ||
- .:/bootcamp | ||
ports: | ||
- "8000:8000" | ||
links: | ||
- postgres | ||
volumes: | ||
postgres_data: {} | ||
|
||
services: | ||
|
||
postgres: | ||
image: postgres:latest | ||
volumes: | ||
- postgres_data:/var/lib/postgresql/data | ||
env_file: .env | ||
ports: | ||
- '5432:5432' | ||
|
||
redis: | ||
image: redis:3.0 | ||
ports: | ||
- '6379:6379' |