Skip to content

Commit

Permalink
fix import path
Browse files Browse the repository at this point in the history
  • Loading branch information
angelafeliciaa committed Nov 16, 2024
1 parent fcb0d68 commit 4c3a1e6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion i18nilize/src/internationalize/api_helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# api_helpers.py
import globals
from . import globals
from core.i18nilize.views import TokenView
from rest_framework.request import Request
from django.http import HttpRequest
Expand Down
20 changes: 10 additions & 10 deletions i18nilize/tests/test_api_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
import sys

from internationalize.api_helpers import create_token, fetch_translation_data
import src.internationalize.globals as globals_module
from src.internationalize import globals

class TestAPIHelpers(unittest.TestCase):

def setUp(self):
self.languages_dir = "src/internationalize/languages"
os.makedirs(self.languages_dir, exist_ok=True)

self.original_token = globals_module.token
self.original_token = globals.token

def tearDown(self):
globals_module.token = self.original_token
globals.token = self.original_token

# clean up any created language files
if os.path.exists(self.languages_dir):
Expand All @@ -40,7 +40,7 @@ def test_create_token_success(self, mock_token_view):
create_token()

mock_token_view_instance.post.assert_called_once()
self.assertEqual(globals_module.token, 'test-token')
self.assertEqual(globals.token, 'test-token')
mock_print.assert_called_once_with("Token set.")

@patch('src.internationalize.api_helpers.TokenView')
Expand All @@ -63,7 +63,7 @@ def test_create_token_failure(self, mock_token_view):
@patch('src.internationalize.api_helpers.translation_processor.get_translations_by_language')
@patch('src.internationalize.api_helpers.create_token')
def test_fetch_translation_data_token_exists(self, mock_create_token, mock_get_translations):
globals_module.token = 'existing-token'
globals.token = 'existing-token'

mock_get_translations.return_value = {'hello': 'hola'}

Expand All @@ -77,10 +77,10 @@ def test_fetch_translation_data_token_exists(self, mock_create_token, mock_get_t
@patch('src.internationalize.api_helpers.translation_processor.get_translations_by_language')
@patch('src.internationalize.api_helpers.create_token')
def test_fetch_translation_data_token_missing_and_created_successfully(self, mock_create_token, mock_get_translations):
globals_module.token = ''
globals.token = ''

def side_effect_create_token():
globals_module.token = 'new-token'
globals.token = 'new-token'
print("Token set.")
mock_create_token.side_effect = side_effect_create_token

Expand All @@ -99,7 +99,7 @@ def side_effect_create_token():
@patch('src.internationalize.api_helpers.translation_processor.get_translations_by_language')
@patch('src.internationalize.api_helpers.create_token')
def test_fetch_translation_data_token_missing_and_creation_fails(self, mock_create_token, mock_get_translations):
globals_module.token = ''
globals.token = ''

mock_create_token.side_effect = Exception("Failed to retrieve token.")

Expand All @@ -112,7 +112,7 @@ def test_fetch_translation_data_token_missing_and_creation_fails(self, mock_crea
mock_print.assert_called_once_with("Token not found. Creating a new token...")

def test_fetch_translation_data_missing_language(self):
globals_module.token = 'existing-token'
globals.token = 'existing-token'

with patch('builtins.print') as mock_print:
with self.assertRaises(Exception) as context:
Expand All @@ -123,7 +123,7 @@ def test_fetch_translation_data_missing_language(self):

@patch('src.internationalize.api_helpers.translation_processor.get_translations_by_language')
def test_fetch_translation_data_no_translations_found(self, mock_get_translations):
globals_module.token = 'existing-token'
globals.token = 'existing-token'

mock_get_translations.return_value = {}

Expand Down

0 comments on commit 4c3a1e6

Please sign in to comment.