1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/tests/integration/targets/odbc/tasks/main.yml
John Westcott IV a86195623b
Adding ODBC module (#606)
* Adding ODBC module

* Adding symink and fixing docs and argspec

* Another sanity issue

* Hopefully last fix for elements

* Making changes suggested by felixfontein

* Making changes suggested by Andersson007

* Removing defaults and added info in description

* Fixing line too long

* More cleanup suggested by felixfontein

* Changing module call
2020-07-17 07:39:37 +03:00

144 lines
3.3 KiB
YAML

#
# Test for proper failures without pyodbc
#
# Some of the docker images already have pyodbc installed on it
- include_tasks: no_pyodbc.yml
when: ansible_os_family != 'FreeBSD' and ansible_os_family != 'Suse' and ansible_os_family != 'Debian'
#
# Get pyodbc installed
#
- include_tasks: install_pyodbc.yml
#
# Test missing parameters & invalid DSN
#
- include_tasks: negative_tests.yml
#
# Setup DSN per env
#
- name: Changing DSN for Suse
set_fact:
dsn: "DRIVER={PSQL};Server=localhost;Port=5432;Database=postgres;Uid={{ my_user }};Pwd={{ my_pass_decrypted }};UseUnicode=True"
when: ansible_os_family == 'Suse'
- name: Changing DSN for Debian
set_fact:
dsn: "DRIVER={PostgreSQL Unicode};Server=localhost;Port=5432;Database=postgres;Uid={{ my_user }};Pwd={{ my_pass_decrypted }};UseUnicode=True"
when: ansible_os_family == 'Debian'
#
# Name setup database
#
- name: Create a user to run the tests with
postgresql_user:
name: "{{ my_user }}"
password: "{{ my_pass }}"
encrypted: 'yes'
role_attr_flags: "SUPERUSER"
db: postgres
become_user: "{{ pg_user }}"
become: True
- name: Create a table
odbc:
dsn: "{{ dsn }}"
query: |
CREATE TABLE films (
code char(5) CONSTRAINT firstkey PRIMARY KEY,
title varchar(40) NOT NULL,
did integer NOT NULL,
date_prod date,
kind varchar(10),
len interval hour to minute
);
become_user: "{{ pg_user }}"
become: True
register: results
- assert:
that:
- results is changed
#
# Insert records
#
- name: Insert a record without params
odbc:
dsn: "{{ dsn }}"
query: "INSERT INTO films (code, title, did, date_prod, kind, len) VALUES ('asdfg', 'My First Movie', 1, '2019-01-12', 'SyFi', '02:00')"
become_user: "{{ pg_user }}"
become: True
register: results
- assert:
that:
- results is changed
- name: Insert a record with params
odbc:
dsn: "{{ dsn }}"
query: "INSERT INTO films (code, title, did, date_prod, kind, len) VALUES (?, ?, ?, ?, ?, ?)"
params:
- 'qwert'
- 'My Second Movie'
- 2
- '2019-01-12'
- 'Comedy'
- '01:30'
become_user: "{{ pg_user }}"
become: True
register: results
- assert:
that:
- results is changed
- results['row_count'] == -1
- results['results'] == []
- results['description'] == []
#
# Select data
#
- name: Perform select single row without params (do not coherse changed)
odbc:
dsn: "{{ dsn }}"
query: "SELECT * FROM films WHERE code='asdfg'"
register: results
- assert:
that:
- results is changed
- results is successful
- results.row_count == 1
- name: Perform select multiple rows with params (coherse changed)
odbc:
dsn: "{{ dsn }}"
query: 'SELECT * FROM films WHERE code=? or code=?'
params:
- 'asdfg'
- 'qwert'
register: results
changed_when: False
- assert:
that:
- results is not changed
- results is successful
- results.row_count == 2
- name: Drop the table
odbc:
dsn: "{{ dsn }}"
query: "DROP TABLE films"
register: results
- assert:
that:
- results is successful
- results is changed
- results['row_count'] == -1
- results['results'] == []
- results['description'] == []