Mercurial > libervia-pubsub
comparison idavoll/test/test_storage.py @ 227:8540825f85e0
Replaced unmaintained pyPgSQL by Psycopg 2
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 17 May 2012 00:31:36 +0200 |
parents | b7018ec56ee5 |
children |
comparison
equal
deleted
inserted
replaced
226:b7018ec56ee5 | 227:8540825f85e0 |
---|---|
478 | 478 |
479 def setUp(self): | 479 def setUp(self): |
480 from idavoll.pgsql_storage import Storage | 480 from idavoll.pgsql_storage import Storage |
481 from twisted.enterprise import adbapi | 481 from twisted.enterprise import adbapi |
482 if self.dbpool is None: | 482 if self.dbpool is None: |
483 self.__class__.dbpool = adbapi.ConnectionPool('pyPgSQL.PgSQL', | 483 self.__class__.dbpool = adbapi.ConnectionPool('psycopg2', |
484 database='pubsub_test', | 484 database='pubsub_test', |
485 cp_reconnect=True, | 485 cp_reconnect=True, |
486 client_encoding='utf-8', | 486 client_encoding='utf-8', |
487 ) | 487 ) |
488 self.s = Storage(self.dbpool) | 488 self.s = Storage(self.dbpool) |
503 VALUES ('pre-existing', 'leaf', TRUE)""") | 503 VALUES ('pre-existing', 'leaf', TRUE)""") |
504 cursor.execute("""INSERT INTO nodes (node) VALUES ('to-be-deleted')""") | 504 cursor.execute("""INSERT INTO nodes (node) VALUES ('to-be-deleted')""") |
505 cursor.execute("""INSERT INTO nodes (node) VALUES ('to-be-reconfigured')""") | 505 cursor.execute("""INSERT INTO nodes (node) VALUES ('to-be-reconfigured')""") |
506 cursor.execute("""INSERT INTO nodes (node) VALUES ('to-be-purged')""") | 506 cursor.execute("""INSERT INTO nodes (node) VALUES ('to-be-purged')""") |
507 cursor.execute("""INSERT INTO entities (jid) VALUES (%s)""", | 507 cursor.execute("""INSERT INTO entities (jid) VALUES (%s)""", |
508 OWNER.userhost()) | 508 (OWNER.userhost(),)) |
509 cursor.execute("""INSERT INTO affiliations | 509 cursor.execute("""INSERT INTO affiliations |
510 (node_id, entity_id, affiliation) | 510 (node_id, entity_id, affiliation) |
511 SELECT node_id, entity_id, 'owner' | 511 SELECT node_id, entity_id, 'owner' |
512 FROM nodes, entities | 512 FROM nodes, entities |
513 WHERE node='pre-existing' AND jid=%s""", | 513 WHERE node='pre-existing' AND jid=%s""", |
514 OWNER.userhost()) | 514 (OWNER.userhost(),)) |
515 cursor.execute("""INSERT INTO entities (jid) VALUES (%s)""", | 515 cursor.execute("""INSERT INTO entities (jid) VALUES (%s)""", |
516 SUBSCRIBER.userhost()) | 516 (SUBSCRIBER.userhost(),)) |
517 cursor.execute("""INSERT INTO subscriptions | 517 cursor.execute("""INSERT INTO subscriptions |
518 (node_id, entity_id, resource, state) | 518 (node_id, entity_id, resource, state) |
519 SELECT node_id, entity_id, %s, 'subscribed' | 519 SELECT node_id, entity_id, %s, 'subscribed' |
520 FROM nodes, entities | 520 FROM nodes, entities |
521 WHERE node='pre-existing' AND jid=%s""", | 521 WHERE node='pre-existing' AND jid=%s""", |
522 (SUBSCRIBER.resource, | 522 (SUBSCRIBER.resource, |
523 SUBSCRIBER.userhost())) | 523 SUBSCRIBER.userhost())) |
524 cursor.execute("""INSERT INTO entities (jid) VALUES (%s)""", | 524 cursor.execute("""INSERT INTO entities (jid) VALUES (%s)""", |
525 SUBSCRIBER_TO_BE_DELETED.userhost()) | 525 (SUBSCRIBER_TO_BE_DELETED.userhost(),)) |
526 cursor.execute("""INSERT INTO subscriptions | 526 cursor.execute("""INSERT INTO subscriptions |
527 (node_id, entity_id, resource, state) | 527 (node_id, entity_id, resource, state) |
528 SELECT node_id, entity_id, %s, 'subscribed' | 528 SELECT node_id, entity_id, %s, 'subscribed' |
529 FROM nodes, entities | 529 FROM nodes, entities |
530 WHERE node='pre-existing' AND jid=%s""", | 530 WHERE node='pre-existing' AND jid=%s""", |
531 (SUBSCRIBER_TO_BE_DELETED.resource, | 531 (SUBSCRIBER_TO_BE_DELETED.resource, |
532 SUBSCRIBER_TO_BE_DELETED.userhost())) | 532 SUBSCRIBER_TO_BE_DELETED.userhost())) |
533 cursor.execute("""INSERT INTO entities (jid) VALUES (%s)""", | 533 cursor.execute("""INSERT INTO entities (jid) VALUES (%s)""", |
534 SUBSCRIBER_PENDING.userhost()) | 534 (SUBSCRIBER_PENDING.userhost(),)) |
535 cursor.execute("""INSERT INTO subscriptions | 535 cursor.execute("""INSERT INTO subscriptions |
536 (node_id, entity_id, resource, state) | 536 (node_id, entity_id, resource, state) |
537 SELECT node_id, entity_id, %s, 'pending' | 537 SELECT node_id, entity_id, %s, 'pending' |
538 FROM nodes, entities | 538 FROM nodes, entities |
539 WHERE node='pre-existing' AND jid=%s""", | 539 WHERE node='pre-existing' AND jid=%s""", |
540 (SUBSCRIBER_PENDING.resource, | 540 (SUBSCRIBER_PENDING.resource, |
541 SUBSCRIBER_PENDING.userhost())) | 541 SUBSCRIBER_PENDING.userhost())) |
542 cursor.execute("""INSERT INTO entities (jid) VALUES (%s)""", | 542 cursor.execute("""INSERT INTO entities (jid) VALUES (%s)""", |
543 PUBLISHER.userhost()) | 543 (PUBLISHER.userhost(),)) |
544 cursor.execute("""INSERT INTO items | 544 cursor.execute("""INSERT INTO items |
545 (node_id, publisher, item, data, date) | 545 (node_id, publisher, item, data, date) |
546 SELECT node_id, %s, 'to-be-deleted', %s, | 546 SELECT node_id, %s, 'to-be-deleted', %s, |
547 now() - interval '1 day' | 547 now() - interval '1 day' |
548 FROM nodes | 548 FROM nodes |
567 cursor.execute("""DELETE FROM nodes WHERE node in | 567 cursor.execute("""DELETE FROM nodes WHERE node in |
568 ('non-existing', 'pre-existing', 'to-be-deleted', | 568 ('non-existing', 'pre-existing', 'to-be-deleted', |
569 'new 1', 'new 2', 'new 3', 'to-be-reconfigured', | 569 'new 1', 'new 2', 'new 3', 'to-be-reconfigured', |
570 'to-be-purged')""") | 570 'to-be-purged')""") |
571 cursor.execute("""DELETE FROM entities WHERE jid=%s""", | 571 cursor.execute("""DELETE FROM entities WHERE jid=%s""", |
572 OWNER.userhost()) | 572 (OWNER.userhost(),)) |
573 cursor.execute("""DELETE FROM entities WHERE jid=%s""", | 573 cursor.execute("""DELETE FROM entities WHERE jid=%s""", |
574 SUBSCRIBER.userhost()) | 574 (SUBSCRIBER.userhost(),)) |
575 cursor.execute("""DELETE FROM entities WHERE jid=%s""", | 575 cursor.execute("""DELETE FROM entities WHERE jid=%s""", |
576 SUBSCRIBER_TO_BE_DELETED.userhost()) | 576 (SUBSCRIBER_TO_BE_DELETED.userhost(),)) |
577 cursor.execute("""DELETE FROM entities WHERE jid=%s""", | 577 cursor.execute("""DELETE FROM entities WHERE jid=%s""", |
578 SUBSCRIBER_PENDING.userhost()) | 578 (SUBSCRIBER_PENDING.userhost(),)) |
579 cursor.execute("""DELETE FROM entities WHERE jid=%s""", | 579 cursor.execute("""DELETE FROM entities WHERE jid=%s""", |
580 PUBLISHER.userhost()) | 580 (PUBLISHER.userhost(),)) |
581 | 581 |
582 try: | 582 try: |
583 import pyPgSQL | 583 import psycopg2 |
584 pyPgSQL | |
585 except ImportError: | 584 except ImportError: |
586 PgsqlStorageStorageTestCase.skip = "pyPgSQL not available" | 585 PgsqlStorageStorageTestCase.skip = "Psycopg2 not available" |