def test_set_status(self): with patch('raider_admin.raider.RaiderAdmin._try_connect') as mock_func: mock_cursor = MockCursor(result=[ (2, '*****@*****.**', Decimal('1.00'), 'Leon Richter', 'Sophienhof 17', 'DE', 'paypal', '*****@*****.**', datetime.datetime(2020, 7, 10, 12, 5, 26), datetime.datetime(2020, 7, 10, 12, 5, 26)) ]) mock_conn = MockConnection(mock_cursor) mock_func.return_value = mock_conn raider_admin = RaiderAdmin.from_config(SAMPLE_CONFIG) assert raider_admin.set_status(34, PayoutStatus.Pending) self.assertTupleEqual(mock_cursor.query_args, (PayoutStatus.Pending.value, 34))
def test_cursor_context(self): with patch('raider_admin.raider.RaiderAdmin._try_connect') as mock_func: mock_conn = MockConnection() mock_func.return_value = mock_conn raider_admin = RaiderAdmin.from_config(SAMPLE_CONFIG) assert not mock_conn._cursor.close_called with raider_admin.cursor() as cur: assert cur assert mock_conn._cursor.close_called
def test_get_account_data(self): with patch('raider_admin.raider.RaiderAdmin._try_connect') as mock_func: mock_cursor = MockCursor(result=[ (2, '*****@*****.**', Decimal('1.00'), 'Leon Richter', 'Sophienhof 17', 'DE', 'paypal', '*****@*****.**', datetime.datetime(2020, 7, 10, 12, 5, 26), datetime.datetime(2020, 7, 10, 12, 5, 26)) ]) mock_conn = MockConnection(mock_cursor) mock_func.return_value = mock_conn raider_admin = RaiderAdmin.from_config(SAMPLE_CONFIG) acc = raider_admin.get_account_data(45) assert isinstance(acc, Account)
def test_init_from_config_case_insensitive(self): config = dict( HOST=HOST, DATABASE=DATABASE, USER=USER, PASSWORD=PASSWORD ) raider_admin = RaiderAdmin.from_config(config) assert raider_admin.host == HOST assert raider_admin.database == DATABASE assert raider_admin.user == USER assert raider_admin.password == PASSWORD
def test_connection_context(self): with patch('raider_admin.raider.RaiderAdmin._try_connect')as mock_func: mock_conn = MockConnection() mock_func.return_value = mock_conn raider_admin = RaiderAdmin.from_config(SAMPLE_CONFIG) with raider_admin.connection() as conn: assert conn # assert commit and close are called if function does not raise an error assert mock_conn.commit_called assert mock_conn.close_called # but rollback was not called assert not mock_conn.rollback_called
def test_payout(self): with patch('raider_admin.raider.RaiderAdmin._try_connect') as mock_func: mock_cursor = MockCursor(result=[ ( 4, 1, Decimal('150.00'), 'EUR', 'processed', "blu", "bli", 2, datetime.datetime(2020, 7, 10, 12, 37, 49), datetime.datetime(2020, 7, 10, 12, 37, 49) ) ]) mock_conn = MockConnection(mock_cursor) mock_func.return_value = mock_conn raider_admin = RaiderAdmin.from_config(SAMPLE_CONFIG) payout = raider_admin.get_payout(34) assert payout assert isinstance(payout, Payout)
def test_get_all_payouts(self): with patch('raider_admin.raider.RaiderAdmin._try_connect') as mock_func: mock_cursor = MockCursor(result=[ ( 4, 1, Decimal('150.00'), 'EUR', 'processed', "blu", "bli", 2, datetime.datetime(2020, 7, 10, 12, 37, 49), datetime.datetime(2020, 7, 10, 12, 37, 49) ) ]) mock_conn = MockConnection(mock_cursor) mock_func.return_value = mock_conn raider_admin = RaiderAdmin.from_config(SAMPLE_CONFIG) payouts = raider_admin.get_all_payouts(limit=100, offset=900) assert isinstance(payouts, List) assert isinstance(payouts[0], Payout) assert len(payouts) == 1 assert mock_cursor.query_args == (100, 900)
def test_connection_with_error(self): with patch('raider_admin.raider.RaiderAdmin._try_connect') as mock_func: mock_conn = MockConnection() mock_func.return_value = mock_conn raider_admin = RaiderAdmin.from_config(SAMPLE_CONFIG) try: with raider_admin.connection() as conn: raise ValueError("Blub") except ValueError: pass # assert rollback and close are called if function does not raise an error assert mock_conn.rollback_called assert mock_conn.close_called # but commit not assert not mock_conn.commit_called
def test_init_from_config(self): raider_admin = RaiderAdmin.from_config(SAMPLE_CONFIG) assert raider_admin.host == HOST assert raider_admin.database == DATABASE assert raider_admin.user == USER assert raider_admin.password == PASSWORD
def test_try_connect_raises_error(self): raider_admin = RaiderAdmin.from_config(SAMPLE_CONFIG) self.assertRaises(ConnectionError, lambda: raider_admin._try_connect())
def test_config_missing_param(self): self.assertRaises(MalformedConfigurationError, lambda: RaiderAdmin.from_config({}))