Esempio n. 1
0
 def test_execute_sql(self, mock_psql):
     mock_psql.connect.return_value = MockPsycopg2()
     try:
         service = DbService()
         service.execute_sql('test', 1, 2, 3)
         assert_true(True)
     except:
         assert_true(False)
Esempio n. 2
0
 def test_set_status(self, mock_psql):
     mock_psql.connect.return_value = MockPsycopg2()
     try:
         service = DbService()
         service.set_status('asdf', 'completed')
         assert_true(True)
     except:
         assert_true(False)
Esempio n. 3
0
 def test_add_thumbnail(self, mock_psql):
     mock_psql.connect.return_value = MockPsycopg2()
     try:
         service = DbService()
         service.add_thumbnail('asdf', 1, 2, '/test.thumb')
         assert_true(True)
     except:
         assert_true(False)
Esempio n. 4
0
 def test_execute_sql_with_response(self, mock_psql):
     expected_data = [1, 2, 3]
     behaviors = {'fetchall': {'response': expected_data}}
     mock_psql.connect.return_value = MockPsycopg2(behaviors)
     try:
         service = DbService()
         response = service.execute_sql_with_response('test', 1, 2, 3)
         assert_true(set(expected_data) == set(response))
     except:
         assert_true(False)
Esempio n. 5
0
 def test_connect_fails(self, mock_psql):
     mock_psql.connect.side_effect = Exception('exception:connect')
     try:
         DbService()
         assert_true(False)
     except Exception as ex:
         assert_true(str(ex) == 'exception:connect')
Esempio n. 6
0
 def test_connect(self, mock_psql):
     mock_psql.connect.return_value = MockPsycopg2()
     try:
         DbService()
         assert_true(True)
     except:
         assert_true(False)
Esempio n. 7
0
 def test_fetch_by(self, mock_psql):
     response_set = [('asdf', 'http://www.google.com', 'processing',
                      'today')]
     behaviors = {'fetchall': {'response': response_set}}
     mock_psql.connect.return_value = MockPsycopg2(behaviors)
     try:
         service = DbService()
         response = service.fetch_by('asdf', 'uiop')
         assert_true(isinstance(response, type([])))
         obj = response[0]
         assert_true('uuid' in obj and obj['uuid'] == response_set[0][0])
         assert_true('url' in obj and obj['url'] == response_set[0][1])
         assert_true('status' in obj
                     and obj['status'] == response_set[0][2])
         assert_true('created_at' in obj
                     and obj['created_at'] == response_set[0][3])
     except:
         assert_true(False)