Beispiel #1
0
    def test_get_singleton_document_succeeds_when_one_document_is_found(self):
        doc_id = uuid.uuid4()
        tu.save_document({'_id': doc_id, 'type': 'zagnut'})
        the_dict = tu.get_singleton_document('zagnut')

        assert the_dict
        assert the_dict['_id'] == str(doc_id)
Beispiel #2
0
    def test_get_document_fetches_a_document_with_the_proper_id_supplied_as_uuid(self):
        doc_id = uuid.uuid4()
        tu.save_document({'_id': doc_id, 'type': 'zagnut'})
        the_dict = tu.get_document(doc_id)

        assert the_dict
        assert the_dict['_id'] == str(doc_id)
Beispiel #3
0
    def test_save_document_fails_when_no_id(self):
        dict_in = {'type': 'wookie'}
        with pytest.raises(DocumentConfigurationError) as exception_info:
            tu.save_document(dict_in)

        assert 'trying to save the document with no id' in str(
            exception_info.value)
Beispiel #4
0
    def test_get_singleton_document_succeeds_when_one_document_is_found(self):
        doc_id = uuid.uuid4()
        tu.save_document({'_id': doc_id, 'type': 'zagnut'})
        the_dict = tu.get_singleton_document('zagnut')

        assert the_dict
        assert the_dict['_id'] == str(doc_id)
Beispiel #5
0
    def test_save_document_works_when_document_is_complete(self):
        doc_id = uuid.uuid4()
        dict_in = {'_id': doc_id,
                   'type': 'wookie'}
        tu.save_document(dict_in)

        assert tu.item_exists(doc_id, 'any')
Beispiel #6
0
    def test_save_document_casts_id_to_string(self):
        doc_id = uuid.uuid4()
        dict_in = {'_id': doc_id, 'type': 'wookie'}
        tu.save_document(dict_in)

        the_retrieved_doc = current_app.db[str(doc_id)]
        assert type(the_retrieved_doc['_id']).__name__ == 'unicode'
Beispiel #7
0
    def test_item_exists_returns_false_when_item_exists_but_doesnt_match_type(
            self):
        item_id = uuid.uuid4()
        doc_1 = {'_id': str(item_id), 'type': 'picture'}
        tu.save_document(doc_1)

        assert not tu.item_exists(item_id, 'exterminator')
Beispiel #8
0
    def test_get_singleton_document_fails_when_more_than_one_documents_exist(self):
        tu.save_document({'_id': uuid.uuid4(), 'type': 'marathon'})
        tu.save_document({'_id': uuid.uuid4(), 'type': 'marathon'})
        with pytest.raises(DocumentConfigurationError) as exception_info:
            tu.get_singleton_document('marathon')

        error_string = 'more than one document found of type marathon, expected singleton'
        assert error_string in str(exception_info.value)
Beispiel #9
0
    def test_save_document_fails_when_no_type(self):
        doc_id = uuid.uuid4()
        dict_in = {'_id': doc_id}
        with pytest.raises(DocumentConfigurationError) as exception_info:
            tu.save_document(dict_in)

        error_string = 'trying to save the document with no value for type: {0}'.format(str(doc_id))
        assert error_string in str(exception_info.value)
Beispiel #10
0
    def test_get_document_fetches_a_document_with_the_proper_id_supplied_as_uuid(
            self):
        doc_id = uuid.uuid4()
        tu.save_document({'_id': doc_id, 'type': 'zagnut'})
        the_dict = tu.get_document(doc_id)

        assert the_dict
        assert the_dict['_id'] == str(doc_id)
Beispiel #11
0
    def test_save_document_casts_id_to_string(self):
        doc_id = uuid.uuid4()
        dict_in = {'_id': doc_id,
                   'type': 'wookie'}
        tu.save_document(dict_in)

        the_retrieved_doc = current_app.db[str(doc_id)]
        assert type(the_retrieved_doc['_id']).__name__ == 'unicode'
Beispiel #12
0
    def test_item_exists_returns_true_when_item_exists_type_any(self):
        item_id = uuid.uuid4()
        doc_1 = {
            '_id': str(item_id),
            'type': 'picture'
        }
        tu.save_document(doc_1)

        assert tu.item_exists(item_id, 'any')
Beispiel #13
0
    def test_get_singleton_document_fails_when_more_than_one_documents_exist(
            self):
        tu.save_document({'_id': uuid.uuid4(), 'type': 'marathon'})
        tu.save_document({'_id': uuid.uuid4(), 'type': 'marathon'})
        with pytest.raises(DocumentConfigurationError) as exception_info:
            tu.get_singleton_document('marathon')

        error_string = 'more than one document found of type marathon, expected singleton'
        assert error_string in str(exception_info.value)
Beispiel #14
0
    def test_save_document_fails_when_no_type(self):
        doc_id = uuid.uuid4()
        dict_in = {'_id': doc_id}
        with pytest.raises(DocumentConfigurationError) as exception_info:
            tu.save_document(dict_in)

        error_string = 'trying to save the document with no value for type: {0}'.format(
            str(doc_id))
        assert error_string in str(exception_info.value)
Beispiel #15
0
    def test_get_singleton_document_fails_when_zero_documents_exist(self):
        doc_id = uuid.uuid4()
        dict_in = {'_id': doc_id, 'type': 'twix'}
        tu.save_document(dict_in)
        with pytest.raises(NotFoundError) as exception_info:
            tu.get_singleton_document('skittles')

        error_string = 'no document found of type skittles, expected singleton'
        assert error_string in str(exception_info.value)
Beispiel #16
0
    def test_item_exists_returns_false_when_item_exists_but_doesnt_match_type(self):
        item_id = uuid.uuid4()
        doc_1 = {
            '_id': str(item_id),
            'type': 'picture'
        }
        tu.save_document(doc_1)

        assert not tu.item_exists(item_id, 'exterminator')
Beispiel #17
0
    def test_get_singleton_document_fails_when_zero_documents_exist(self):
        doc_id = uuid.uuid4()
        dict_in = {'_id': doc_id,
                   'type': 'twix'}
        tu.save_document(dict_in)
        with pytest.raises(NotFoundError) as exception_info:
            tu.get_singleton_document('skittles')

        error_string = 'no document found of type skittles, expected singleton'
        assert error_string in str(exception_info.value)
Beispiel #18
0
    def test_save_document_removes_dynamically_calculated_attributes(self):
        doc_id = uuid.uuid4()
        dict_in = {'_id': doc_id, 'type': 'wookie'}
        one_dynamic_attr_name = tu.dynamically_calculated_attributes[0]
        dict_in[one_dynamic_attr_name] = 'something'
        tu.save_document(dict_in)

        the_saved_doc = current_app.db[str(doc_id)]

        assert one_dynamic_attr_name not in the_saved_doc
Beispiel #19
0
    def test_get_document_with_exception_throws_exception_when_document_of_specified_type_doesnt_exist(self):
        doc_id = uuid.uuid4()
        dict_in = {'_id': doc_id,
                   'type': 'twix'}
        tu.save_document(dict_in)
        with pytest.raises(NotFoundError) as exception_info:
            tu.get_document_with_exception(doc_id, document_type='skittles')

        error_string = 'No document of type skittles found for id {0}'.format(str(doc_id))
        assert error_string in str(exception_info.value)
Beispiel #20
0
    def test_get_document_with_exception_throws_exception_when_document_of_specified_type_doesnt_exist(
            self):
        doc_id = uuid.uuid4()
        dict_in = {'_id': doc_id, 'type': 'twix'}
        tu.save_document(dict_in)
        with pytest.raises(NotFoundError) as exception_info:
            tu.get_document_with_exception(doc_id, document_type='skittles')

        error_string = 'No document of type skittles found for id {0}'.format(
            str(doc_id))
        assert error_string in str(exception_info.value)
Beispiel #21
0
    def test_save_document_removes_dynamically_calculated_attributes(self):
        doc_id = uuid.uuid4()
        dict_in = {'_id': doc_id,
                   'type': 'wookie'}
        one_dynamic_attr_name = tu.dynamically_calculated_attributes[0]
        dict_in[one_dynamic_attr_name] = 'something'
        tu.save_document(dict_in)

        the_saved_doc = current_app.db[str(doc_id)]

        assert one_dynamic_attr_name not in the_saved_doc
Beispiel #22
0
    def test_get_document_with_exception_throws_exception_when_no_document_of_any_type_exists_for_requested_id(self):
        doc_id = uuid.uuid4()
        dict_in = {'_id': doc_id,
                   'type': 'twix'}
        tu.save_document(dict_in)
        second_doc_id = uuid.uuid4()
        with pytest.raises(NotFoundError) as exception_info:
            tu.get_document_with_exception(second_doc_id)

        error_string = 'No document of type any found for id {0}'.format(str(second_doc_id))
        assert error_string in str(exception_info.value)
Beispiel #23
0
def save_generic(document_in, document_type):  # a wrapper function just to have consistent naming and function location
    '''
    requires document to have at least _id and type
    '''
    if '_id' in document_in:
        if 'type' not in document_in:
             raise DocumentConfigurationError('trying to save the document with no value for type')
        if document_in['type'] != document_type:
             raise DocumentConfigurationError('trying to save the document that is not of type {0}'.format(str(document_type)))
        save_document(document_in)
    else:
         raise DocumentConfigurationError('trying to save a document with no id')
Beispiel #24
0
    def test_get_document_with_exception_throws_exception_when_no_document_of_any_type_exists_for_requested_id(
            self):
        doc_id = uuid.uuid4()
        dict_in = {'_id': doc_id, 'type': 'twix'}
        tu.save_document(dict_in)
        second_doc_id = uuid.uuid4()
        with pytest.raises(NotFoundError) as exception_info:
            tu.get_document_with_exception(second_doc_id)

        error_string = 'No document of type any found for id {0}'.format(
            str(second_doc_id))
        assert error_string in str(exception_info.value)
Beispiel #25
0
def update_generic(document_in, document_type):
    '''
    requires document to have at least _id and type
    '''
    if '_id' in document_in:
        the_id = cast_uuid_to_string(document_in['_id'])
        if not item_exists(the_id, 'any'):
            raise DocumentConfigurationError('trying to update {0} when no document exists for that id'.format(the_id))
        if not item_exists(the_id, document_type):
            raise DocumentConfigurationError('trying to alter document type for id {0} during update'.format(the_id))
        save_document(document_in)
    else:
         raise DocumentConfigurationError('trying to update a document with no id')
Beispiel #26
0
    def test_save_document_fails_when_no_id(self):
        dict_in = {'type': 'wookie'}
        with pytest.raises(DocumentConfigurationError) as exception_info:
            tu.save_document(dict_in)

        assert 'trying to save the document with no id' in str(exception_info.value)
Beispiel #27
0
    def test_save_document_works_when_document_is_complete(self):
        doc_id = uuid.uuid4()
        dict_in = {'_id': doc_id, 'type': 'wookie'}
        tu.save_document(dict_in)

        assert tu.item_exists(doc_id, 'any')
Beispiel #28
0
    def test_item_exists_returns_true_when_item_exists_type_any(self):
        item_id = uuid.uuid4()
        doc_1 = {'_id': str(item_id), 'type': 'picture'}
        tu.save_document(doc_1)

        assert tu.item_exists(item_id, 'any')