Test works at 1st run
diff --git a/xos/configurations/test-standalone/Makefile b/xos/configurations/test-standalone/Makefile
index a7ed841..f00979f 100644
--- a/xos/configurations/test-standalone/Makefile
+++ b/xos/configurations/test-standalone/Makefile
@@ -1,27 +1,44 @@
MYIP:=$(shell hostname -i)
-xos:
- sudo make -f ../common/Makefile.prereqs
- sudo docker-compose up -d
- bash ../common/wait_for_xos.sh
- sudo docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /opt/xos/configurations/frontend/sample.yaml
- sudo docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /opt/xos/configurations/common/fixtures.yaml
+define TRUNCATE_FN
+ CREATE OR REPLACE FUNCTION truncate_tables(username IN VARCHAR) RETURNS void AS $$$$
+ DECLARE
+ statements CURSOR FOR
+ SELECT tablename FROM pg_tables
+ WHERE tableowner = username AND schemaname = 'public';
+ BEGIN
+ FOR stmt IN statements LOOP
+ EXECUTE 'TRUNCATE TABLE ' || quote_ident(stmt.tablename) || ' CASCADE;';
+ END LOOP;
+ END;
+ $$$$ LANGUAGE plpgsql;
+endef
+export TRUNCATE_FN
-restore-initial-db-status:
- sudo docker exec teststandalone_xos_db_1 psql -U postgres -d xos -c "SELECT truncate_tables('postgres');"
- sudo docker exec teststandalone_xos_db_1 psql -U postgres -d xos -c "INSERT INTO core_user (id, password, username, email, firstname, lastname, is_admin, last_login, created, updated, is_active, is_staff, is_readonly, is_registering, is_appuser, backend_status) VALUES (1, 'pass', 'padmin@vicci.org', 'padmin@vicci.org', 'xos', 'xos', true, now(), now(), now(), true, true, false, false, false, 'be status');"
- sudo docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /opt/xos/configurations/common/base.yaml
- sudo docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /opt/xos/configurations/frontend/sample.yaml
- sudo docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /opt/xos/configurations/common/fixtures.yaml
-
-prepare:
+prepare: xos
# INSTALL DEPS
# RUN ONCE BEFORE RUNNING TESTS
sudo docker exec -i teststandalone_xos_1 bash -c "cd /opt/xos/tests/api; npm install --production"
sudo docker exec teststandalone_xos_1 pip install dredd_hooks
+xos:
+ sudo make -f ../common/Makefile.prereqs
+ sudo docker-compose up -d
+ bash ../common/wait_for_xos.sh
+ # sudo docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /opt/xos/configurations/frontend/sample.yaml
+ # sudo docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /opt/xos/configurations/common/fixtures.yaml
-test:
+restore-initial-db-status:
+ sudo docker exec teststandalone_xos_db_1 psql -U postgres -d xos -c "$$TRUNCATE_FN"
+ sudo docker exec teststandalone_xos_db_1 psql -U postgres -d xos -c "SELECT truncate_tables('postgres');"
+ sudo docker exec teststandalone_xos_db_1 psql -U postgres -d xos -c "SELECT setval('core_tenant_id_seq', 1)"
+ sudo docker-compose run xos python /opt/xos/manage.py --noobserver --nomodelpolicy loaddata /opt/xos/core/fixtures/core_initial_data.json
+ sudo docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /opt/xos/configurations/frontend/sample.yaml
+ sudo docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /opt/xos/configurations/common/fixtures.yaml
+
+
+
+test: restore-initial-db-status
# RUN TESTS
sudo docker exec -i teststandalone_xos_1 bash -c "cd /opt/xos/tests/api; npm test"
diff --git a/xos/configurations/test-standalone/README.md b/xos/configurations/test-standalone/README.md
index bbee0ec..b60b9ff 100644
--- a/xos/configurations/test-standalone/README.md
+++ b/xos/configurations/test-standalone/README.md
@@ -3,8 +3,7 @@
This configuration is intended to be used to test the API,
to use it:
-- `make containers` //rebuild the container with current code
-- `make xos` //start the container with fixtures data
-- `make prepare` //install test dependencies
+- `make containers`
+- `make`
Then anytime is needed `make test` (`xos/api` folder is shared with the container)
\ No newline at end of file
diff --git a/xos/tests/api/helpers/subscriber.py b/xos/tests/api/helpers/subscriber.py
index 4d702fd..0ff02c2 100644
--- a/xos/tests/api/helpers/subscriber.py
+++ b/xos/tests/api/helpers/subscriber.py
@@ -110,7 +110,7 @@
vcpe_slice.caller = user
vcpe_slice.save()
- # print 'vcpe_slice created'
+ print 'vcpe_slice created'
# create a lan network
lan_net = Network()
@@ -119,7 +119,7 @@
lan_net.template = private_template
lan_net.save()
- # print 'lan_network created'
+ print 'lan_network created'
# add relation between vcpe slice and lan network
vcpe_network = NetworkSlice()
@@ -127,13 +127,15 @@
vcpe_network.slice = vcpe_slice
vcpe_network.save()
- # print 'vcpe network relation added'
+ print 'vcpe network relation added'
# vbng service
vbng_service = VBNGService()
vbng_service.name = 'service_vbng'
vbng_service.save()
+ print 'vbng_service creater'
+
# volt tenant
vt = VOLTTenant(subscriber=subscriber.id, id=1)
vt.s_tag = "222"
@@ -142,7 +144,7 @@
vt.caller = user
vt.save()
- # print "Subscriber Created"
+ print "Subscriber Created"
def deleteTruckrolls():
@@ -162,4 +164,4 @@
tn.save()
-doLogin('padmin@vicci.org', 'letmein')
+createTestSubscriber()
diff --git a/xos/tests/api/hooks.py b/xos/tests/api/hooks.py
index 3c306e1..1b3ed61 100644
--- a/xos/tests/api/hooks.py
+++ b/xos/tests/api/hooks.py
@@ -51,7 +51,7 @@
for s in NetworkSlice.objects.all():
s.delete(purge=True)
- # print 'DB Cleaned'
+ print 'DB Cleaned'
def createTestSubscriber():
@@ -101,7 +101,7 @@
vcpe_slice.caller = user
vcpe_slice.save()
- # print 'vcpe_slice created'
+ print 'vcpe_slice created'
# create a lan network
lan_net = Network()
@@ -110,7 +110,7 @@
lan_net.template = private_template
lan_net.save()
- # print 'lan_network created'
+ print 'lan_network created'
# add relation between vcpe slice and lan network
vcpe_network = NetworkSlice()
@@ -118,13 +118,15 @@
vcpe_network.slice = vcpe_slice
vcpe_network.save()
- # print 'vcpe network relation added'
+ print 'vcpe network relation added'
# vbng service
vbng_service = VBNGService()
vbng_service.name = 'service_vbng'
vbng_service.save()
+ print 'vbng_service creater'
+
# volt tenant
vt = VOLTTenant(subscriber=subscriber.id, id=1)
vt.s_tag = "222"
@@ -133,7 +135,7 @@
vt.caller = user
vt.save()
- # print "Subscriber Created"
+ print "Subscriber Created"
def deleteTruckrolls():
@@ -153,8 +155,15 @@
tn.save()
+@hooks.before_all
+def my_before_all_hook(transactions):
+ print "-------------------------------- Before All Hook --------------------------------"
+ cleanDB()
+
+
@hooks.before_each
def my_before_each_hook(transaction):
+ print "-------------------------------- Before Each Hook --------------------------------"
auth = doLogin('padmin@vicci.org', 'letmein')
transaction['request']['headers']['X-CSRFToken'] = auth['token']
transaction['request']['headers']['Cookie'] = "xossessionid=%s; xoscsrftoken=%s" % (auth['sessionid'], auth['token'])