Example #1
0
 def test_simple5_version_errors(self):
     """garbage in check, bad versions"""
     raises(AttributeError, lambda: Version('1.2.3', scheme=Simple5VersionScheme))
     raises(AttributeError, lambda: Version('1.2.3.', scheme=Simple5VersionScheme))
     # raises(AttributeError, lambda: Version('1.2.3.4', scheme=Simple5VersionScheme))
     raises(AttributeError, lambda: Version('1.2.3.4.', scheme=Simple5VersionScheme))
     raises(AttributeError, lambda: Version('1.2.3.4.5.', scheme=Simple5VersionScheme))
     raises(AttributeError, lambda: Version('1.2.3.4.5.6', scheme=Simple5VersionScheme))
def test_raise_FileNotFound_getChunkLocations():
    # Arrange
    master_server_handler = MasterServerHandler()
    master_server_handler.file_name_to_file_info["kabuk"] = FileInfo("kabuk", get_length_by_handles_count(23))

    with raises(FileNotFoundException):
        master_server_handler.getChunkLocations("shnitzel", randint(0, 100), randint(0, 100))
    def test_get_official_copy_data_throws_exception_when_api_returns_500_response(
            self, mock_get):

        with raises(Exception) as e:
            api_client.get_official_copy_data('title123')

        assert 'API returned an unexpected response (500)' in str(e)
    def test_get_official_copy_data_throws_exception_when_200_response_body_is_not_json(
            self, mock_get):

        with raises(Exception) as e:
            api_client.get_official_copy_data('title123')

        assert 'API response body is not JSON' in str(e)
Example #5
0
def test_save_item_with_missing_attr(fx_test_model):
    fx_test_model.create_table()
    item = fx_test_model(
        hash_key_attr='hash_key',
        range_key_attr='range_key'
    )
    with raises(NullAttributeException):
        item.save()
Example #6
0
def test_put_item_with_missing_attr(fx_test_model):
    fx_test_model.create_table()
    attrs = {
        'hash_key_attr': 'hash_key',
        'range_key_attr': 'range_key'
    }
    with raises(NullAttributeException):
        fx_test_model.put_item(**attrs)
Example #7
0
def test_put_item_with_missing_attr(fx_test_model):
    fx_test_model.create_table()
    attrs = {
        'hash_key_attr': 'hash_key',
        'range_key_attr': 'range_key'
    }
    with raises(NullAttributeException):
        fx_test_model.put_item(**attrs)
Example #8
0
def test_save_item_with_missing_attr(fx_test_model):
    fx_test_model.create_table()
    item = fx_test_model(
        hash_key_attr='hash_key',
        range_key_attr='range_key'
    )
    with raises(NullAttributeException):
        item.save()
Example #9
0
def test_delete_item(fx_test_model):
    fx_test_model.create_table()

    hash_key_value = 'Hash Key Value'
    range_key_value = 'Range Key Value'
    attr1_value = 'Attribute1 Value'
    fx_test_model.put_item(
        hash_key_attr=hash_key_value,
        range_key_attr=range_key_value,
        attr_1=attr1_value
    )

    item = fx_test_model.get_item(hash_key_value, range_key_value)
    item.delete()
    with raises(ItemNotFoundException):
        fx_test_model.get_item(hash_key_value, range_key_value)
Example #10
0
def test_delete_item(fx_test_model):
    fx_test_model.create_table()

    hash_key_value = 'Hash Key Value'
    range_key_value = 'Range Key Value'
    attr1_value = 'Attribute1 Value'
    fx_test_model.put_item(
        hash_key_attr=hash_key_value,
        range_key_attr=range_key_value,
        attr_1=attr1_value
    )

    item = fx_test_model.get_item(hash_key_value, range_key_value)
    item.delete()
    with raises(ItemNotFoundException):
        fx_test_model.get_item(hash_key_value, range_key_value)
Example #11
0
def test_batch_write(fx_query_test_model):

    with fx_query_test_model.batch_write() as batch:
        for i in range(200):
            batch.put_item(published_at=str(i), title=str(i))
    assert fx_query_test_model.scan().count() == 200

    with fx_query_test_model.batch_write() as batch:
        for i in range(10):
            batch.delete_item(str(i), str(i))

        for i in range(200, 300):
            batch.put_item(published_at=str(i), title=str(i))
    assert fx_query_test_model.scan().count() == 290

    with raises(NullAttributeException):
        with fx_query_test_model.batch_write() as batch:
            batch.put_item(published_at=500)
Example #12
0
def test_condition_not_in_key_conditions():
    with raises(ConditionNotRecognizedException):
        build_condition({'title__contains': 'title'}, KEY_CONDITIONS)
Example #13
0
def test_list_page_non_positive():
    with raises(ValueError):
        crm.list_contacts(pages=-1)
Example #14
0
def test_contact_non_200():
    httpretty.register_uri(httpretty.GET,
                           crm.url.format(url='contacts/10000/'),
                           status=404)
    with raises(HTTPError):
        crm.show_contact(10000)
Example #15
0
def test_list_page_non_positive():
    with raises(ValueError):
        crm.list_contacts(pages=-1)
Example #16
0
def test_list_page_no_number():
    with raises(ValueError):
        crm.list_contacts(pages='3')
Example #17
0
def test_encrypt_should_raise_exception_when_key_is_less_than_1():
    key = random.randint(-10, 0)
    with raises(ValueError) as exception:
        encrypt('a', key)
    assert str(exception.value) == 'Please use a valid integer key between 1 and 25.'
Example #18
0
def test_encrypt_should_raise_exception_when_key_is_not_int():
    key = 'encrypt'
    with raises(ValueError) as exception:
        encrypt('a', key)
    assert str(exception.value) == 'Please use a valid integer key between 1 and 25.'
Example #19
0
def test_set_attribute_invalidate(fx_model_with_set_attr):
    with raises(ValueError):
        fx_model_with_set_attr.put_item(hash_key='2', attr={1, 2})
Example #20
0
def test_cannot_register_non_entities():
    class Dummy(object):
        pass

    with raises(ValueError):
        register(Dummy)
Example #21
0
def test_decrypt_should_raise_exception_when_key_is_greater_than_25():
    key = random.randint(26, 100)
    with raises(ValueError) as exception:
        decrypt('a', key)
    assert str(
        exception.value) == 'Please use a valid integer key between 1 and 25.'
Example #22
0
def test_invalid_method():
    with raises(ValueError):
        # noinspection PyProtectedMember
        crm._request('invalid_method', 'localhost', (None, None), {})
Example #23
0
def test_encrypt_should_raise_exception_when_key_is_less_than_1():
    key = random.randint(-10, 0)
    with raises(ValueError) as exception:
        encrypt('a', key)
    assert str(
        exception.value) == 'Please use a valid integer key between 1 and 25.'
Example #24
0
def test_decrypt_should_raise_exception_when_key_is_not_int():
    key = 'decrypt'
    with raises(ValueError) as exception:
        decrypt('a', key)
    assert str(
        exception.value) == 'Please use a valid integer key between 1 and 25.'
Example #25
0
def test_contact_non_200():
    httpretty.register_uri(httpretty.GET, crm.url.format(url='contacts/10000/'), status=404)
    with raises(HTTPError):
        crm.show_contact(10000)
Example #26
0
    def test_pep440_version_errors(self):
        """garbage in check, bad versions"""
        raises(AttributeError, lambda: Version('1.', scheme=Pep440VersionScheme))
        raises(AttributeError, lambda: Version('1-2', scheme=Pep440VersionScheme))
        raises(AttributeError, lambda: Version('1_2', scheme=Pep440VersionScheme))
        raises(AttributeError, lambda: Version('1.2.3.a4', scheme=Pep440VersionScheme))
        raises(AttributeError, lambda: Version('1.2.3-a4', scheme=Pep440VersionScheme))
        raises(AttributeError, lambda: Version('1.2.3_a4', scheme=Pep440VersionScheme))
        raises(AttributeError, lambda: Version('1.2.3a4-foo5', scheme=Pep440VersionScheme))
        raises(AttributeError, lambda: Version('1.2.3a4.foo5', scheme=Pep440VersionScheme))

        # invalid local versions
        raises(AttributeError, lambda: Version('1.2.3.dev6+.1', scheme=Pep440VersionScheme))
        raises(AttributeError, lambda: Version('1.2.3.dev6+1.', scheme=Pep440VersionScheme))
        raises(AttributeError, lambda: Version('1.2.3.dev6+1(a)2', scheme=Pep440VersionScheme))
Example #27
0
def test_projectblog_non_200():
    httpretty.register_uri(httpretty.GET, crm.url.format(url='projectblogs/10000/'), status=404)
    with raises(HTTPError):
        crm.show_projectblog(10000)
Example #28
0
 def test_simple4_version_errors(self):
     """garbage in check, bad versions"""
     raises(AttributeError, lambda: Version('1.2.3', scheme=Simple4VersionScheme))
     raises(AttributeError, lambda: Version('1.2.3.', scheme=Simple4VersionScheme))
     raises(AttributeError, lambda: Version('1.2.3.4.', scheme=Simple4VersionScheme))
     raises(AttributeError, lambda: Version('1.2.3.4.5', scheme=Simple4VersionScheme))
Example #29
0
def test_invalid_entity():
    with raises(ValueError):
        # noinspection PyProtectedMember
        crm._list(entity='invalid_entity')
Example #30
0
def test_decrypt_should_raise_exception_when_key_is_greater_than_25():
    key = random.randint(26, 100)
    with raises(ValueError) as exception:
        decrypt('a', key)
    assert str(exception.value) == 'Please use a valid integer key between 1 and 25.'
Example #31
0
def test_projectblog_non_200():
    httpretty.register_uri(httpretty.GET,
                           crm.url.format(url='projectblogs/10000/'),
                           status=404)
    with raises(HTTPError):
        crm.show_projectblog(10000)
Example #32
0
def test_invalid_entity():
    with raises(ValueError):
        # noinspection PyProtectedMember
        crm._list(entity='invalid_entity')
Example #33
0
def test_list_page_no_number():
    with raises(ValueError):
        crm.list_contacts(pages='3')
Example #34
0
def test_invalid_method():
    with raises(ValueError):
        # noinspection PyProtectedMember
        crm._request('invalid_method', 'localhost', (None, None), {})
Example #35
0
def test_init_solve_missing_cred():
    with raises(TypeError):
        Solve360()
    with raises(ValueError):
        Solve360(None, None)
Example #36
0
 def test_variable_dotted_errors(self):
     raises(AttributeError, lambda: Version('1.', scheme=VariableDottedIntegerVersionScheme))
     raises(AttributeError, lambda: Version('1.2.', scheme=VariableDottedIntegerVersionScheme))
     raises(AttributeError, lambda: Version('1.2.3.', scheme=VariableDottedIntegerVersionScheme))
     raises(AttributeError, lambda: Version('1.2.3.4.', scheme=VariableDottedIntegerVersionScheme))
     raises(AttributeError, lambda: Version('1.2.3.4.5.', scheme=VariableDottedIntegerVersionScheme))
Example #37
0
def test_init_solve_missing_cred():
    with raises(TypeError):
        Solve360()
    with raises(ValueError):
        Solve360(None, None)
Example #38
0
def test_scalar_attribute_invalidate(fx_model_with_number_attr):
    with raises(ValueError):
        fx_model_with_number_attr.put_item(hash_key='hash', attr='12.34')
Example #39
0
def test_cannot_register_non_entities():
  class Dummy(object):
    pass

  with raises(ValueError):
    register(Dummy)