def test_create_category(self): t = 'uniqTitle' c1 = Category(title=t) c2 = Category(title=t) c1.save() try: c2.save() except: pass else: self.fail('Should not have two categories with same title')
def setUp(self): self.client = Client() self.category = Category(title='cat') self.category.save() self.entries = Entry.objects.all() self.categories = Category.objects.all()
def test_delete_category(self): category = Category(title='Cat') category.save() entries = self._generate_entries(50) self._assign_category(entries, category) for e in entries: e.save() f = Entry.objects.filter(category=category)[0] self.assertEquals(f.category_id, category.id) id = category.id category.delete() self.assertEquals(len(Entry.objects.filter(category_id=id)), 0)
def setUp(self): e = Entry(title='Twitter', username='******', url='twitter.com', password='******', comment='no comment') c = Category(title='Internet', parent=None) self.entry = e self.category = c c.save() e.category = c e.save()
def test_save_entry_with_encrypted_key(self): c = Category(title='Internet') c.save() for i, password in enumerate(self.texts): password_after_encryption = self.engine.encrypt(password) title = 'My Twitter Account: ' + str(i) e = Entry(title=title, username='******', url='twitter.com', password=password_after_encryption, comment='no comment') e.category = c e.save() # Fetches the saved entry f = Entry.objects.filter(title=title)[0] password_decrypted = self.engine.decrypt(f.password) self.assertEquals(password_after_encryption, f.password) self.assertEquals(password_decrypted, password) f.delete()
def test_entry_add(self): self._authentificate() cat = Category(title='New cat') cat.save() entries = self._generate_entries(20, cat) # Test good insertions for e in entries: s = { 'title': e.title, 'password': e.password, 'category': e.category.id } response = self.client.post('/api/entry/add', s) self.assertEquals(response.status_code, 200) self.assertEquals(response.content, '1') entry_from_db = Entry.objects.filter(title=e.title) e2 = entry_from_db[0] self.assertTrue(len(entry_from_db) >= 1) self.assertEquals(e2.title, s['title']) self.assertEquals(e2.password, s['password']) self.assertEquals(e2.category.id, s['category']) # Test bad insertions s = [ { 'title': 'test', 'category': self.category.id }, { 'password': '******', 'category': self.category.id }, { 'password': '******', 'title': 'test' }, { 'password': '******' }, { 'title': 't' }, { 'category': self.category.id }, { 'password': '******', 'title': 'test', 'category': self.category.id + 1000 }, ] for bad in s: response = self.client.post('/api/entry/add', bad) self.assertEquals(response.status_code, 200) self.assertEquals(response.content, '0') # Test dates title = str(random.random()) date = '06/14/2025' s = { 'title': title, 'password': '******', 'category': e.category.id, 'expires': date } response = self.client.post('/api/entry/add', s) self.assertEquals(response.status_code, 200) self.assertEquals(response.content, '1') entry_from_db = Entry.objects.filter(title=title)[0] self.assertEquals(entry_from_db.expires, datetime.datetime.strptime(date, "%m/%d/%Y").date())