-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added the dbclient support using resty
- Loading branch information
darius BERNARD
committed
Nov 23, 2016
1 parent
151581a
commit 85899cf
Showing
12 changed files
with
296 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals, absolute_import, print_function | ||
|
||
from django.core.management import call_command | ||
from django.test.testcases import TestCase | ||
|
||
from rest_models.backend.client import DatabaseClient | ||
|
||
|
||
class ClientTest(TestCase): | ||
def setUp(self): | ||
self.original_execute = DatabaseClient.execute_subprocess | ||
self.original_ports = DatabaseClient.port_range | ||
|
||
def tearDown(self): | ||
DatabaseClient.execute_subprocess = self.original_execute | ||
DatabaseClient.port_range = self.original_ports | ||
|
||
def test_existing_db(self): | ||
called = [] | ||
|
||
def tmp_exec(self_dc, args, env): | ||
self.assertEqual(env['_resty_host'], 'http://localhost:8097/api/v2*') | ||
called.append(args) | ||
|
||
DatabaseClient.execute_subprocess = tmp_exec | ||
|
||
self.assertEqual(len(called), 0) | ||
call_command('dbshell', database='api') | ||
self.assertEqual(len(called), 1) | ||
|
||
def test_to_run_db(self): | ||
called = [] | ||
|
||
def tmp_exec(self_dc, args, env): | ||
self.assertEqual(env['_resty_host'], 'http://127.0.0.1:8080/api/v2*') | ||
called.append(args) | ||
|
||
DatabaseClient.execute_subprocess = tmp_exec | ||
|
||
self.assertEqual(len(called), 0) | ||
call_command('dbshell', database='api2') | ||
self.assertEqual(len(called), 1) | ||
|
||
def test_run_error_server(self): | ||
DatabaseClient.port_range = (80, 80) # this port wont work | ||
|
||
def tmp_exec(self_dc, args, env): | ||
raise AssertionError('the exec shall not being called') | ||
|
||
DatabaseClient.execute_subprocess = tmp_exec | ||
self.assertRaises(Exception, call_command, 'dbshell', database='api') |
Oops, something went wrong.