Exemplo n.º 1
0
 def test_user_can_install(self):
     with app.test_client() as c:
         response = c.get('/install')
         expect(response.status_code).to(equal(200))
         html_string = response.data.decode("utf-8")
         expect(html_string).to(contain("Install"))
         expect(html_string).to(contain("button"))
def test_get_info_all_cards(inbox_list):
    new_card = inbox_list.add_card("test_card", "card test")
    cards = inbox_list.list_cards()
    info = get_info_all_cards(cards)
    expect(info).not_to(be_empty)
    expect(info).to(contain(new_card.name))
    expect(info).to(contain(new_card.description))
Exemplo n.º 3
0
 def test_specifies_fullscreen_option(self):
     Browser()
     spy = self.fake_webdriver.driver_spy
     expect(spy).not_to(equal(None))
     expect(spy.call_history).to(have_length(1))
     _, kwargs = spy.call_history[0]
     expect(kwargs.keys()).to(contain("chrome_options"))
     opts = kwargs["chrome_options"]
     expect(opts).to(be_a(webdriver.chrome.options.Options))
     expect(opts.arguments).to(contain("start-fullscreen"))
 def test_contains_exception_message(self):
     exception = RuntimeError("failed intentionally")
     self.publish(TestEvent.suite_started)
     self.publish(TestEvent.suite_erred, exception=exception)
     self.publish(TestEvent.suite_ended)
     test = self.extract_dummy_test()
     failures = test.findall("./error")
     expect(failures).to(have_length(1))
     failure = failures[0].attrib
     expect(failure.keys()).to(contain("message"))
     expect(failure["message"]).to(contain(str(exception)))
Exemplo n.º 5
0
    def test(self):
#         expect_diff = '''\
# expected                                got
# {'spam_code': 'spam',                   {'spam_code': 'spam',
#  'spam_count': 4295,
#  'spam_id': '32102903',                  'spam_id': '32102903',
#  'spam_method': 'thorough',              'spam_method': 'thorough',
#  'spam_transaction': 'ABS32402983SAJFD   'spam_transaction': 'ABS32402983SAJFD
# AJFS',                                  AJFS',
#  'spam_type': 'full',                    'spam_type': 'full',
#  'spamspamspamspam': '2016-08-26T15:20   'spamspamspamspam': '2016-08-26T15:21
# :12Z'}                                  :12Z'}

# '''
        expect_value = {
            "spam_id": "32102903",
            "spam_code": "spam",
            "spam_count": 4295,
            "spam_method": "thorough",
            "spam_type": "full",
            "spamspamspamspam": "2016-08-26T15:20:12Z",
            "spam_transaction": "ABS32402983SAJFDAJFS"
        }
        got_value = {
            "spam_id": "32102903",
            "spam_code": "spam",
            "spam_method": "thorough",
            "spam_type": "full",
            "spamspamspamspam": "2016-08-26T15:21:12Z",
            "spam_transaction": "ABS32402983SAJFDAJFS"
        }
        expect_snippet = ("'spamspamspamspam': '2016-08-26T15:2\x1b[0;33m1\x1b[m \n\x1b[0;33m\x1b[m:12Z'}")
        with failure(contain(expect_snippet)):
            expect(got_value).to(icdiff_expects.equal(expect_value))
Exemplo n.º 6
0
 def it_should_return_the_correct_list_of_available_paths_equal_to_4_size(self):
     expected_paths = [
         [self.vertexA, self.vertexB, self.vertexC, self.vertexD]
     ]
     expect(self.paths_equal_4_size).to(have_len(1))
     for path in expected_paths:
         expect(self.paths_equal_4_size).to(contain(path))
 def test_setting_header_to_none_removes_it(self):
     key = "something"
     sut = HttpClient()
     sut.set_persistent_headers(**{key: "spam"})
     sut.set_persistent_headers(**{key: None})
     sut.get("http://albatross")
     expect(self.extract_request_headers().keys()).not_to(contain(key))
Exemplo n.º 8
0
    def test_correct_exception_raised_for_status_code_and_surveymonkey_error_code(
            self, mock, surveymonkey_exception, error_message):  # noqa:E501
        with HTTMock(mock):
            with pytest.raises(surveymonkey_exception) as e:
                self.manager.get("mocked://")

            expect(str(e.value)).to(contain(error_message))
Exemplo n.º 9
0
 def test_uses_supplied_message(self):
     expected = "Why on earth would you want to do that?"
     try:
         skip(expected)
         assert False, "No exception was raised"
     except TestSkipped as e:
         expect(str(e)).to(contain(expected))
Exemplo n.º 10
0
 async def test__set_indexes(self, *args):
     mock_ctx = {
         '_id': 'some-value',
         'service_id': 'some-id',
         'path': 'some-endpoint'
     }
     mock_db = MagicMock()
     mock_hset = CoroutineMock()
     mock_db.hset = mock_hset
     await EndpointCacher._set_indexes(mock_ctx, mock_db)
     expect(mock_hset.await_count).to(equal(1))
     for call in mock_hset.await_args_list:
         expect([endpoint_cache_service_id_index]).to(contain(call[0][0]))
         expect(call[0][1]).to(equal(mock_ctx['_id']))
         expect([mock_ctx['service_id'],
                 mock_ctx['path']]).to(contain(call[0][2]))
Exemplo n.º 11
0
 def test_handler_saves_debug_entry(self):
     # If it saves debug, we can infer that the log level is DEBUG
     # which means it will save other entries as well
     fake_module = FakeLogging()
     msg = "We represent the Lollipop Guild"
     fake_module.getLogger("something").debug(msg)
     expect([r.msg for r in fake_module.stored_records]).to(contain(msg))
Exemplo n.º 12
0
    def test_valid_request_endpoint(self, get_mock):
        """Tests that the request goes to a valid endpoint"""
        get_mock.return_value.status_code = 200

        NetworkManager.make_request(self, "API_KEY", "APP_ID", "x", "y")
        expect(get_mock.call_args_list[0][0]).to(
            contain(str.format(pydict.core.API_URL, word="x")))
Exemplo n.º 13
0
 def test_removes_unsafe_chars_from_test_name(self):
     ugly = "I' f!@#$0-_%\\^&*/()?><\",;:`blah+\t\n=.pas"
     pretty = "".join(
         map(lambda c: c
             if c in ascii_letters + digits + "-_." else "_", ugly))
     publish(test_name=ugly)
     expect(self.fake_file.filename).to(contain(pretty))
Exemplo n.º 14
0
 def test_runs_python_script_buried_in_specified_directory(self):
     path = "spinach"
     filename = self.context.os.path.join(path, "spam", "eggs",
                                          "sausage.py")
     self.fake_file(filename=filename)
     run_all(path)
     expect(self.popen_class.scripts_executed()).to(contain(filename))
Exemplo n.º 15
0
 def test_attaches_artifact_to_suite_when_no_test_named(self):
     artifact = b"fffffffffffffff"
     start_suite()
     EventBroker.publish(event=TestEvent.artifact_created,
                         artifact=artifact)
     end_suite()
     results = self.retrieve_results()
     expect(results.artifacts).to(contain(artifact))
Exemplo n.º 16
0
 def it_should_return_the_correct_list_of_available_paths_smaller_than_2_size(self):
     expected_paths = [
         [self.vertexA, self.vertexD],
         [self.vertexA, self.vertexB, self.vertexD]
     ]
     expect(self.paths_less_than_cutoff).to(have_len(2))
     for path in expected_paths:
         expect(self.paths_less_than_cutoff).to(contain(path))
Exemplo n.º 17
0
 def it_should_return_the_correct_list_of_available_paths(self):
     expected_paths = [
         [self.vertexA, self.vertexC, self.vertexD, self.vertexA],
         [self.vertexA, self.vertexB, self.vertexC, self.vertexD, self.vertexA]
     ]
     expect(self.paths).to(have_len(2))
     for path in expected_paths:
         expect(self.paths).to(contain(path))
 def test_complains_if_bucket_not_configured(self):
     self.context.unset_env("S3_BUCKET_FOR_ARTIFACTS")
     publish_artifact()
     assert 0 == len(
         self.put_spy.call_history
     ), "Detected an unexpected PUT when the bucket was not configured"
     levels = [rec.levelname for rec in self.context.logging.stored_records]
     expect(levels).to(contain("ERROR"))
Exemplo n.º 19
0
 def test_sets_full_screen(self):
     remote_spy = MasterSpy(EndlessFake())
     self.webdriver_spy.Remote = lambda *a, **k: remote_spy
     Browser()
     expect(remote_spy.attribute_spies.keys()).to(
         contain("fullscreen_window"))
     calls = remote_spy.attribute_spies["fullscreen_window"].call_history
     assert calls, "fullscreen_window was not called"
Exemplo n.º 20
0
 def test_request_headers(self):
     headers = {"X-yz": "yogurt humphrey", "Content-length": "infinite"}
     sut = HttpClient()
     sut.get("http://something", headers=headers)
     EventBroker.publish(event=TestEvent.test_failed,
                         exception=RuntimeError())
     expect(self.published["artifact"]).to(
         contain("\n".join(["%s: %s" % (k, v)
                            for k, v in headers.items()])))
Exemplo n.º 21
0
 def test_request_method_and_url(self):
     method = "HEAD"
     sut = HttpClient()
     url = "http://i.love2spam.net/spam"
     getattr(sut, method.lower())(url)
     EventBroker.publish(event=TestEvent.test_failed,
                         exception=RuntimeError())
     expect(self.published["artifact"]).to(
         contain("\n%s %s" % (method, url)))
 def test_contains_exception_stack_trace(self):
     exception = RuntimeError("failed intentionally")
     self.publish(TestEvent.suite_started)
     self.publish(TestEvent.suite_erred, exception=exception)
     self.publish(TestEvent.suite_ended)
     test = self.extract_dummy_test()
     failures = test.findall("./error")
     expect(failures).to(have_length(1))
     failure = failures[0]
     expect(failure.text).to(contain(format_exception(exception)))
Exemplo n.º 23
0
 async def test__clear_indexes(self, *args):
     mock_id = 'some-value'
     mock_db = MagicMock()
     mock_hdel = CoroutineMock()
     mock_db.hdel = mock_hdel
     await EndpointCacher._clear_indexes(mock_id, mock_db)
     expect(mock_hdel.await_count).to(equal(1))
     for call in mock_hdel.await_args_list:
         expect([endpoint_cache_service_id_index]).to(contain(call[0][0]))
         expect(call[0][1]).to(equal(mock_id))
Exemplo n.º 24
0
    def test_user_can_be_thanked(self, mocker):
        with app.test_client() as c:
            mocker.patch.object(pyBot, 'auth')
            pyBot.auth.return_value = True
            response = c.get('/thanks')

            expect(response.status_code).to(equal(200))

            html_string = response.data.decode('utf-8')
            expect(html_string).to(contain('Thanks for installing!'))
Exemplo n.º 25
0
 def test_response_headers(self):
     headers = {"X-yz": "Sam the spammer", "Content-length": "2"}
     self.fake_requests.response.headers = headers
     sut = HttpClient()
     sut.get("http://something")
     EventBroker.publish(event=TestEvent.test_failed,
                         exception=RuntimeError())
     expect(self.published["artifact"]).to(
         contain("\n".join(["%s: %s" % (k, v)
                            for k, v in headers.items()])))
Exemplo n.º 26
0
 async def test_set_indexes(self, *args):
     mock_ctx = {
         '_id': 'some-value',
         'path': 'some-path',
         'host': 'some-host',
         'status_code': 'some-value',
         'rule_id': 'some-value',
     }
     mock_db = MagicMock()
     mock_hset = CoroutineMock()
     mock_db.hset = mock_hset
     await RateLimiter._set_indexes(mock_ctx, mock_db)
     args[0].assert_awaited()
     for call in mock_hset.await_args_list:
         expect([
             rule_status_code_index, entry_rule_id_index, entry_host_index
         ]).to(contain(call[0][0]))
         expect(call[0][1]).to(equal(mock_ctx['_id']))
         expect([mock_ctx[key]
                 for key in mock_ctx.keys()]).to(contain(call[0][2]))
Exemplo n.º 27
0
 def test_applies_affect_only_functions_flag_recursively(self):
     child = EmptyFake()
     child.value = 7
     parent = EmptyFake()
     parent.get_child = lambda: child
     parent_spy = MasterSpy(parent, affect_only_functions=False)
     parent_spy.get_child()
     func_spy = parent_spy.attribute_spies["get_child"]
     ret_spy = func_spy.return_value_spies[0]
     ret_spy.value
     expect(ret_spy.attribute_spies.keys()).to(contain("value"))
Exemplo n.º 28
0
    def test_doc_from_code_doc(self, capsys):

        parser = argparse.ArgumentParser()
        JustOneCommandGroup().build(parser.add_subparsers())
        try:
            parser.parse_args(['demo', 'callme', '--help'])
        except SystemExit:
            pass
        captured = capsys.readouterr()

        expect(captured.out).to(contain('Calls me, maybe.'))
Exemplo n.º 29
0
 def test_outputs_captured_stdout_on_proc_exit(self):
     expected = "Our chief weapons are suprise, blah blah\n"
     unexpected = "wrong!\n"
     spy = StringIO()
     self.context.inject(sys.stdout, spy)
     path = "ximinez"
     proc = FakePopen(complete=False, exit_code=0)
     proc.fake_stdout(unexpected)
     filename = os.path.join(path, "something.py")
     self.fake_file(filename)
     self.popen_class.canned_objects[filename] = proc
     t = self.context.create_time_controller(target=partial(run_all, path))
     t.start()
     sleep(0.05)
     proc.fake_stdout(expected)
     proc.complete()
     t.join()
     actual = spy.getvalue()
     expect(actual).not_to(contain(unexpected))
     expect(actual).to(contain(expected))
Exemplo n.º 30
0
 async def test__clear_indexes(self, *args):
     mock_id = 'some-value'
     mock_db = MagicMock()
     mock_hdel = CoroutineMock()
     mock_db.hdel = mock_hdel
     await RateLimiter._clear_indexes(mock_id, mock_db)
     args[0].assert_awaited()
     for call in mock_hdel.await_args_list:
         expect([
             rule_status_code_index, entry_rule_id_index, entry_host_index
         ]).to(contain(call[0][0]))
         expect(call[0][1]).to(equal(mock_id))
Exemplo n.º 31
0
 def test_attaches_artifact_to_named_test(self):
     artifact = b"bbbbbbbbbbbbbbbbbb"
     name = "Bobbb"
     start_suite()
     start_test(name)
     EventBroker.publish(event=TestEvent.artifact_created,
                         test_name=name,
                         artifact=artifact)
     end_test(name)
     end_suite()
     results = self.retrieve_results()
     expect(results.tests).to(have_length(1))
     expect(results.tests[0].artifacts).to(contain(artifact))
Exemplo n.º 32
0
    def test_client_post_invalid_action(self, client, token_generator):
        headers = {'content-type': 'application/json', 'authorization': f'bearer {token_generator.get_token(client)}'}
        user_ids = post_users(USERS, client, token_generator.get_token(client))
        client_ids = self._post_clients(client, user_ids, token_generator)

        client_to_patch = client_ids[0]

        response = client.post('/clients?action=some_invalid_action',
                               data=json.dumps({"id": client_to_patch}), headers=headers)
        expect(response.status_code).to(equal(422))
        expect(response.json['messages']).to(contain("Invalid query param!"))

        self._cleanup(client, token_generator, user_ids=user_ids)
Exemplo n.º 33
0
 def test_sends_content_type(self):
     fake = FakeHttpClient()
     url = "http://yadda.dada"
     fake.get_responses[url] = FakeResponse("""
         <html><body><form action="spam" method="POST"/></body></html>
         """)
     form = HtmlForm(http_client=fake, url=url, xpath="//form")
     form.submit()
     _, args, kwargs = fake.post_requests[-1]
     expect(kwargs.keys()).to(contain("headers"))
     expect(kwargs["headers"]).to(
         contain_key_with_value("Content-type",
                                "application/x-www-form-urlencoded"))
from co import factory, errors

from expects import expect, be_true, contain, raise_error

with description('Follow user'):
    with before.each:
        self.nickname = '@foolano'
        self.other_nickname = '@da_kewl_guru'
        self.service = factory.create_users_service()

    with it('returns all users followed by a user'):
        self.service.register(self.nickname)
        self.service.register(self.other_nickname)

        self.service.follow_to(self.nickname, self.other_nickname)

        expect(self.service.follows_to(self.nickname)).to(contain(self.other_nickname))

    with context('when user is not registered'):
        with it('raises an error'):
            self.service.register(self.other_nickname)

            expect(lambda: self.service.follow_to(self.nickname, self.other_nickname)).to(raise_error(errors.UserDoesNotExistError))

    with context('when target user is not registered'):
        with it('raises an error'):
            self.service.register(self.nickname)

            expect(lambda: self.service.follow_to(self.nickname, self.other_nickname)).to(raise_error(errors.UserDoesNotExistError))
Exemplo n.º 35
0
 def it_should_return_the_urls_only_for_that_user(self):
     expect(self.result).to(have_len(2))
     for item in self.result:
         expect(self.alice_urls).to(contain(item))
Exemplo n.º 36
0
 def it_should_have_a_body_with_not_found_message(self):
     expect(self.result.text).to(contain("The document has not found."))
Exemplo n.º 37
0
 def it_should_have_a_body_with_a_redirect_message_with_the_url(self):
     expect(self.result.text).to(contain("Moved Permanently"))
Exemplo n.º 38
0
    with before.each:
        self.a_link = one_link()
        self.linkstore = an_in_memory_sqlite_linkstore()
        self.a_new_tag = 'a new tag'

    with context('modifying tags for one link'):
        with before.each:
            self.linkstore.save(self.a_link)

            self.one_of_the_orignal_tags = self.a_link.tags[0]
            self.linkstore.modify_tag(self.a_link, {self.one_of_the_orignal_tags: self.a_new_tag})

            self.modified_link = self.linkstore.get_all()[0]

        with it('adds the new tag'):
            expect(self.modified_link.tags).to(contain(self.a_new_tag))

        with it('removes the old tag'):
            expect(self.modified_link.tags).not_to(contain(self.one_of_the_orignal_tags))

    with context('modifying tags for all links'):
        with before.each:
            self.one_of_the_orignal_tags = 'the original tag'

            for link in some_links_with_at_lesat_the_tags((self.one_of_the_orignal_tags,)):
                self.linkstore.save(link)

            self.linkstore.modify_tag_globally({self.one_of_the_orignal_tags: self.a_new_tag})

        with it('adds the new tag'):
            for modified_link in self.linkstore.get_all():
        with it('accomplish another example'):
            provided_filename = '/tmp/example2'
            generated_filename = self.example2.save(provided_filename)
            expect(isfile(generated_filename)).to(be_true)

    with context('save barcode in a file with extension'):
        with it('create a filename with extension if it is not provided'):
            path = '/tmp/example-c57'
            file = self.example_c57.save(path)
            expect(file).to(contain_exactly('/tmp/example-c57.svg'))

        with it('create a filename with only one extension if it is provided'):
            path = '/tmp/example-c57.svg'
            file = self.example_c57.save(path)
            expect(file).to(contain_exactly('/tmp/example-c57.svg'))

    with context('SVG barcode'):
        with it('accomplish the example of cuaderno57.pdf'):
            svg = self.example_c57.svg()
            expect(svg).to(contain('<svg', '</svg>'))

        with it('accomplish another example'):
            path = '/tmp/example1'
            svg = self.example1.svg()
            expect(svg).to(contain('<svg', '</svg>'))

        with it('accomplish another example'):
            path = '/tmp/example2'
            svg = self.example2.svg()
            expect(svg).to(contain('<svg', '</svg>'))
Exemplo n.º 40
0
                dulwich_repo = porcelain.init(repo_path)

                assert_repo_exists_at_given_path_after_init(repo_path)

        with it('should create a new repo if it does not exist'):
            with TemporaryDirectory() as dir_name:
                repo_path = Path(dir_name)

                assert_repo_exists_at_given_path_after_init(repo_path)

    with context('add_all'):
        with it("should add new files"):
            with TemporaryDirectory() as dir_name:
                repo, file = repo_with_new_file(dir_name)

                expect(staged_files(repo)).to(contain(str(file.name).encode()))

        with it("should add modified files"):
            with TemporaryDirectory() as dir_name:
                repo, file = repo_with_new_file(dir_name)

                repo.commit()
                file.write_text("data")
                repo.stage_all()

                expect(staged_files(repo)).to(contain(str(file.name).encode()))

    with context('commit'):
        with it('performs no commit if there are no changes'):
            with TemporaryDirectory() as dir_name:
                git_mock = mock_git_interface()
Exemplo n.º 41
0
from expects import expect, contain

from ..helpers import an_in_memory_sqlite_linkstore
from ..fixtures import one_link


with description('deleting previously saved links'):
    with it('is successfully deleted'):
        a_link = one_link()
        linkstore = an_in_memory_sqlite_linkstore()
        linkstore.save(a_link)

        linkstore.delete(a_link)

        expect(linkstore.get_all()).not_to(contain(a_link))