Skip to content

Commit

Permalink
- Refactored tests that require files to be loaded to use absolute pa…
Browse files Browse the repository at this point in the history
…th so it is consistent between tests

- Added google-api-python-client as a python dependency
  • Loading branch information
Marethyu1 committed Dec 15, 2018
1 parent 19f9bac commit ee2d9f1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
randomwords
randomwords
google-api-python-client
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
history = history_file.read()

requirements = [
"randomwords"
"randomwords",
"google-api-python-client"
]

setup_requirements = [
Expand Down
29 changes: 20 additions & 9 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@
"""

import unittest
import os

from coast_search import search
from coast_search import utils


class TestSearch(unittest.TestCase):

def setUp(self):
# using abspath means there is consistency between running running ```python setup.py test``` and tests
# through ide
cwd = os.path.dirname(os.path.abspath(__file__))
self.test_data_folder_location = os.path.join(cwd, "test_data/")

def test_write_to_file_json(self):
# I wrote these to produce a file that I then manually checked.
Expand All @@ -26,17 +32,22 @@ def test_write_to_file_txt(self):
search.write_to_file("test_file", test_string, "../tests/test_output", ".txt")

def test_extract_search_results_from_JSON(self):
filename = "../tests/test_data/results_for_testing_extraction.json"
json_data = utils.get_json_from_file(filename)
filename = "results_for_testing_extraction.json"
filepath = os.path.join(self.test_data_folder_location, filename)
json_data = utils.get_json_from_file(filepath)

result = search.extract_search_results_from_JSON(json_data)
expected = utils.get_json_from_file('../tests/test_data/expected_results.json')
expected_results_filename = "expected_results.json"
expected_results_filpath = os.path.join(self.test_data_folder_location, expected_results_filename)
expected = utils.get_json_from_file(expected_results_filpath)

self.assertEqual(expected, result)

def test_deduplicate_urls_no_repetiton_between_segments(self):
filename = "../tests/test_data/results_for_testing_dedup.json"
json_data = utils.get_json_from_file(filename)
filename = "results_for_testing_dedup.json"
filepath = os.path.join(self.test_data_folder_location, filename)

json_data = utils.get_json_from_file(filepath)
deduplicated_urls_object = search.deduplicate_urls(json_data)
deduplicated_urls_list = deduplicated_urls_object["deduplicated_urls"]

Expand All @@ -57,8 +68,10 @@ def test_deduplicate_urls_no_repetiton_between_segments(self):
self.assertRaises(KeyError, lambda: deduplicated_urls_object["warning"])

def test_deduplicate_urls_repetiton_between_segments(self):
filename = "../tests/test_data/results_for_testing_dedup_between_seg.json"
json_data = utils.get_json_from_file(filename)
filename = "results_for_testing_dedup_between_seg.json"
filepath = os.path.join(self.test_data_folder_location, filename)

json_data = utils.get_json_from_file(filepath)
deduplicated_urls_object = search.deduplicate_urls(json_data)
deduplicated_urls_list = deduplicated_urls_object["deduplicated_urls"]

Expand All @@ -80,5 +93,3 @@ def test_deduplicate_urls_repetiton_between_segments(self):
self.assertEqual("same url found across more than 1 segment", deduplicated_urls_object["warning"]["message"])
self.assertEqual(["https://kb.iu.edu/d/afdk"], deduplicated_urls_object["warning"]["urls"])
self.assertEqual([2, 3], deduplicated_urls_object["warning"]["segments"])


0 comments on commit ee2d9f1

Please sign in to comment.