コード例 #1
0
ファイル: test_notes.py プロジェクト: rb560u/airship-shipyard
 def test_store_retrieve_basic_verbosity(self):
     nm = NotesManager(MemoryNotesStorage(), get_token)
     nm.store(
         Note(assoc_id="test1/11111/aaa",
              subject="store_retrieve_1",
              sub_type="test",
              note_val="this is my note 1",
              verbosity=5))
     n_list = nm.retrieve(Query("test1", max_verbosity=3))
     assert len(n_list) == 0
コード例 #2
0
ファイル: test_notes.py プロジェクト: rb560u/airship-shipyard
    def test_store_retrieve_url_does_not_exist(self):
        responses.add(method="GET",
                      url="http://test.test2",
                      body="Hello from testland2",
                      status=200,
                      content_type="text/plain")

        nm = NotesManager(MemoryNotesStorage(), get_token)
        nm.store(
            Note(assoc_id="test1/11111/aaa",
                 subject="store_retrieve3",
                 sub_type="test",
                 note_val="this is my note 1",
                 link_url="test_breakage://test.test/"))
        nm.store(
            Note(assoc_id="test1/11111/bbb",
                 subject="store_retrieve3",
                 sub_type="test",
                 note_val="this is my note 2",
                 link_url="http://test.test2/"))
        n_list = nm.retrieve(Query("test1"))
        assert len(n_list) == 2
        for n in n_list:
            if n.assoc_id == "test1/11111/aaa":
                with pytest.raises(NoteURLRetrievalError):
                    nd = nm.get_note_url_info(n.note_id)
            else:
                nd = nm.get_note_url_info(n.note_id)
                assert nd.startswith("Hello from testland")
コード例 #3
0
ファイル: test_notes.py プロジェクト: rb560u/airship-shipyard
 def test_store_retrieve_urls(self):
     responses.add(method="GET",
                   url="http://test.test",
                   body="Hello from testland",
                   status=200,
                   content_type="text/plain")
     responses.add(method="GET",
                   url="http://test.test2",
                   body="Hello from testland2",
                   status=200,
                   content_type="text/plain")
     nm = NotesManager(MemoryNotesStorage(), get_token)
     nm.store(
         Note(assoc_id="test1/11111/aaa",
              subject="store_retrieve3",
              sub_type="test",
              note_val="this is my note 1",
              link_url="http://test.test/"))
     nm.store(
         Note(assoc_id="test1/11111/bbb",
              subject="store_retrieve3",
              sub_type="test",
              note_val="this is my note 2",
              link_url="http://test.test2/"))
     n_list = nm.retrieve(Query("test1"))
     assert len(n_list) == 2
     for n in n_list:
         assert n.resolved_url_value.startswith("Details at notedetails/")
         assert nm.get_note_url_info(
             n.note_id).startswith("Hello from testland")
     with pytest.raises(KeyError):
         auth_hdr = responses.calls[0].request.headers['X-Auth-Token']
コード例 #4
0
 def _setup_notes_helper(self):
     """Setup a notes helper for use by all descendent operators"""
     connect_timeout = self.config.get(REQUESTS_CONFIG,
                                       'notes_connect_timeout')
     read_timeout = self.config.get(REQUESTS_CONFIG, 'notes_read_timeout')
     self.notes_helper = NotesHelper(
         NotesManager(storage=ShipyardSQLNotesStorage(
             self._get_shipyard_db_engine),
                      get_token=self._token_getter,
                      connect_timeout=connect_timeout,
                      read_timeout=read_timeout))
コード例 #5
0
ファイル: test_notes.py プロジェクト: rb560u/airship-shipyard
 def test_note_view(self):
     nm = NotesManager(MemoryNotesStorage(), get_token)
     nm.store(
         Note(assoc_id="test1/11111/aaa",
              subject="store_retrieve_1",
              sub_type="test",
              note_val="this is my note 1"))
     n_list = nm.retrieve(Query("test1"))
     assert len(n_list) == 1
     nid = n_list[0].note_id
     nt = n_list[0].note_timestamp
     assert n_list[0].view() == {
         'assoc_id': 'test1/11111/aaa',
         'subject': 'store_retrieve_1',
         'sub_type': 'test',
         'note_val': 'this is my note 1',
         'verbosity': 1,
         'note_id': nid,
         'note_timestamp': nt,
         'resolved_url_value': None,
     }
コード例 #6
0
ファイル: test_notes.py プロジェクト: rb560u/airship-shipyard
    def test_init(self):
        with pytest.raises(NotesInitializationError) as nie:
            nm = NotesManager(None, None)
        assert "Storage object is not" in str(nie.value)

        with pytest.raises(NotesInitializationError) as nie:
            nm = NotesManager({}, None)
        assert "Storage object is not" in str(nie.value)

        with pytest.raises(NotesInitializationError) as nie:
            nm = NotesManager(MemoryNotesStorage(), None)
        assert "Parameter get_token" in str(nie.value)

        with pytest.raises(NotesInitializationError) as nie:
            nm = NotesManager(MemoryNotesStorage(), {})
        assert "Parameter get_token" in str(nie.value)

        nm = NotesManager(MemoryNotesStorage(), get_token)
        assert nm.connect_timeout == 3
        assert nm.read_timeout == 10

        nm = NotesManager(MemoryNotesStorage(),
                          get_token,
                          connect_timeout=99,
                          read_timeout=999)
        assert nm.connect_timeout == 99
        assert nm.read_timeout == 999
        assert isinstance(nm.storage, MemoryNotesStorage)
コード例 #7
0
ファイル: test_notes.py プロジェクト: rb560u/airship-shipyard
 def test_store_retrieve_url_not_specified(self):
     nm = NotesManager(MemoryNotesStorage(), get_token)
     nm.store(
         Note(assoc_id="test1/11111/aaa",
              subject="store_retrieve3",
              sub_type="test",
              note_val="this is my note 1",
              link_url=""))
     nm.store(
         Note(assoc_id="test1/11111/bbb",
              subject="store_retrieve3",
              sub_type="test",
              note_val="this is my note 2",
              link_url=None))
     n_list = nm.retrieve(Query("test1"))
     assert len(n_list) == 2
     for n in n_list:
         with pytest.raises(NoteURLNotSpecifiedError):
             nd = nm.get_note_url_info(n.note_id)
コード例 #8
0
ファイル: test_notes.py プロジェクト: rb560u/airship-shipyard
 def test_store_retrieve_basic(self):
     nm = NotesManager(MemoryNotesStorage(), get_token)
     nm.store(
         Note(assoc_id="test1/11111/aaa",
              subject="store_retrieve_1",
              sub_type="test",
              note_val="this is my note 1"))
     n_list = nm.retrieve(Query("test1"))
     assert len(n_list) == 1
     assert n_list[0].subject == "store_retrieve_1"
     n_list = nm.retrieve(Query("test2"))
     assert len(n_list) == 0
コード例 #9
0
ファイル: test_notes.py プロジェクト: rb560u/airship-shipyard
    def test_store_retrieve_unexpected_exception_handling(self):
        nm = NotesManager(NotesStorageErrorImpl(), get_token)
        with pytest.raises(NotesStorageError) as nse:
            n = Note(assoc_id="test1/11111/aaa",
                     subject="store_retrieve_1",
                     sub_type="test",
                     note_val="this is my note 1")
            n.note_id = None
            nm.store(n)
        assert "Unhandled" in str(nse.value)

        with pytest.raises(NotesRetrievalError) as nse:
            nm.retrieve(Query("test"))
        assert "Unhandled" in str(nse.value)
コード例 #10
0
ファイル: test_notes.py プロジェクト: rb560u/airship-shipyard
 def test_store_retrieve_url_refs(self):
     """Tests that notes retrieved as a list have notedetails refs"""
     nm = NotesManager(MemoryNotesStorage(), get_token)
     nm.store(
         Note(assoc_id="test1/11111/aaa",
              subject="store_retrieve3",
              sub_type="test",
              note_val="this is my note 1",
              link_url="http://test.test/"))
     nm.store(
         Note(assoc_id="test1/11111/bbb",
              subject="store_retrieve3",
              sub_type="test",
              note_val="this is my note 2",
              link_url="http://test.test2/"))
     n_list = nm.retrieve(Query("test1"))
     assert len(n_list) == 2
     for n in n_list:
         assert n.resolved_url_value == ("Details at notedetails/" +
                                         n.note_id)
コード例 #11
0
ファイル: test_notes.py プロジェクト: rb560u/airship-shipyard
    def test_store_bad_verbosity(self):
        nm = NotesManager(MemoryNotesStorage(), get_token)
        with pytest.raises(NotesStorageError) as nse:
            nm.store(
                Note(assoc_id="test1/11111/aaa",
                     subject="store_retrieve_1",
                     sub_type="test",
                     note_val="this is my note 1",
                     verbosity=-4))
        assert "Verbosity of notes must" in str(nse.value)

        with pytest.raises(NotesStorageError) as nse:
            nm.store(
                Note(assoc_id="test1/11111/aaa",
                     subject="store_retrieve_1",
                     sub_type="test",
                     note_val="this is my note 1",
                     verbosity=6))
        assert "Verbosity of notes must" in str(nse.value)
コード例 #12
0
ファイル: test_notes.py プロジェクト: rb560u/airship-shipyard
    def test_store_retrieve_with_auth(self):
        responses.add(method="GET",
                      url="http://test.test2",
                      body="Hello from testland2",
                      status=200,
                      content_type="text/plain")

        nm = NotesManager(MemoryNotesStorage(), get_token)
        nm.store(
            Note(assoc_id="test1/11111/bbb",
                 subject="store_retrieve3",
                 sub_type="test",
                 note_val="this is my note 2",
                 link_url="http://test.test2/",
                 is_auth_link=True))
        n_list = nm.retrieve(Query("test1"))
        assert len(n_list) == 1
        for n in n_list:
            nd = nm.get_note_url_info(n.note_id)
            assert nd == "Hello from testland2"
        auth_hdr = responses.calls[0].request.headers['X-Auth-Token']
        assert 'token' == auth_hdr
コード例 #13
0
            print(e)
            print("This test requires that the file at '{}' is a valid yaml "
                  "file containing a list of action names at a key of "
                  "'actions'".format(a_path))
            assert False
    return action_list


def get_token():
    """Stub method to use for NotesHelper/NotesManager"""
    return "token"


# Notes helper that can be mocked into various objects to prevent database
# dependencies
nh = NotesHelper(NotesManager(MemoryNotesStorage(), get_token))


def create_req(ctx, body):
    '''creates a falcon request'''
    env = testing.create_environ(path='/',
                                 query_string='',
                                 protocol='HTTP/1.1',
                                 scheme='http',
                                 host='falconframework.org',
                                 port=None,
                                 headers={'Content-Type': 'application/json'},
                                 app='',
                                 body=body,
                                 method='POST',
                                 wsgierrors=None,
コード例 #14
0
def get_notes_helper():
    """Setup a notes helper using the in-memory storage module"""
    return NotesHelper(
        NotesManager(storage=MemoryNotesStorage(),
                     get_token=lambda: "fake_token"))
コード例 #15
0
ファイル: test_notes.py プロジェクト: rb560u/airship-shipyard
 def test_store_retrieve_multi(self):
     nm = NotesManager(MemoryNotesStorage(), get_token)
     nm.store(
         Note(assoc_id="test1/11111/aaa",
              subject="store_retrieve",
              sub_type="test",
              note_val="this is my note 1"))
     nm.store(
         Note(assoc_id="test1/11111/bbb",
              subject="store_retrieve",
              sub_type="test",
              note_val="this is my note 2"))
     nm.store(
         Note(assoc_id="test2/2222/aaa",
              subject="store_retrieve_2",
              sub_type="test",
              note_val="this is my note 3"))
     n_list = nm.retrieve(Query("test2"))
     assert len(n_list) == 1
     assert n_list[0].subject == "store_retrieve_2"
     n_list = nm.retrieve(Query("test1"))
     assert len(n_list) == 2
     n_list = nm.retrieve(Query("test1", exact_match=True))
     assert len(n_list) == 0
     n_list = nm.retrieve(Query("test1/11111/aaa", exact_match=True))
     assert len(n_list) == 1
コード例 #16
0
def _notes_manager():
    """Setup a NotesManager object using Shipyard settings"""
    sy_engine_getter = SHIPYARD_DB.get_engine
    return NotesManager(ShipyardSQLNotesStorage(sy_engine_getter), get_token,
                        CONF.requests_config.notes_connect_timeout,
                        CONF.requests_config.notes_read_timeout)