def test_insert_news(self): name = "test suitcase" Topics_model.db_insert_one_topic(name) topic_obj = Topics_model.db_get_one_topic_by_name(name) c_date = timezone.now() News_model.db_insert_one_news(_title="test news title", _news_date=c_date, _summary="testing_news_summary_16", _news_url="wwww.google", _topic=topic_obj, _image_url="https://pbs.twimg.com/profile_images/626307178563960833/lKjVudoW.jpg")
def cluster_test_flow(): try: test_topic_name = "White House Press Secretary" test_topic = Topics_model.db_get_one_topic_by_name(test_topic_name) if test_topic is None: return None one_topic_news_dynamic_cluster_flow(test_topic) except Exception as e: logger.error("cluster_test_flow() failed: " + str(e))
def generate_news(topic): topic_obj = Topics_model.db_get_one_topic_by_name(topic) news_date = timezone.now() news_url = "https://www.google.ie/" img_url = "http://lorempixel.com/400/250/" if topic_obj is not None: for i in range(3): news_title = topic + " - news - " + str(i) summary = topic + " - news summary - " + str(i) News_model.db_insert_one_news(news_title, news_date, summary, news_url, topic_obj, img_url)
def latest_cluster_time_mark_clean(): try: test_topic_name = "White House Press Secretary" test_topic = Topics_model.db_get_one_topic_by_name(test_topic_name) if test_topic is None: return None test_topic.latest_filter_time = None test_topic.latest_cluster_time = None test_topic.save() Model_Interfaces.db2_get_filter_news_of_one_topic( test_topic.id).delete() except Exception as e: logger.error("latest_cluster_time_mark_clean() failed: " + str(e))
def generate_ori_news(topic): topic_obj = Topics_model.db_get_one_topic_by_name(topic) current_date = timezone.now() news_url = "https://www.google.ie/" img_url = "http://lorempixel.com/400/250/" if topic_obj is not None: for day in range(1, 5): news_date = current_date - timedelta(days=day) for i in range(randint(0, 6)): news_title = topic + " - day - " + str( day) + " - news - " + str(i) summary = topic + " - day - " + str( day) + " - news summary - " + str(i) Ori_News_model.db_insert_one_news(news_title, news_date, summary, news_url, topic_obj, img_url)
def db2_add_new_topics(topic_name_list): flag = -1 add_list = [] fail_list = [] if topic_name_list is not None: try: for name in topic_name_list: topic = Topics_model.db_insert_one_topic(name) if topic == None: fail_list.append(name) flag = 0 else: add_list.append(name) if add_list == topic_name_list: flag = 1 for e_name in fail_list: topic = Topics_model.db_get_one_topic_by_name(e_name) if topic is not None: topic.db_update_recent_hot_date() except Exception as e: logger.error("db2_add_new_topics failed: " + str(e)) return flag, add_list, fail_list return flag, add_list, fail_list
def test_get_topic_unexist_name(self): name = "Test topic 0" topic_check = Topics_model.db_get_one_topic_by_name(name) self.assertIsNone(topic_check)
def test_get_topic_name(self): name = self.topic.topic_name topic_check = Topics_model.db_get_one_topic_by_name(name) self.assertEqual(name, topic_check.topic_name)
print("Test Name : Get one topic by not exist id") print("Expect Output: [*] DoesNotExist & None") id = 1 print("Actual Output:") topic = Topics_model.db_get_one_topic_by_id(id) print(topic) # test 5 -- test 4.1.2.3 # Test Name: Get one topic by its name # Expect Output: topic's name print("\ntest 5 -- test 4.1.2.3") print("Test Name : Get one topic by its name") print("Expect Output: topic's name & id") print("Actual Output:") name = "Science" topic = Topics_model.db_get_one_topic_by_name(name) print(topic.id) # test 6 -- test 4.1.2.3 # Test Name: Get one topic by not exist name # Expect Output: [*] IntegrityError & None print("\ntest 6 -- test 4.1.2.3") print("Test Name : Get one topic by not exist name") print("Expect Output: [*] DoesNotExist & None") print("Actual Output:") name = "Technology" topic = Topics_model.db_get_one_topic_by_name(name) print(topic) # test 7 -- test 4.1.2.4 # Test Name: successfully update