-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
120 lines (100 loc) · 6.34 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import hacker_news_scraping as hns
import helping_functions as hf
import unittest
from HN_Data import HNData
from tests_helping_functions import*
import hacker_news_scraping as hns
from bs4 import BeautifulSoup as bs
class TestHNS(unittest.TestCase):
""" A class for testing the hacker_news_scraping data."""
def test_simple_get_for_valid_html(self):
""" Tests that the url is a good response."""
result = hns.simple_get("https://news.ycombinator.com/not-an-html") is None
self.assertEqual(result, True, "The uri is not a good response.")
def test_validate_fetched_record_with_valid_data(self):
""" Tests if all the data are correctly fetched."""
hn_data_obj = initialize_hn_valid_object()
result = hf.validate_fetched_record(hn_data_obj)
self.assertEqual(result, True, msg= "One or more data haven't fetched correctly.")
def test_validate_fetched_record_with_invalid_title_empty(self):
""" Tests if the title is an empty string."""
hn_data_obj = initialize_hn_obj_invalid_title_empty()
result = hf.validate_fetched_record(hn_data_obj)
self.assertEqual(result, False, msg= "The title can't be empty.")
def test_validate_fetched_record_with_invalid_title_number(self):
""" Tests if the title is a number."""
hn_data_obj = initialize_hn_obj_invalid_title_number()
result = hf.validate_fetched_record(hn_data_obj)
self.assertEqual(result, False, msg= "The title can't be a number.")
def test_validate_fetched_record_with_invalid_title_too_long(self):
""" Tests if the title is too long."""
hn_data_obj = initialize_hn_obj_invalid_title_too_long()
result = hf.validate_fetched_record(hn_data_obj)
self.assertEqual(result, False, msg= "The title can't be more then 256 characters.")
def test_validate_fetched_record_with_invalid_author_name_empty(self):
""" Tests if the author's name is an empty string."""
hn_data_obj = initialize_hn_obj_invalid_author_name_empty()
result = hf.validate_fetched_record(hn_data_obj)
self.assertEqual(result, False, msg= "The author's name can't be empty.")
def test_validate_fetched_record_with_invalid_author_name_number(self):
""" Tests if the author's name is not a number."""
hn_data_obj = initialize_hn_obj_invalid_author_name_number()
result = hf.validate_fetched_record(hn_data_obj)
self.assertEqual(result, False, msg= "The author's name can't be a number.")
def test_validate_fetched_record_with_invalid_author_name_too_long(self):
""" Tests if the author's name is not too long."""
hn_data_obj = initialize_hn_obj_invalid_author_name_too_long()
result = hf.validate_fetched_record(hn_data_obj)
self.assertEqual(result, False, msg= "The author's name can't be more then 256 characters.")
def test_validate_fetched_record_with_invalid_points_characters(self):
""" Tests if the points are characters."""
hn_data_obj = initialize_hn_obj_invalid_points_character()
result = hf.validate_fetched_record(hn_data_obj)
self.assertEqual(result, False, msg= "The points can't be characters.")
def test_validate_fetched_record_with_invalid_points_negative_number(self):
""" Tests if the points are a negative number."""
hn_data_obj = initialize_hn_obj_invalid_points_negative_number()
result = hf.validate_fetched_record(hn_data_obj)
self.assertEqual(result, False, msg= "The points can't be a negative number.")
def test_validate_fetched_record_with_invalid_points_not_integer(self):
""" Tests if the points are an integer number."""
hn_data_obj = initialize_hn_obj_invalid_points_not_integer()
result = hf.validate_fetched_record(hn_data_obj)
self.assertEqual(result, False, msg= "The points must be an integer.")
def test_validate_fetched_record_with_invalid_comments_characters(self):
""" Tests if the numbers of comments are characters."""
hn_data_obj = initialize_hn_obj_invalid_comments_character()
result = hf.validate_fetched_record(hn_data_obj)
self.assertEqual(result, False, msg= "The points can't be characters.")
def test_validate_fetched_record_with_invalid_comments_negative_number(self):
""" Tests if the number of comments are a negative number."""
hn_data_obj = initialize_hn_obj_invalid_comments_negative_number()
result = hf.validate_fetched_record(hn_data_obj)
self.assertEqual(result, False, msg= "The points can't be a negative number.")
def test_validate_fetched_record_with_invalid_comments_not_integer(self):
""" Tests if the number of comments are an integer number."""
hn_data_obj = initialize_hn_obj_invalid_comments_not_integer()
result = hf.validate_fetched_record(hn_data_obj)
self.assertEqual(result, False, msg= "The points must be an integer.")
def test_validate_fetched_record_with_invalid_rank_character(self):
""" Tests if the rank is characters."""
hn_data_obj = initialize_hn_obj_invalid_rank_character()
result = hf.validate_fetched_record(hn_data_obj)
self.assertEqual(result, False, msg= "The rank can't be characters.")
def test_validate_fetched_record_with_invalid_rank_negative_number(self):
""" Tests if the rank is a negative number."""
hn_data_obj = initialize_hn_obj_invalid_rank_negative_number()
result = hf.validate_fetched_record(hn_data_obj)
self.assertEqual(result, False, msg= "The rank can't be a negative number.")
def test_validate_fetched_record_with_invalid_rank_not_integer(self):
""" Tests if the rank are an integer number."""
hn_data_obj = initialize_hn_obj_invalid_rank_not_integer()
result = hf.validate_fetched_record(hn_data_obj)
self.assertEqual(result, False, msg= "The rank must be an integer.")
def test_store_all_returns_list(self):
""" Tests that the store_all_data func returns a list of objects."""
hn_data_obj = initialize_hn_valid_object()
result = hns.store_all_data(2, hn_data_obj)
self.assertEqual(isinstance(result, list), True, "The store_all_data doesn't return a list.")
"""Provide a command-line interface to the test script."""
unittest.main()