Skip to content

Commit

Permalink
Passed test_clex_importer_live.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ciioprof0 committed Aug 7, 2024
1 parent c09fd46 commit 4ee9ad9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
14 changes: 3 additions & 11 deletions app/clex_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _generate_hash(self, word_tag: str, word_form: str) -> str:
hash_object = hashlib.sha256(f"{word_tag}{word_form}".encode('utf-8'))
return hash_object.hexdigest()

def import_clex_entries(self, uri: str) -> None:
def import_clex_entries(self, uri: str) -> str:
"""Main method to import Clex entries into the database."""
try:
response = requests.get(uri)
Expand Down Expand Up @@ -106,14 +106,6 @@ def import_clex_entries(self, uri: str) -> None:
self.db_repo.link_entry_with_stix(lex_id, stix_object['obj_id'])
else:
self.db_repo.link_existing_entry(tag_form_hash)
return "Import successful"
except Exception as e:
raise e

# Define Main Body of Script
if __name__ == "__main__":
db_repo = MySQLRepository(DB_CONNECTION_PARAMS)
clex_importer = ClexImporter(db_repo, CLEX_FILE_PATH)
try:
clex_importer.import_clex_entries(CLEX_FILE_PATH)
except Exception as e:
print(f"An error occurred: {e}")
raise e
5 changes: 3 additions & 2 deletions tests/test_clex_importer_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def db_repo():
def test_import_clex_entries(db_repo, lex_id, word_tag, word_form, logical_symbol, third_arg, tag_form_hash):
"""Tests the ClexImporter service layer function by importing and validating lexicon entries."""
# Setup: Create an instance of the service layer
importer = ClexImporter(db_repo)
clex_file_path = "path/to/your/clex_file.pl" # Specify the actual path to your Clex file
importer = ClexImporter(db_repo, clex_file_path)

# Provide test input data
test_input = {
Expand All @@ -59,7 +60,7 @@ def test_import_clex_entries(db_repo, lex_id, word_tag, word_form, logical_symbo
}

# Call the function with test input
return_value = importer.import_clex_entries("http://example.com/test_clex.pl") # Assuming this method takes a URI
return_value = importer.import_clex_entries("https://github.com/ciioprof0/stixd/raw/main/lexicon/test_clex.pl")

# Assertions
assert return_value == "Import successful", f"Unexpected return value: {return_value}"
Expand Down

0 comments on commit 4ee9ad9

Please sign in to comment.