Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions .circleci/config.yml

This file was deleted.

28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: CI

on:
push:
pull_request:

permissions:
contents: read

jobs:
build-and-test:
runs-on: ubuntu-latest

steps:
- name: Check out repository
uses: actions/checkout@v7

- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: "3.10"
cache: pip

- name: Install dependencies
run: python -m pip install --user -r requirements.txt

- name: Run tests
run: python tests/bootstrap.py
11 changes: 8 additions & 3 deletions tests/bootstrap.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
#!/usr/bin/env python

import unittest
import os
from unit.test_utils import TestUtils
from unit.test_push import TestPush
from unit.test_get_url import TestGetUrl
from unit.test_lang_format import TestLanguageFormat
from unit.test_pull import TestPull

def main ():
os.chdir(os.path.dirname(__file__))
# Run the test suites
util1= unittest.TestLoader().loadTestsFromTestCase(TestUtils)
util2= unittest.TestLoader().loadTestsFromTestCase(TestPush)
util3= unittest.TestLoader().loadTestsFromTestCase(TestGetUrl)
util4= unittest.TestLoader().loadTestsFromTestCase(TestPull)
unittest.TestSuite([util1, util2, util3, util4])
unittest.main()
util5= unittest.TestLoader().loadTestsFromTestCase(TestLanguageFormat)
suite = unittest.TestSuite([util1, util2, util3, util4, util5])
result = unittest.TextTestRunner().run(suite)
return result.wasSuccessful()

if __name__ == '__main__':
main()
raise SystemExit(not main())
7 changes: 4 additions & 3 deletions tests/unit/test_lang_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

class TestLanguageFormat (unittest.TestCase):
def test_correct_language_format (self):
actual = check_and_return_lang_format('/unit/fr.json', 'push')
actual = check_and_return_lang_format('fr.json', 'push')
expected = 'fr'
self.assertEqual(actual, expected)

def test_incorrect_language_format (self):
actual = check_and_return_lang_format('/unit/fr', 'push')
with self.assertRaises(SystemExit) as error:
check_and_return_lang_format('fr', 'push')
expected = 'Wrong filename for'
self.assertTrue(expected in actual)
self.assertIn(expected, str(error.exception))
33 changes: 32 additions & 1 deletion tests/unit/test_pull.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,44 @@
import unittest
import json
import sys
import os
from io import StringIO
from unittest.mock import patch
import unit.test_config as test_config
sys.path.append(os.path.join(os.path.dirname(__file__), '../../'))
from localize.commands import *


class FakeResponse:
def __init__(self, status_code=200, message='', content=b'{}'):
self.status_code = status_code
self.text = json.dumps({'meta': {'error': {'message': message}}})
self.content = content

def iter_content(self, chunk_size=1024):
yield self.content


class TestPull (unittest.TestCase):
def setUp(self):
self.requests_get = patch('localize.commands.requests.get', side_effect=self.fake_get)
self.requests_get.start()

def tearDown(self):
self.requests_get.stop()

@staticmethod
def fake_get(url, headers, verify, params, stream):
language = params['language']
format = params['format']
if language == 'ta':
return FakeResponse(400, 'Failed to pull ta. This language does not exist in your project')
if language == 'xyz':
return FakeResponse(400, 'language code you provided is not found')
if format == 'IOS_STRINGS':
return FakeResponse(400, "The format doesn't support export for web project")
return FakeResponse()

def test_pull_missing_pull_targets (self):
config = {
'api': {
Expand Down Expand Up @@ -235,4 +266,4 @@ def test_pull_unsupported_file_format (self):
sys.stdout = sys.__stdout__
actual = capturedOutput.getvalue()
expected = 'The format doesn\'t support export for web project'
self.assertTrue(expected in actual)
self.assertTrue(expected in actual)
60 changes: 46 additions & 14 deletions tests/unit/test_push.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
import unittest
import json
import sys
import os
from io import StringIO
from unittest.mock import patch
import unit.test_config as test_config
sys.path.append(os.path.join(os.path.dirname(__file__), '../../'))
from localize.commands import *


class FakeResponse:
def __init__(self, status_code=200, message=''):
self.status_code = status_code
self.text = json.dumps({'meta': {'error': {'message': message}}})


class TestPush (unittest.TestCase):

def setUp(self):
self.requests_post = patch('localize.commands.requests.post', side_effect=self.fake_post)
self.requests_post.start()

def tearDown(self):
self.requests_post.stop()

@staticmethod
def fake_post(url, headers, verify, data, files):
language = data['language']
format = data['format']
if language == 'ta':
return FakeResponse(400, 'Target language is not supported by the project')
if language == 'wrong_name':
return FakeResponse(400, 'language code you provided is not found')
if format == 'STRINGS':
return FakeResponse(400, 'ValidationError: "format" must be one of')
return FakeResponse()

def test_push_missing_token (self):
push_path = os.getcwd() + '/unit/test_files/fr.json'
config = {
Expand Down Expand Up @@ -62,10 +89,11 @@ def test_push_missing_file (self):
'type': 'phrase',
}

with self.assertRaises(SystemExit) as SystemExitMessage:
capturedOutput = StringIO()
with patch('sys.stdout', capturedOutput):
push(config, '')
expected = 'Successfully pushed 0 file(s) to Localize'
self.assertTrue(expected in SystemExitMessage.exception.args[0])
self.assertIn(expected, capturedOutput.getvalue())

def test_push_with_correct_data (self):
push_path = os.getcwd() + '/unit/test_files/fr.json'
Expand All @@ -86,10 +114,11 @@ def test_push_with_correct_data (self):
'type': 'phrase',
}

with self.assertRaises(SystemExit) as SystemExitMessage:
capturedOutput = StringIO()
with patch('sys.stdout', capturedOutput):
push(config, '')
expected = 'Successfully pushed 1 file(s) to Localize'
self.assertTrue(expected in SystemExitMessage.exception.args[0])
expected = 'Successfully pushed 1 file(s) to Localize'
self.assertIn(expected, capturedOutput.getvalue())

def test_push_non_existent_file (self):
pull_path = os.getcwd() + '/unit/test_files/xyz.csv'
Expand All @@ -115,10 +144,11 @@ def test_push_non_existent_file (self):
'type': 'glossary',
}

with self.assertRaises(SystemExit) as SystemExitMessage:
capturedOutput = StringIO()
with patch('sys.stdout', capturedOutput):
push(config, 'my-phrase')
expected = 'Skipping import of xyz. No target file path in the localize cli config.yml'
self.assertTrue(expected in SystemExitMessage.exception.args[0])
expected = 'Skipping import of xyz. No target file path in the localize cli config.yml'
self.assertIn(expected, capturedOutput.getvalue())

def test_push_with_custom_profile_test1 (self):
push_path = os.getcwd() + '/unit/test_files/fr.json'
Expand All @@ -144,10 +174,11 @@ def test_push_with_custom_profile_test1 (self):
'type': 'glossary',
}

with self.assertRaises(SystemExit) as SystemExitMessage:
capturedOutput = StringIO()
with patch('sys.stdout', capturedOutput):
push(config, 'my-glossary')
expected = 'Successfully pushed 1 file(s) to Localize'
self.assertTrue(expected in SystemExitMessage.exception.args[0])
expected = 'Successfully pushed 1 file(s) to Localize'
self.assertIn(expected, capturedOutput.getvalue())

def test_push_with_custom_profile_test2 (self):
pull_path = os.getcwd() + '/unit/test_files/fr.csv'
Expand All @@ -173,10 +204,11 @@ def test_push_with_custom_profile_test2 (self):
'type': 'glossary',
}

with self.assertRaises(SystemExit) as SystemExitMessage:
capturedOutput = StringIO()
with patch('sys.stdout', capturedOutput):
push(config, 'my-phrase')
expected = 'Successfully pushed 1 file(s) to Localize'
self.assertTrue(expected in SystemExitMessage.exception.args[0])
expected = 'Successfully pushed 1 file(s) to Localize'
self.assertIn(expected, capturedOutput.getvalue())

def test_push_incorrect_language_code (self):
pull_path = os.getcwd() + '/unit/test_files/ta.csv'
Expand Down
Loading