import unittest
import redis
import pprint
from vote import *

class TestSimpleRedis(unittest.TestCase):
	def setUp(self):
		pool = redis.ConnectionPool(host='localhost', port=6379, db=15)
		self.conn = redis.Redis(connection_pool=pool)

	def tearDown(self):
		del self.conn
		print
		print

	def test_article_functionality(self):
		conn = self.conn
		article_id = str(post_article(conn, 'username', 'A title', 'http://www.google.com'))
		print "We posted a new article with id:", article_id
		print
		self.assertTrue(article_id)
		print "Its HASH looks like:"
		r = conn.hgetall('article:' + article_id)
		print r
		print
		self.assertTrue(r)
		article_vote(conn, 'other_user', 'article:' + article_id)
		print "We voted for the article, it now has votes:",
		v = int(conn.hget('article:' + article_id, 'votes'))
		print v
		print
		self.assertTrue(v > 1)
		print "The currently highest-scoring articles are:"
		articles = get_articles(conn, 1)
		pprint.pprint(articles)
		print

		self.assertTrue(len(articles) >= 1)
		add_remove_groups(conn, article_id, ['new-group'])
		print "We added the article to a new group, other articles include:"
		articles = get_group_articles(conn, 'new-group', 1)
		pprint.pprint(articles)
		print

		self.assertTrue(len(articles) >= 1)
		to_del = (
			conn.keys('time:*') + conn.keys('voted:*') + conn.keys('score:*') +
			conn.keys('article:*') + conn.keys('group:*')
			)
		if to_del:
			conn.delete(*to_del)

import unittest
import redis
import pprint
from vote import *

class TestSimpleRedis(unittest.TestCase):
	def setUp(self):
		pool = redis.ConnectionPool(host='localhost', port=6379, db=15)
		self.conn = redis.Redis(connection_pool=pool)

	def tearDown(self):
		del self.conn
		print
		print

	def test_article_functionality(self):
		conn = self.conn
		article_id = str(post_article(conn, 'username', 'A title', 'http://www.google.com'))
		print "We posted a new article with id:", article_id
		print
		self.assertTrue(article_id)
		print "Its HASH looks like:"
		r = conn.hgetall('article:' + article_id)
		print r
		print
		self.assertTrue(r)
		article_vote(conn, 'other_user', 'article:' + article_id)
		print "We voted for the article, it now has votes:",
		v = int(conn.hget('article:' + article_id, 'votes'))
		print v
		print
		self.assertTrue(v > 1)
		print "The currently highest-scoring articles are:"
		articles = get_articles(conn, 1)
		pprint.pprint(articles)
		print

		self.assertTrue(len(articles) >= 1)
		add_remove_groups(conn, article_id, ['new-group'])
		print "We added the article to a new group, other articles include:"
		articles = get_group_articles(conn, 'new-group', 1)
		pprint.pprint(articles)
		print

		self.assertTrue(len(articles) >= 1)
		to_del = (
			conn.keys('time:*') + conn.keys('voted:*') + conn.keys('score:*') +
			conn.keys('article:*') + conn.keys('group:*')
			)
		if to_del:
			conn.delete(*to_del)
