def test_re(self): w = Wklejka() w.save() url = reverse("reply", kwargs={"id": w.id}) response = self.client.get(url) self.assertEquals(response.status_code, 200) self.assertTemplateUsed(response, "homepage.dhtml")
def test_public_url(self): w = Wklejka(is_private=False, user=self.user) w.save() self.get(w) self.get_txt(w) self.get_dl(w) self.get_del(w) self.post_del(w)
def test_children_count(self): parent = Wklejka() parent.save() self.assertEquals(parent.children_count(), 0) child = Wklejka(parent=parent) child.save() self.assertEquals(parent.children_count(), 1)
def test_is_parent(self): parent = Wklejka() parent.save() self.assertFalse(parent.is_parent()) child = Wklejka(parent=parent) child.save() self.assertTrue(parent.is_parent())
def test_private_url(self): w = Wklejka(is_private=True, hash="foobar", user=self.user) w.save() self.get(w) self.get_txt(w) self.get_dl(w) self.get_del(w) self.post_del(w)
def dodaj_wpis(tresc, syntax, autor="Anonim"): """ Pozwala zdalnie dodawac wpisy do wkleja. """ w = Wklejka(nickname=autor, body=tresc, syntax=syntax) w.save() return w.get_absolute_url()
def auth_dodaj_wpis(tresc, syntax, salt): """ Pozwala zdalnei dodawac wpisy do konta """ try: p = UserProfile.objects.get(current_salt=salt) except: return dodaj_wpis(tresc, syntax) w = Wklejka(nickname=p.username(), body=tresc, syntax=syntax, user=p.user) w.save() return w.get_absolute_url()
def test_is_child(self): parent = Wklejka() parent.save() child = Wklejka() child.save() self.assertFalse(child.is_child()) child.parent = parent self.assertTrue(child.is_child())
def test_author(self): user = User(username="******") self.wklejka = Wklejka( user=user, nickname="Anonymous", body="Foobar", ) self.assertEqual(self.wklejka.author, user) self.wklejka = Wklejka( nickname="Anonymous", body="Foobar", ) self.assertEqual(self.wklejka.author, "Anonymous")
def test_get_del_url(self): w = Wklejka(hash="foobar", is_private=True) w.save() self.assertEqual(w.get_del_url(), "/hash/{}/delete/".format(w.hash)) w.is_private = False self.assertEqual(w.get_del_url(), "/id/{}/delete/".format(w.id))
def dodaj_prywatny_wpis(tresc, syntax, autor="Anonim"): """ Pozwala zdalnie dodawać prywatne wpisy do wkleja """ w = Wklejka(nickname=autor, body=tresc, syntax=syntax, is_private=True) w.save() salt = sha.new(str(random.random())).hexdigest()[:10] hash = sha.new(salt).hexdigest()[:10] w.hash = hash w.save() return w.get_absolute_url()
def auth_dodaj_prywatny_wpis(tresc, syntax, salt): """ Pozwala zdalnei dodawac wpisy do konta """ try: p = UserProfile.objects.get(current_salt=salt) except: return dodaj_prywatny_wpis(tresc, syntax) w = Wklejka(nickname=p.username(), body=tresc, syntax=syntax, user=p.user, is_private=True) w.save() salt = sha.new(str(random.random())).hexdigest()[:10] hash = sha.new(salt).hexdigest()[:10] w.hash = hash w.save() return w.get_absolute_url()
def test_get_10_lines(self): w = Wklejka(body="\n".join("abcdefghijklmn")) self.assertEqual(w.get_10_lines().splitlines()[-1], "j")
def test_hl(self): w = Wklejka(syntax="python") self.assertEqual(w.hl, "python") w = Wklejka(syntax="", guessed_syntax="perl") self.assertEqual(w.hl, "perl")
def test_banned_lexer(self): w = Wklejka(syntax="raw") w.save() self.get(w)
def test_get_id_url(self): w = Wklejka() w.save() self.assertEqual(w.get_id_url(), "/id/{}/".format(w.id))
def handle(self, how_many=100, **options): for i in range(int(how_many)): w = Wklejka(**wklejka()) w.save() print "WKLEJKA", w.id
def test_get_hash_url(self): w = Wklejka(hash="foobar") w.save() self.assertEqual(w.get_hash_url(), "/hash/foobar/")