Skip to content

Commit

Permalink
added delete complained word from global dictionary test
Browse files Browse the repository at this point in the history
removed unused redirrects
issue #6
  • Loading branch information
i-pavlov committed Apr 6, 2014
1 parent 4d78306 commit 5541b8e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
2 changes: 0 additions & 2 deletions handlers/complain_word_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def __init__(self, *args, **kwargs):
def post(self, *args, **kwargs):
deleted_word = self.request.get("word")
ndb.delete_multi(ComplainedWord.query(ComplainedWord.word == deleted_word).fetch(keys_only=True))
self.redirect("/admin/complain/list")


class DeleteFromGlobalDictionaryHandler(AdminRequestHandler):
Expand All @@ -75,7 +74,6 @@ def post(self, *args, **kwargs):
word.tags += "-deleted"
word.put()
ndb.delete_multi(ComplainedWord.query(ComplainedWord.word == data).fetch(keys_only=True))
self.redirect("/admin/complain/list")



28 changes: 27 additions & 1 deletion tests/complain_word_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import unittest2

from objects.complained_word import ComplainedWord
from objects.global_dictionary_word import GlobalDictionaryWord
from google.appengine.ext import ndb
from tests.base_functions import *
import main
import os

Expand Down Expand Up @@ -85,14 +88,37 @@ def test_erase(self):
len_before = ComplainedWord.query().count()
response = request.get_response(main.app)

self.assertEqual(response.status_int, 302) # not 200, because redirrect
self.assertEqual(response.status_int, 200)
len_after = ComplainedWord.query().count()
self.assertEqual(len_before, len_after + 2)
request = webapp2.Request.blank('/admin/complain/clear')
request.method = 'POST'
response = request.get_response(main.app)
self.assertEqual(ComplainedWord.query().count(), 0)

def test_delete_from_global_dictionary(self):
words = ["a", "b", "c", "d"]
for i in words:
GlobalDictionaryWord(word=i, id=i, tags="").put()
ComplainedWord(word="c").put()
ComplainedWord(word="c").put()
ComplainedWord(word="d").put()
request = make_request("/admin/complain/remove", "POST", True, 'word=c')
response = request.get_response(main.app)
self.assertEqual(response.status_int, 200)
self.assertEqual(ComplainedWord.query().count(), 1)
self.assertEqual(GlobalDictionaryWord.query().count(), 4)
self.assertEqual(ndb.Key(GlobalDictionaryWord, "c").get().tags, "-deleted")

ComplainedWord(word="c").put()
response = request.get_response(main.app)
self.assertEqual(ComplainedWord.query().count(), 1)
self.assertEqual(GlobalDictionaryWord.query().count(), 4)
self.assertEqual(ndb.Key(GlobalDictionaryWord, "c").get().tags, "-deleted")




def tearDown(self):
complain_word_test.logoutCurrentUser()
self.testbed.deactivate()
Expand Down
3 changes: 2 additions & 1 deletion tests/userdictionary_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def test_different_users_iteraction(self):
request.method = "GET"
response = request.get_response(main.app)
diff = json.loads(response.body)
self.assertEqual(len(diff["words"]), expected_counts[i], msg="count mismatch with device {}. expected {} found {}".format(i, expected_counts[i], len(diff["words"])))
self.assertEqual(len(diff["words"]), expected_counts[i],
msg="count mismatch with device {}. expected {} found {}".format(i, expected_counts[i], len(diff["words"])))

def tearDown(self):
self.testbed.deactivate()
Expand Down

0 comments on commit 5541b8e

Please sign in to comment.