Example #1
0
    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)
Example #2
0
 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']
Example #3
0
    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")
Example #4
0
 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
Example #5
0
 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
Example #6
0
 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
Example #7
0
 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)
Example #8
0
    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)
Example #9
0
 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)
Example #10
0
 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,
     }
Example #11
0
    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
            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,
def get_notes_helper():
    """Setup a notes helper using the in-memory storage module"""
    return NotesHelper(
        NotesManager(storage=MemoryNotesStorage(),
                     get_token=lambda: "fake_token"))