Skip to content

Commit

Permalink
Merge branch 'fix-29-init' of 'git://github.com/andygrunwald/sortingh…
Browse files Browse the repository at this point in the history
…at.git'

Fix chaoss#29
Closes chaoss#59
Merges chaoss#59
  • Loading branch information
sduenas committed Jan 4, 2016
2 parents 8479abe + eb24409 commit 20ed55d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions sortinghat/cmd/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import argparse

from ..command import Command, CMD_SUCCESS, CMD_FAILURE
from ..command import Command, CMD_SUCCESS
from ..exceptions import DatabaseError, LoadError
from ..db.database import Database
from ..db.model import Country
Expand Down Expand Up @@ -92,11 +92,11 @@ def initialize(self, name):
self.__load_countries(db)
except DatabaseError as e:
self.error(str(e))
return CMD_FAILURE
return e.code
except LoadError as e:
Database.drop(user, password, name, host, port)
self.error(str(e))
return CMD_FAILURE
return e.code

return CMD_SUCCESS

Expand Down
11 changes: 6 additions & 5 deletions tests/test_cmd_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
sys.path.insert(0, '..')

from sortinghat import api
from sortinghat.command import CMD_SUCCESS, CMD_FAILURE
from sortinghat.command import CMD_SUCCESS
from sortinghat.cmd.init import Init
from sortinghat.db.database import Database
from sortinghat.exceptions import CODE_DATABASE_ERROR

from tests.config import DB_USER, DB_PASSWORD, DB_HOST, DB_PORT

Expand Down Expand Up @@ -96,7 +97,7 @@ def test_connection_error(self):

cmd = Init(**kwargs)
code = cmd.run(self.name)
self.assertEqual(code, CMD_FAILURE)
self.assertEqual(code, CODE_DATABASE_ERROR)

with warnings.catch_warnings(record=True):
output = sys.stderr.getvalue().strip()
Expand All @@ -110,7 +111,7 @@ def test_existing_db_error(self):
self.assertEqual(code1, CMD_SUCCESS)

code2 = self.cmd.run(self.name)
self.assertEqual(code2, CMD_FAILURE)
self.assertEqual(code2, CODE_DATABASE_ERROR)

# Context added to catch deprecation warnings raised on Python 3
with warnings.catch_warnings(record=True):
Expand Down Expand Up @@ -147,7 +148,7 @@ def test_connection_error(self):

cmd = Init(**kwargs)
code = cmd.initialize(self.name)
self.assertEqual(code, CMD_FAILURE)
self.assertEqual(code, CODE_DATABASE_ERROR)

# Context added to catch deprecation warnings raised on Python 3
with warnings.catch_warnings(record=True):
Expand All @@ -162,7 +163,7 @@ def test_existing_db_error(self):
self.assertEqual(code1, CMD_SUCCESS)

code2 = self.cmd.initialize(self.name)
self.assertEqual(code2, CMD_FAILURE)
self.assertEqual(code2, CODE_DATABASE_ERROR)

# Context added to catch deprecation warnings raised on Python 3
with warnings.catch_warnings(record=True):
Expand Down

0 comments on commit 20ed55d

Please sign in to comment.