Ejemplo n.º 1
0
 def db2_get_all_topics(start_id, amount):
     topic_list = []
     count = 0
     last_id = None
     for i in range(start_id, start_id + amount):
         topic = Topics_model.db_get_one_topic_by_id(i)
         if topic is not None:
             topic_list.append(topic)
             count = count + 1
             last_id = topic.id
     return topic_list, amount, count, last_id
Ejemplo n.º 2
0
 def db2_add_one_filter_news(news_date, news_title, news_summary,
                             news_topic_id, news_url, image_rul):
     if len(news_summary) < 200:
         return None
     if len(image_rul) < 3:
         return None
     flag = -1
     topic = Topics_model.db_get_one_topic_by_id(news_topic_id)
     if topic is not None:
         news = News_model.db_insert_one_news(news_title, news_date,
                                              news_summary, news_url, topic,
                                              image_rul)
         if news is not None:
             flag = 1
             topic.latest_filter_time = timezone.now()
             topic2 = Topics_model.db_update_one_topic(topic)
     else:
         news = None
         topic = None
     return flag, news, topic
Ejemplo n.º 3
0
 def test_get_topic_name_by_id(self):
     id = self.topic.id
     name = self.topic.topic_name
     topic_check = Topics_model.db_get_one_topic_by_id(id)
     # self.assertIsNotNone(topic_check)
     self.assertEqual(name, topic_check.topic_name)
Ejemplo n.º 4
0
 def test_get_topic_name_by_unexist_id(self):
     id = 100
     name = self.topic.topic_name
     topic_check = Topics_model.db_get_one_topic_by_id(id)
     self.assertIsNone(topic_check)
Ejemplo n.º 5
0
print(topic)

#if topic is not None:
#    topic.delete()
#print("All topics:")
#print(Topics_model.objects.all())

# test 3 -- test 4.1.2.2
# Test Name: Get one topic by its id
# Expect Output: topic's name
print("\ntest 3 -- test 4.1.2.2")
print("Test Name : Get one topic by its id")
print("Expect Output: topic's id & name")
id = 2
print("Actual Output:")
topic = Topics_model.db_get_one_topic_by_id(id)
if topic is not None:
    print(topic.id)
print(topic)

# test 4 -- test 4.1.2.2
# Test Name: Get one topic by not exist id
# Expect Output: [*] IntegrityError & None
print("\ntest 4 -- test 4.1.2.2")
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)