Example #1
0
        def creates_container_from_docker_client():
            expected_image = 'test_img'
            expected_host_config = {}
            expected_name = 'test_name'
            expected_env = {}
            expected_cmd = '/bin/sh -c "while true; do sleep 1000; done"'
            expected_cn_id = '12345'

            docker_mock = create_autospec(DockerClient, spec_set=True)
            docker_mock.create_container.return_value = {'Id': expected_cn_id}

            subject = Container(expected_image,
                                expected_host_config,
                                docker_mock,
                                name=expected_name,
                                env=expected_env)

            docker_mock.create_container\
                .assert_called_once_with(image=expected_image,
                                         host_config=expected_host_config,
                                         name=expected_name,
                                         environment=expected_env,
                                         command=expected_cmd)

            assert_that(subject.id).is_equal_to(expected_cn_id)
def test_create_gallery(graphene_client: Client):
    result = graphene_client.execute('''
    mutation {
        createGallery(name: "galleryName", public: true, position: 78) {
            gallery {
                galleryId
                name
                public
                position
            }
        }
    }
    ''')
    assert_that(json.dumps(result)).is_equal_to_ignoring_whitespace('''
    {
        "data": {
            "createGallery": {
                "gallery": {
                    "galleryId": 1,
                    "name": "galleryName",
                    "public": true,
                    "position": 78
                }
            }
        }
    }''')
    gallery = Gallery.query.get(1)
    assert_that(gallery.id).is_equal_to(1)
    assert_that(gallery.name).is_equal_to('galleryName')
    assert_that(gallery.public).is_true()
    assert_that(gallery.position).is_equal_to(78)
Example #3
0
 def test_is_after_failure(self):
     try:
         d2 = datetime.datetime.today()
         assert_that(self.d1).is_after(d2)
         fail('should have raised error')
     except AssertionError as ex:
         assert_that(str(ex)).matches('Expected <\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}> to be after <\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}>, but was not.')
Example #4
0
 def test_valid(self):
     msg = CommandMessage(original_text='.count ham',
                          text='ham',
                          sender='123_homer@localhost/Oklahomer')
     assert_that(hipchat_count(msg, {})) \
         .described_as(".count command increments count") \
         .is_equal_to('1')
Example #5
0
 def test_is_equal_to_ignoring_milliseconds_failure(self):
     try:
         d2 = datetime.datetime.today() + datetime.timedelta(days=1)
         assert_that(self.d1).is_equal_to_ignoring_milliseconds(d2)
         fail('should have raised error')
     except AssertionError as ex:
         assert_that(str(ex)).matches('Expected <\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}> to be equal to <\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}>, but was not.')
Example #6
0
 def test_is_close_to_failure(self):
     try:
         d2 = self.d1 + datetime.timedelta(minutes=5)
         assert_that(self.d1).is_close_to(d2, datetime.timedelta(minutes=1))
         fail('should have raised error')
     except AssertionError as ex:
         assert_that(str(ex)).matches('Expected <\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}> to be close to <\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}> within tolerance <\d+:\d{2}:\d{2}>, but was not.')
Example #7
0
 def test_is_close_to_bad_tolerance_arg_type_failure(self):
     try:
         d2 = datetime.datetime.today()
         assert_that(self.d1).is_close_to(d2, 123)
         fail('should have raised error')
     except TypeError as ex:
         assert_that(str(ex)).is_equal_to('given tolerance arg must be timedelta, but was <int>')
Example #8
0
 def test_is_less_than_or_equal_to_failure(self):
     try:
         d2 = datetime.datetime.today()
         assert_that(d2).is_less_than_or_equal_to(self.d1)
         fail('should have raised error')
     except AssertionError as ex:
         assert_that(str(ex)).matches('Expected <\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}> to be less than or equal to <\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}>, but was not.')
Example #9
0
 def test_is_between_bad_arg2_type_failure(self):
     try:
         d2 = datetime.datetime.today()
         assert_that(self.d1).is_between(d2, 123)
         fail('should have raised error')
     except TypeError as ex:
         assert_that(str(ex)).is_equal_to('given high arg must be datetime, but was <int>')
Example #10
0
 def test_contents_of_return_type_ascii(self):
     if sys.version_info[0] == 3:
         contents = contents_of(self.tmp.name, 'ascii')
         assert_that(contents).is_type_of(str)
     else:
         contents = contents_of(self.tmp.name, 'ascii')
         assert_that(contents).is_type_of(str)
Example #11
0
 def devices_do_not_contain_places(self, device_id: str) -> list:
     """ The opposite of `device_and_place_contain_each_other`."""
     device, _ = self.get(self.DEVICES, '', device_id)
     assert_that(device).does_not_contain('place')
     for component_id in device.get('components', []):
         component, _ = self.get(self.DEVICES, '', component_id)
         assert_that(component).does_not_contain('place')
Example #12
0
    def test_is_instance_of(self):
        assert_that(self.fred).is_instance_of(Person)
        assert_that(self.fred).is_instance_of(object)

        assert_that(self.joe).is_instance_of(Developer)
        assert_that(self.joe).is_instance_of(Person)
        assert_that(self.joe).is_instance_of(object)
Example #13
0
 def test_is_file_directory_failure(self):
     try:
         dirname = os.path.dirname(self.tmp.name)
         assert_that(dirname).is_file()
         fail('should have raised error')
     except AssertionError as ex:
         assert_that(str(ex)).matches('Expected <.*> to be a file, but was not.')
def test_is_not_same_as_failure():
    for obj in [object(), 1, 'foo', True, None, 123.456]:
        try:
            assert_that(obj).is_not_same_as(obj)
            fail('should have raised error')
        except AssertionError as ex:
            assert_that(str(ex)).matches('Expected <.+> to be not identical to <.+>, but was.')
Example #15
0
 def test_extracting_dict_missing_key_failure(self):
     people_as_dicts = [{'first_name': p.first_name, 'last_name': p.last_name} for p in self.people]
     try:
         assert_that(people_as_dicts).extracting('foo')
         fail('should have raised error')
     except ValueError as ex:
         assert_that(str(ex)).matches(r'item keys \[.*\] did not contain key <foo>')
Example #16
0
File: mv.py Project: yunify/qsctl
def step_impl(context):
    for row in context.input:
        assert_that(bucket.head_object(row["name"]).status_code
                    ).is_equal_to(404)
        assert_that(os.path.isfile("tmp/" + row["name"])).is_equal_to(True)

    sh.rm("-rf", "tmp").wait()
Example #17
0
File: ls.py Project: yunify/qsctl
def step_impl(context):
    ok = True
    for row in context.table:
        if row["name"] not in context.output:
            ok = False
            break
    assert_that(ok).is_equal_to(True)
Example #18
0
def test_create_image(graphene_client: Client):
    result = graphene_client.execute('''
    mutation {
        createImage(name: "myImage") {
            image {
                imageId
                name
                public
                keywords
            }
        }
    }
    ''')
    assert_that(json.dumps(result)).is_equal_to_ignoring_whitespace('''
    {
        "data": {
            "createImage": {
                "image": {
                    "imageId": 1,
                    "name": "myImage",
                    "public": false,
                    "keywords": []
                }
            }
        }
    }
    ''')
    image = Image.query.get(1)
    assert_that(image.id).is_equal_to(1)
    assert_that(image.name).is_equal_to('myImage')
    assert_that(image.public).is_false()
    assert_that(image.keywords).is_empty()
Example #19
0
def test_create_image_with_keywords(graphene_client: Client):
    result = graphene_client.execute('''
    mutation {
        createImage(name: "myImage", keywords: ["foo", "bar", "baz"]) {
            image {
                keywords
            }
        }
    }
    ''')
    assert_that(json.dumps(result)).is_equal_to_ignoring_whitespace('''
    {
        "data": {
            "createImage": {
                "image": {
                    "keywords": [
                        "foo",
                        "bar",
                        "baz"
                    ]
                }
            }
        }
    }
    ''')
    image = Image.query.get(1)
    assert_that([keyword.keyword for keyword in image.keywords]).contains_sequence("foo", "bar", "baz")
def test_expected_exception_all_failure():
    try:
        assert_that(func_noop).raises(RuntimeError).when_called_with('a', 'b', 3, 4, foo=1, bar=2, baz='dog')
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).is_equal_to(
            "Expected <func_noop> to raise <RuntimeError> when called with ('a', 'b', 3, 4, 'bar': 2, 'baz': 'dog', 'foo': 1).")
def test_expected_exception_one_arg_failure():
    try:
        assert_that(func_noop).raises(RuntimeError).when_called_with('foo')
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).is_equal_to(
            "Expected <func_noop> to raise <RuntimeError> when called with ('foo').")
Example #22
0
File: cp.py Project: yunify/qsctl
def step_impl(context):
    resp = bucket.list_objects()
    assert_that(sorted([i["key"] for i in resp["keys"]])
                ).is_equal_to(sorted([row["name"] for row in context.table]))

    for row in context.table:
        bucket.delete_object(row["name"])
Example #23
0
 def test_is_less_than_or_equal_to_failure(self):
     try:
         t2 = datetime.timedelta(seconds=90)
         assert_that(t2).is_less_than_or_equal_to(self.t1)
         fail('should have raised error')
     except AssertionError as ex:
         assert_that(str(ex)).matches('Expected <\d{1,2}:\d{2}:\d{2}> to be less than or equal to <\d{1,2}:\d{2}:\d{2}>, but was not.')
Example #24
0
    def test_expected_exceptions(self):
        def some_func(arg):
            raise RuntimeError('some err')

        assert_that(some_func).raises(RuntimeError).when_called_with('foo')
        assert_that(some_func).raises(RuntimeError).when_called_with('foo')\
            .is_length(8).starts_with('some').is_equal_to('some err')
Example #25
0
 def test_is_greater_than_failure(self):
     try:
         t2 = datetime.timedelta(seconds=90)
         assert_that(self.t1).is_greater_than(t2)
         fail('should have raised error')
     except AssertionError as ex:
         assert_that(str(ex)).matches('Expected <\d{1,2}:\d{2}:\d{2}> to be greater than <\d{1,2}:\d{2}:\d{2}>, but was not.')
Example #26
0
    def test__init(self):
        msg = CommandMessage(original_text='.hello',
                             text='',
                             sender='spam@localhost/ham')
        response = hipchat_hello(msg, {})

        assert_that(response) \
            .described_as(".hello initiates conversation.") \
            .is_instance_of(UserContext) \
            .has_message("Hello. How are you feeling today?")

        assert_that(response.input_options) \
            .described_as("User has two options to respond.") \
            .is_length(2)

        assert_that([o.next_step.__name__ for o in response.input_options]) \
            .described_as("Those options include 'Good' and 'Bad'") \
            .contains(hipchat_user_feeling_good.__name__,
                      hipchat_user_feeling_bad.__name__)

        assert_that(response.input_options[0].next_step("Good", {})) \
            .described_as("When 'Good,' just return text.") \
            .is_equal_to("Good to hear that.")

        assert_that(response.input_options[1].next_step("Bad", {})) \
            .described_as("When 'Bad,' continue to ask health status") \
            .is_instance_of(UserContext)
Example #27
0
    def wait_future_finish(self, future):
        sleep(.5)  # Why would I need this line?? Check later.

        ret = concurrent.futures.wait([future], 5, return_when=ALL_COMPLETED)
        if len(ret.not_done) > 0:
            logging.error("Jobs are not finished.")
        assert_that(ret.done).contains(future)
Example #28
0
File: rm.py Project: yunify/qsctl
def step_impl(context):
    for row in context.table:
        assert_that(bucket.head_object(row["name"]).status_code
                    ).is_equal_to(404 if row["deleted"] == "1" else 200)

    for row in context.table:
        bucket.delete_object(row["name"])
Example #29
0
    def test_multiple_calls_with_same_word(self):
        msg = CommandMessage(original_text='.count ham',
                             text='ham',
                             sender='123_homer@localhost/Oklahomer')
        assert_that(hipchat_count(msg, {})) \
            .described_as("First count returns 1") \
            .is_equal_to('1')

        other_msg = CommandMessage(original_text='.count ham',
                                   text='ham',
                                   sender='other@localhost/Oklahomer')
        assert_that(hipchat_count(other_msg, {})) \
            .described_as("Different counter for different message") \
            .is_equal_to('1')

        assert_that(hipchat_count(msg, {})) \
            .described_as("Same message results in incremented count") \
            .is_equal_to('2')

        reset_msg = CommandMessage(original_text='.reset_count',
                                   text='',
                                   sender='123_homer@localhost/Oklahomer')
        assert_that(hipchat_reset_count(reset_msg, {})) \
            .described_as(".reset_count command resets current count") \
            .is_equal_to("restart counting")

        assert_that(hipchat_count(msg, {})) \
            .described_as("Count restarts") \
            .is_equal_to('1')
Example #30
0
    def test_parsing_of_dependency_list_output(self):
        with open(os.path.join(os.path.dirname(__file__), 'mvn_dependency_list_output.txt'), 'r') as output_file:
            output = output_file.read()

        dependencies = self.dependency_list.parse_dependencies(output)

        assert_that(dependencies).is_length(22)
Example #31
0
def test_is_equal_ignoring_case_bad_value_type_failure():
    try:
        assert_that(123).is_equal_to_ignoring_case(12)
        fail('should have raised error')
    except TypeError as ex:
        assert_that(str(ex)).is_equal_to('val is not a string')
Example #32
0
def test_starts_with_bad_arg_empty_failure():
    try:
        assert_that('fred').starts_with('')
        fail('should have raised error')
    except ValueError as ex:
        assert_that(str(ex)).is_equal_to('given prefix arg must not be empty')
Example #33
0
def test_starts_with_bad_arg_type_failure():
    try:
        assert_that('fred').starts_with(123)
        fail('should have raised error')
    except TypeError as ex:
        assert_that(str(ex)).is_equal_to('given prefix arg must be a string')
Example #34
0
def test_starts_with_bad_value_type_failure():
    try:
        assert_that(123).starts_with(12)
        fail('should have raised error')
    except TypeError as ex:
        assert_that(str(ex)).is_equal_to('val is not a string or iterable')
Example #35
0
def test_starts_with_failure():
    try:
        assert_that('fred').starts_with('bar')
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).is_equal_to('Expected <fred> to start with <bar>, but did not.')
Example #36
0
def test_starts_with():
    assert_that('fred').starts_with('f')
    assert_that('fred').starts_with('fr')
    assert_that('fred').starts_with('fred')
Example #37
0
def test_is_equal_ignoring_case_bad_arg_type_failure():
    try:
        assert_that('fred').is_equal_to_ignoring_case(12)
        fail('should have raised error')
    except TypeError as ex:
        assert_that(str(ex)).is_equal_to('given arg must be a string')
Example #38
0
def test_is_equal_ignoring_case():
    assert_that('FOO').is_equal_to_ignoring_case('foo')
    assert_that('foo').is_equal_to_ignoring_case('FOO')
    assert_that('fOO').is_equal_to_ignoring_case('foo')
Example #39
0
def test_is_not_empty():
    assert_that('foo').is_not_empty()
Example #40
0
def test_is_equal_ignoring_case_failure():
    try:
        assert_that('foo').is_equal_to_ignoring_case('bar')
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).is_equal_to('Expected <foo> to be case-insensitive equal to <bar>, but was not.')
Example #41
0
def test_does_not_contain_list_multi_item_failure():
    try:
        assert_that('foo').does_not_contain('x','f','o')
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).is_equal_to("Expected <foo> to not contain items <'x', 'f', 'o'>, but did contain <'f', 'o'>.")
Example #42
0
def test_is_not_empty_failure():
    try:
        assert_that('').is_not_empty()
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).is_equal_to('Expected not empty string, but was empty.')
Example #43
0
def test_does_not_contain():
    assert_that('foo').does_not_contain('x')
    assert_that('foo').does_not_contain('x','y')
Example #44
0
def test_is_empty():
    assert_that('').is_empty()
Example #45
0
def test_contains_ignoring_case_list_multi_item_failure():
    try:
        assert_that(['foo','bar']).contains_ignoring_case('Foo','X','Y')
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).is_equal_to("Expected <['foo', 'bar']> to case-insensitive contain items <'Foo', 'X', 'Y'>, but did not contain <'X', 'Y'>.")
Example #46
0
def test_does_not_contain_single_item_failure():
    try:
        assert_that('foo').does_not_contain('f')
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).is_equal_to('Expected <foo> to not contain item <f>, but did.')
Example #47
0
def test_contains_ignoring_case_list_multi_elem_type_failure():
    try:
        assert_that(['foo', 123]).contains_ignoring_case('f')
        fail('should have raised error')
    except TypeError as ex:
        assert_that(str(ex)).is_equal_to('val items must all be strings')
Example #48
0
def test_contains_ignoring_case_list_multi_item_type_failure():
    try:
        assert_that(['foo','bar']).contains_ignoring_case('F', 12)
        fail('should have raised error')
    except TypeError as ex:
        assert_that(str(ex)).is_equal_to('given args must all be strings')
Example #49
0
def test_contains_ignoring_case_single_item_type_failure():
    try:
        assert_that('foo').contains_ignoring_case(12)
        fail('should have raised error')
    except TypeError as ex:
        assert_that(str(ex)).is_equal_to('given arg must be a string')
Example #50
0
def test_contains_ignoring_case_list_missinge_item_failure():
    try:
        assert_that(['foo']).contains_ignoring_case()
        fail('should have raised error')
    except ValueError as ex:
        assert_that(str(ex)).is_equal_to('one or more args must be given')
Example #51
0
def test_is_subset_of_single_item_superset():
    assert_that(['a']).is_subset_of(['a'])
    assert_that((1, )).is_subset_of((1, ))
    assert_that('ab').is_subset_of('ab')
    assert_that(set([1])).is_subset_of(set([1]))
    assert_that({'a': 1}).is_subset_of({'a': 1})
Example #52
0
def test_contains_ignoring_case_list():
    assert_that(['foo']).contains_ignoring_case('Foo')
    assert_that(['foo', 'bar', 'baz']).contains_ignoring_case('Foo')
    assert_that(['foo', 'bar', 'baz']).contains_ignoring_case('Foo', 'bAr')
    assert_that(['foo', 'bar', 'baz']).contains_ignoring_case('Foo', 'bAr', 'baZ')
Example #53
0
def test_is_not_iterable_failure():
    try:
        assert_that(['a', 'b', 'c']).is_not_iterable()
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).is_equal_to('Expected not iterable, but was.')
Example #54
0
def test_is_subset_of_failure_empty_superset():
    try:
        assert_that(['a', 'b', 'c']).is_subset_of([])
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).contains('to be subset of <>')
Example #55
0
def test_is_iterable_failure():
    try:
        assert_that(123).is_iterable()
        fail('should have raised error')
    except AssertionError as ex:
        assert_that(str(ex)).is_equal_to('Expected iterable, but was not.')
Example #56
0
def test_is_subset_of():
    assert_that(['a', 'b', 'c']).is_subset_of(['a', 'b', 'c'])
    assert_that(['a', 'b', 'c']).is_subset_of(['a', 'b', 'c', 'd'])
    assert_that(['a', 'b', 'c']).is_subset_of(['a'], ['b'], ['c'])
    assert_that(['a', 'b', 'c']).is_subset_of('a', 'b', 'c')
    assert_that(['a', 'b', 'a']).is_subset_of(['a', 'a', 'b'])
    assert_that((1, 2, 3)).is_subset_of((1, 2, 3))
    assert_that((1, 2, 3)).is_subset_of((1, 2, 3, 4))
    assert_that((1, 2, 3)).is_subset_of((1, ), (2, ), (3, ))
    assert_that((1, 2, 3)).is_subset_of(1, 2, 3)
    assert_that((1, 2, 1)).is_subset_of(1, 1, 2)
    assert_that('foo').is_subset_of('abcdefghijklmnopqrstuvwxyz')
    assert_that('foo').is_subset_of('abcdef', set(['m', 'n', 'o']), ['x', 'y'])
    assert_that(set([1, 2, 3])).is_subset_of(set([1, 2, 3, 4]))
    assert_that({'a': 1, 'b': 2}).is_subset_of({'a': 1, 'b': 2, 'c': 3})
    assert_that({'a': 1, 'b': 2}).is_subset_of({'a': 3}, {'b': 2}, {'a': 1})
Example #57
0
def test_chaining():
    assert_that(['a', 'b',
                 'c']).is_iterable().is_type_of(list).is_sorted().is_length(3)
Example #58
0
def test_is_not_iterable():
    assert_that(123).is_not_iterable()
    assert_that({'a': 1, 'b': 2, 'c': 3}).is_iterable()
Example #59
0
def test_is_sorted_failure_bad_val():
    try:
        assert_that(123).is_sorted()
        fail("should have raised error")
    except TypeError as ex:
        assert_that(str(ex)).is_equal_to('val is not iterable')
Example #60
0
def test_is_iterable():
    assert_that(['a', 'b', 'c']).is_iterable()
    assert_that((1, 2, 3)).is_iterable()
    assert_that('foo').is_iterable()
    assert_that({'a': 1, 'b': 2, 'c': 3}.keys()).is_iterable()
    assert_that({'a': 1, 'b': 2, 'c': 3}.values()).is_iterable()
    assert_that({'a': 1, 'b': 2, 'c': 3}.items()).is_iterable()