Skip to content

Commit

Permalink
Merge 82d0b79 into 641dabd
Browse files Browse the repository at this point in the history
  • Loading branch information
jgbarah committed Nov 10, 2017
2 parents 641dabd + 82d0b79 commit 55e2e53
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
4 changes: 2 additions & 2 deletions sortinghat/db/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from contextlib import contextmanager

from sqlalchemy import create_engine
from sqlalchemy.exc import OperationalError, ProgrammingError
from sqlalchemy.exc import OperationalError, ProgrammingError, InternalError
from sqlalchemy.engine.url import URL
from sqlalchemy.orm import mapper, sessionmaker
from sqlalchemy.pool import QueuePool
Expand Down Expand Up @@ -88,7 +88,7 @@ def execute(cls, engine, query):
try:
conn = engine.connect()
conn.execute(query)
except (OperationalError, ProgrammingError) as e:
except (OperationalError, ProgrammingError, InternalError) as e:
raise DatabaseError(error=e.orig.args[1], code=e.orig.args[0])

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cmd_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from tests.config import DB_USER, DB_PASSWORD, DB_HOST, DB_PORT


DB_ACCESS_ERROR = r".+Access denied for user '%(user)s'@'localhost' \(using password: YES\)"
DB_ACCESS_ERROR = r".+Access denied for user '%(user)s'@'localhost'"
DB_EXISTS_ERROR = r".+Can't create database '%(database)s'; database exists \(err: 1007\)"


Expand Down
44 changes: 26 additions & 18 deletions tests/test_cmd_organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,37 @@
REGISTRY_DOM_NOT_FOUND_ERROR_ALT = "Error: bitergia.com not found in the registry"
REGISTRY_EMPTY_OUTPUT = ""

REGISTRY_OUTPUT = """Bitergia\tbitergia.net
Bitergia\tbitergia.com *
REGISTRY_OUTPUT = """Bitergia\tbitergia.com *
Bitergia\tbitergia.net
Example\texample.com
Example\texample.org
Example\texample.net
Example\texample.org
LibreSoft"""

REGISTRY_OUTPUT_ALT = """Bitergia\tbitergia.net
Example\texample.com
Example\tbitergia.com
Example\texample.org
Example\texample.com
Example\texample.net
Example\texample.org
LibreSoft"""

REGISTRY_OUTPUT_EXAMPLE = """Example\texample.com
Example\texample.org
Example\texample.net
Example\texample.org
MyExample\tmyexample.com"""

REGISTRY_OUTPUT_EXAMPLE_ALT = """Example\texample.com
Example\texample.net"""


def sort_lines(lines):
"""Return a string with the lines in a string sorted.
Needed because output comes in different orders in MySQL / mariadb."""

return '\n'.join(sorted(lines.splitlines()))


class TestOrgsCaseBase(TestCommandCaseBase):
"""Defines common setup and teardown methods orgs unit tests"""

Expand Down Expand Up @@ -106,15 +114,15 @@ def test_default_action(self):

code = self.cmd.run()
self.assertEqual(code, CMD_SUCCESS)
output = sys.stdout.getvalue().strip()
output = sort_lines(sys.stdout.getvalue().strip())
self.assertEqual(output, REGISTRY_OUTPUT_EXAMPLE)

def test_list_without_args(self):
"""Test list action with and without arguments"""

code = self.cmd.run('-l')
self.assertEqual(code, CMD_SUCCESS)
output = sys.stdout.getvalue().strip()
output = sort_lines(sys.stdout.getvalue().strip())
self.assertEqual(output, REGISTRY_OUTPUT)

def test_list_with_args(self):
Expand All @@ -126,7 +134,7 @@ def test_list_with_args(self):

code = self.cmd.run('--list', 'Example')
self.assertEqual(code, CMD_SUCCESS)
output = sys.stdout.getvalue().strip()
output = sort_lines(sys.stdout.getvalue().strip())
self.assertEqual(output, REGISTRY_OUTPUT_EXAMPLE)

def test_add_with_args(self):
Expand Down Expand Up @@ -160,7 +168,7 @@ def test_add_with_args(self):
self.assertEqual(code, CMD_SUCCESS)

self.cmd.run('--list')
output = sys.stdout.getvalue().strip()
output = sort_lines(sys.stdout.getvalue().strip())
self.assertEqual(output, REGISTRY_OUTPUT)

def test_add_without_args(self):
Expand All @@ -173,7 +181,7 @@ def test_add_without_args(self):
self.assertEqual(code, CMD_SUCCESS)

self.cmd.run('-l')
output = sys.stdout.getvalue().strip()
output = sort_lines(sys.stdout.getvalue().strip())
self.assertEqual(output, REGISTRY_EMPTY_OUTPUT)

def test_add_with_overwrite_option(self):
Expand All @@ -188,7 +196,7 @@ def test_add_with_overwrite_option(self):
self.assertEqual(code, CMD_SUCCESS)

self.cmd.run('-l')
output = sys.stdout.getvalue().strip()
output = sort_lines(sys.stdout.getvalue().strip())
self.assertEqual(output, REGISTRY_OUTPUT_ALT)

def test_delete_with_args(self):
Expand All @@ -208,7 +216,7 @@ def test_delete_with_args(self):
self.assertEqual(code, CMD_SUCCESS)

self.cmd.run('--list')
output = sys.stdout.getvalue().strip()
output = sort_lines(sys.stdout.getvalue().strip())
self.assertEqual(output, REGISTRY_OUTPUT_EXAMPLE_ALT)

def test_delete_without_args(self):
Expand All @@ -218,7 +226,7 @@ def test_delete_without_args(self):
self.assertEqual(code, CMD_SUCCESS)

self.cmd.run('-l')
output = sys.stdout.getvalue().strip()
output = sort_lines(sys.stdout.getvalue().strip())
self.assertEqual(output, REGISTRY_OUTPUT)

def test_run_mixing_actions(self):
Expand All @@ -242,7 +250,7 @@ def test_run_mixing_actions(self):
self.cmd.run('-d', 'Bitergia')
self.cmd.run()

output = sys.stdout.getvalue().strip()
output = sort_lines(sys.stdout.getvalue().strip())
self.assertEqual(output, REGISTRY_OUTPUT_EXAMPLE_ALT)


Expand Down Expand Up @@ -277,7 +285,7 @@ def test_add(self):

# List the registry and check the output
self.cmd.registry()
output = sys.stdout.getvalue().strip()
output = sort_lines(sys.stdout.getvalue().strip())
self.assertEqual(output, REGISTRY_OUTPUT)

def test_existing_organization(self):
Expand Down Expand Up @@ -528,7 +536,7 @@ def test_registry(self):

code = self.cmd.registry()
self.assertEqual(code, CMD_SUCCESS)
output = sys.stdout.getvalue().strip()
output = sort_lines(sys.stdout.getvalue().strip())
self.assertEqual(output, REGISTRY_OUTPUT)

def test_registry_term(self):
Expand All @@ -540,7 +548,7 @@ def test_registry_term(self):

code = self.cmd.registry('Example')
self.assertEqual(code, CMD_SUCCESS)
output = sys.stdout.getvalue().strip()
output = sort_lines(sys.stdout.getvalue().strip())
self.assertEqual(output, REGISTRY_OUTPUT_EXAMPLE)

def test_not_found_term(self):
Expand Down

0 comments on commit 55e2e53

Please sign in to comment.