def testAccount(self): Doc.objects(name=DOC_NAME)[0].delete( ) #strange bug happens when full collection from db is deleted :| logger.debug('Start TestUI::testAccount.') USER_NAME = 'testLogin' driver = self.driver driver.get(self.base_url) time.sleep(1) driver.find_element_by_css_selector("i.fa.fa-sign-in").click() time.sleep(1) driver.find_element_by_id("id_username").clear() driver.find_element_by_id("id_username").send_keys(USER_NAME) driver.find_element_by_id("id_password").clear() driver.find_element_by_id("id_password").send_keys(USER_NAME) driver.find_element_by_css_selector("input[type=\"submit\"]").click() time.sleep(1) self.assertEqual( "Your username and password didn't match. Please try again.", driver.find_element_by_css_selector("p").text) User.create_user(USER_NAME, USER_NAME) time.sleep(1) driver.get(self.base_url) time.sleep(1) driver.find_element_by_css_selector("i.fa.fa-sign-in").click() time.sleep(1) driver.find_element_by_id("id_username").clear() driver.find_element_by_id("id_username").send_keys(USER_NAME) driver.find_element_by_id("id_password").clear() driver.find_element_by_id("id_password").send_keys(USER_NAME) driver.find_element_by_css_selector("input[type=\"submit\"]").click() time.sleep(1) self.assertEqual("Welcome, " + USER_NAME + ".", driver.find_element_by_css_selector("p").text) PRIVATE_DOC_NAME = "prywatny" driver.find_element_by_class_name("has-menu").click() driver.find_element_by_id("newDocumentMenu").click() time.sleep(1) driver.find_element_by_id("documentNameAtStart").clear() driver.find_element_by_id("documentNameAtStart").send_keys( PRIVATE_DOC_NAME) driver.find_element_by_id("privateFlagAtStart").click() driver.find_element_by_id("saveDocumentButtonAtStart").click() time.sleep(10) logger.debug('Critical point of TestUI::testAccount.') doc = Doc.objects(name=PRIVATE_DOC_NAME)[0] self.assertEqual(doc.name, PRIVATE_DOC_NAME) self.assertTrue(doc.priv) driver.get(self.base_url) time.sleep(1) driver.find_element_by_class_name("has-menu").click() driver.find_element_by_id("documentListButton").click() time.sleep(1) self.assertEqual(PRIVATE_DOC_NAME, driver.find_element_by_css_selector("td").text) driver.find_element_by_id('accounts').click() driver.find_element_by_id("logout").click() time.sleep(1) with self.assertRaises(NoSuchElementException): driver.find_element_by_css_selector("td") logger.debug('End TestUI::testAccount.')
def testCreateDocument(self): create_document({}, DOC_NAME, '') doc = Doc.objects(name=DOC_NAME)[0] self.assertTrue(doc.text == '') self.assertTrue(doc.name == DOC_NAME) Doc.objects.delete() create_document({}, DOC_NAME, 'test') doc = Doc.objects(name=DOC_NAME)[0] self.assertTrue(doc.text == 'test') self.assertTrue(doc.name == DOC_NAME)
def testHandleCreateDocument(self): msg = {'name': DOC_NAME, 'text': EMPTY_DOC_STRING, 'priv': False} handle_create_document(msg, {}) id = msg['id'] created_document = Doc.objects(id=id)[0] self.assertTrue(created_document['name'] == DOC_NAME) self.assertTrue(created_document['text'] == EMPTY_DOC_STRING) msg = {'name': DOC_NAME, 'text': SAMPLE_TEXT, 'priv': False} handle_create_document(msg, {}) id = msg['id'] created_document = Doc.objects(id=id)[0] self.assertTrue(created_document['name'] == DOC_NAME) self.assertTrue(created_document['text'] == SAMPLE_TEXT)
def testSaveAs(self): Doc(name=DOC_NAME + '1', text=LOREM_IPSUM).save() logger.debug('TestUI::testSaveAs documents: ' + str(Doc.objects())) driver = self.driver time.sleep(1) driver.get(self.base_url) time.sleep(1) driver.find_element_by_css_selector("td").click() time.sleep(1) driver.find_element_by_id("saveDocument").click() time.sleep(1) driver.find_element_by_id("documentName").clear() driver.find_element_by_id("documentName").send_keys(DOC_NAME) driver.find_element_by_id("saveDocumentButton").click() self.assertTrue(Doc.objects(name=DOC_NAME)[0]['text'] == LOREM_IPSUM)
def testRemoveText(self): doc = Doc(name=DOC_NAME, last_change=datetime.datetime.now(), text=SAMPLE_TEXT).save() creation_date = doc.last_change remove_text(doc, 'Uzytkownik', 0) doc = Doc.objects(name=DOC_NAME)[0] logger.debug('TestDBManager::testRemoveText compare ' + str(creation_date) + ' and ' + str(doc.last_change)) self.assertTrue(creation_date < doc.last_change) self.assertTrue(doc.text[0] == ' ') Doc.objects.delete() doc = Doc(name=DOC_NAME, text="ok").save() remove_text(doc, 'o', 0) remove_text(doc, 'k', 0) self.assertTrue(Doc.objects(name=DOC_NAME)[0].text == '')
def testInsertText(self): doc = Doc(name=DOC_NAME, last_change=datetime.datetime.now(), text=SAMPLE_TEXT).save() creation_date = doc.last_change insert_text(doc, 'A', 3) doc = Doc.objects(name=DOC_NAME)[0] logger.debug('TestDBManager::testInsertText compare ' + str(creation_date) + ' and ' + str(doc.last_change)) self.assertTrue(creation_date < doc.last_change) self.assertTrue(doc.text[3] == 'A') Doc.objects.delete() doc = Doc(name=DOC_NAME, text="").save() insert_text(doc, 'k', 0) insert_text(doc, 'o', 0) self.assertTrue(Doc.objects(name=DOC_NAME)[0].text == 'ok')
def testPolishCharacters(self): doc = Doc(name=DOC_NAME, last_change=datetime.datetime.now(), text=SAMPLE_TEXT).save() remove_text(doc, u'Użytkownik', 0) doc = Doc.objects(name=DOC_NAME)[0] self.assertTrue(doc.text[0] == ' ')
def testHandleMsg(self): doc = Doc(name=DOC_NAME, last_change=datetime.datetime.now(), text=SAMPLE_TEXT).save() handle_msg({'type': 'i', 'pos': 0, 'text': 'ala'}, doc['id']) doc = Doc.objects(name=DOC_NAME)[0] self.assertTrue(doc.text[:3] == 'ala') Doc.objects.delete() doc = Doc(name=DOC_NAME, last_change=datetime.datetime.now(), text=SAMPLE_TEXT).save() handle_msg({'type': 'r', 'pos': 0, 'text': u'Użytkownik'}, doc['id']) doc = Doc.objects(name=DOC_NAME)[0] print doc.text[0] self.assertTrue(doc.text[0] == ' ') with self.assertRaisesMessage(Http404, 'No Document matches the given query.'): handle_msg({}, 'not_exisitng')
def testNewDocument(self): Doc(name=DOC_NAME + '1', text=LOREM_IPSUM).save() driver = self.driver time.sleep(1) driver.get(self.base_url) time.sleep(1) driver.find_element_by_css_selector("td").click() time.sleep(1) driver.find_element_by_id("newDocument").click() time.sleep(1) driver.find_element_by_id("documentName").clear() driver.find_element_by_id("documentName").send_keys(DOC_NAME) driver.find_element_by_id("saveDocumentButton").click() self.assertTrue( Doc.objects(name=DOC_NAME)[0]['text'] == EMPTY_DOC_STRING)
def calc_idf(self, word: Word): documents_count = Document.objects().count() documents_occur = len(word.documents) return math.log(documents_count / (documents_occur + 0.0001))