feedwarrior

Slim, portable tooling for creating and distributing decentralized append logs
git clone git://git.defalsify.org/logwarrior.git
Info | Log | Files | Refs | README | LICENSE

test_couchdb.py (1466B)


      1 # standard imports
      2 import os
      3 import unittest
      4 import uuid
      5 from email.message import EmailMessage
      6 
      7 # third party imports
      8 import pycouchdb
      9 
     10 # local imports
     11 from feedwarrior.adapters.couchdbadapter import couchdbadapter
     12 from feedwarrior.entry import entry
     13 
     14 DBHOST = os.environ.get('FEEDWARRIOR_HOST', 'localhost')
     15 DBPORT = os.environ.get('FEEDWARRIOR_PORT', 5984)
     16 DBPASS = os.environ.get('FEEDWARRIOR_PASS')
     17 DBUSER = os.environ.get('FEEDWARRIOR_USER')
     18 DBSSL = os.environ.get('FEEDWARRIOR_SSL')
     19 
     20 uu = 'x' + uuid.uuid4().hex
     21 
     22 class TestCouchdbadapter(unittest.TestCase):
     23 
     24     def setUp(self):
     25         ssl = DBSSL != None and DBSSL != ''
     26         scheme = 'http'
     27         if ssl:
     28             scheme += 's'
     29         self.srv = pycouchdb.Server('{}://{}:{}@{}:{}'.format(scheme, DBUSER, DBPASS, DBHOST, DBPORT))
     30         self.db_name = str(uu)
     31         self.db = self.srv.create(self.db_name)
     32 
     33 
     34     def tearDown(self):
     35         self.db.cleanup()
     36         self.srv.delete(self.db_name)
     37 
     38 
     39     def test_init(self):
     40         a = couchdbadapter(DBUSER, DBPASS, self.db_name)
     41 
     42 
     43     def test_put(self):
     44         a = couchdbadapter(DBUSER, DBPASS, self.db_name)
     45         uu = uuid.uuid4()
     46 
     47         msg = EmailMessage()
     48         msg.add_header('Date', 'Thu, 2 Jul 2020 12:00:58 +0200')
     49         msg.add_header('Content-Type', 'multipart/mixed')
     50         msg.add_attachment('foo')
     51 
     52         e = entry(uu, msg)
     53         a.put(uu, e)
     54 
     55         a.get(uu)
     56 
     57 
     58 if __name__ == '__main__':
     59     unittest.main()