Exemplo n.º 1
0
 async def test_frame_nested(self):
     await self.reset_and_goto_test("nested-frames.html")
     dumped_frames = TestUtil.dumpFrames(self.page.mainFrame)
     dumped_frames["0"] | should.contain(
         "http://localhost:8888/static/nested-frames.html")
     dumped_frames["1"] | should.contain(
         "http://localhost:8888/static/frame.html",
         "http://localhost:8888/static/two-frames.html",
     )
     dumped_frames["2"] | should.contain(
         "http://localhost:8888/static/frame.html",
         "http://localhost:8888/static/frame.html",
     )
Exemplo n.º 2
0
    def test_10_create_message_by_kicked_user(self):
        account_data = SignupMethods().create_test_account(generate_fields=True)
        account_id = account_data[1]['response']['id']
        data_to_encode = account_data[0]['username'] + ':' + account_data[0]['password']
        encoded_credentials = self.encoder.encode_data(data_to_encode)
        thread_auth_headers = {'Authorization': 'Basic ' + encoded_credentials}
        logging.info('Inviting user to thread %s' % self.thread_id)
        result = ThreadsMethods().invite_user_to_thread(authorization=self.thread_auth_headers,
                                                        thread_id=self.thread_id,
                                                        user_id=account_id)
        logging.info('Server returned %s' % result)
        invitation_id = result['response'][0]['id']

        logging.info('Accepting invitation to a thread %s' % self.thread_id)
        result = ThreadsMethods().accept_invitation_to_thread(authorization=thread_auth_headers,
                                                              invitation_id=invitation_id, accept=True)
        logging.info('Server returned %s' % result)
        logging.info('Kicking user from a thread %s' % self.thread_id)
        result = ThreadsMethods().kick_user_from_thread(authorization=self.thread_auth_headers,
                                                        thread_id=self.thread_id, user_id=account_id)
        logging.info('Server returned %s' % result)
        message = self.rand.generate_random_string(50)
        logging.info('Creating sample message as kicked user in thread %s' % self.thread_id)
        result = MessageMethods(self.thread_id).send_message_in_thread(authorization=thread_auth_headers,
                                                                       message=message)
        logging.info('Server returned %s' % result)
        result['code'] | should.be.equal.to(403)
        result['response']['message'].lower() | should.contain('is not a member of the thread')
Exemplo n.º 3
0
    async def test_console_event_many(self, ee_helper):
        messages = []
        ee_helper.addEventListener(self.page, Events.Page.Console,
                                   lambda m: messages.append(m))
        await self.page.evaluate("""
// A pair of time/timeEnd generates only one Console API call.
console.time('calling console.time');
console.timeEnd('calling console.time');
console.trace('calling console.trace');
console.dir('calling console.dir');
console.warn('calling console.warn');
console.error('calling console.error');
console.log(Promise.resolve('should not wait until resolved!'));
        """)
        await asyncio.sleep(0.1)
        [msg.type for msg in messages] | should.be.equal.to(
            ["timeEnd", "trace", "dir", "warning", "error", "log"])
        messages[0].text | should.contain("calling console.time")
        [msg.text for msg in messages[1:]] | should.be.equal.to([
            "calling console.trace",
            "calling console.dir",
            "calling console.warn",
            "calling console.error",
            "JSHandle@promise",
        ])
 def test_04_view_messages_as_invited_user(self):
     account_data = SignupMethods().create_test_account(
         generate_fields=True)
     account_id = account_data[1]['response']['id']
     data_to_encode = account_data[0]['username'] + ':' + account_data[0][
         'password']
     encoded_credentials = self.encoder.encode_data(data_to_encode)
     thread_auth_headers = {'Authorization': 'Basic ' + encoded_credentials}
     logging.info('Inviting user to thread %s' % self.thread_id)
     result = ThreadsMethods().invite_user_to_thread(
         authorization=self.thread_auth_headers,
         thread_id=self.thread_id,
         user_id=account_id)
     logging.info('Server returned %s' % result)
     invitation_id = result['response'][0]['id']
     logging.info('Getting messages list from thread %s' % self.thread_id)
     result = MessageMethods(
         self.thread_id).view_messages(authorization=thread_auth_headers)
     logging.info('Server returned %s' % result)
     result['code'] | should.be.equal.to(403)
     result['response']['message'].lower() | should.contain(
         'is not a member of the thread')
     logging.info('Accepting invitation to a thread %s' % self.thread_id)
     result = ThreadsMethods().accept_invitation_to_thread(
         authorization=thread_auth_headers,
         invitation_id=invitation_id,
         accept=True)
     logging.info('Server returned %s' % result)
     logging.info('Getting messages list from thread %s' % self.thread_id)
     result = MessageMethods(
         self.thread_id).view_messages(authorization=thread_auth_headers)
     logging.info('Server returned %s' % result)
     result['code'] | should.be.equal.to(200)
Exemplo n.º 5
0
 def test_07_create_thread_no_name(self):
     logging.info('Trying to create thread with no name')
     result = ThreadsMethods().create_sample_thread(
         authorization=self.thread_headers, private=False)
     logging.info('Server responded with %s' % result)
     result['code'] | should.be.equal.to(409)
     result['response']['message'].lower() | should.contain(
         'thread name required')
Exemplo n.º 6
0
 def test_04_create_too_long_message(self):
     message = self.rand.generate_random_string(301)
     logging.info('Creating sample message in thread %s' % self.thread_id)
     result = MessageMethods(self.thread_id).send_message_in_thread(authorization=self.thread_auth_headers,
                                                                    message=message)
     logging.info('Server returned %s' % result)
     result['code'] = 422
     result['response']['message'].lower() | should.contain('text has to be between 1 and 300 characters')
Exemplo n.º 7
0
 def test_08_create_thread_no_private(self):
     sample_thread = self.rand.get_date(
     ) + self.rand.generate_random_string(10)
     logging.info('Trying to create thread with no private setting')
     result = ThreadsMethods().create_sample_thread(
         authorization=self.thread_headers, thread_name=sample_thread)
     logging.info('Server responded with %s' % result)
     result['code'] | should.be.equal.to(409)
     result['response']['message'].lower() | should.contain(
         'private required')
Exemplo n.º 8
0
 def test_09_add_account_no_lastname(self):
     password = self.rand.generate_random_string(5)
     first_name = self.rand.generate_random_string(5)
     logging.info('Trying to create new test user with no password')
     result = self.signup.create_test_account(unique_username=True,
                                              password=password,
                                              firstname=first_name)
     logging.info('Server responded with %s' % result[1])
     result[1]['code'] | should.be.equal.to(409)
     result[1]['response']['message'].lower() | should.contain(
         'firstname required')
Exemplo n.º 9
0
 def test_05_create_thread_name_number(self):
     sample_thread = self.rand.get_date()
     logging.info('Trying to create sample thread')
     result = ThreadsMethods().create_sample_thread(
         authorization=self.thread_headers,
         thread_name=sample_thread,
         private=False)
     logging.info('Server responded with %s' % result)
     result['code'] = 422
     result['response']['message'].lower() | should.contain(
         'thread name must not be a number')
Exemplo n.º 10
0
 def test_03_create_thread_name_too_short(self):
     sample_thread = 'a'
     logging.info('Trying to create sample thread')
     result = ThreadsMethods().create_sample_thread(
         authorization=self.thread_headers,
         thread_name=sample_thread,
         private=False)
     logging.info('Server responded with %s' % result)
     result['code'] = 422
     result['response']['message'].lower() | should.contain(
         'thread name length must be between 2 and 50 characters')
Exemplo n.º 11
0
 def test_08_create_message_by_non_existing_user(self):
     logging.info('Creating sample message by non existing user in public thread %s' % self.thread_id)
     thread_auth_headers = {'Authorization': 'Basic ' + self.rand.generate_random_string(10)}
     message = self.rand.generate_random_string(50)
     try:
         result = MessageMethods(self.thread_id).send_message_in_thread(authorization=thread_auth_headers,
                                                                        message=message)
         result | should.be.none
     except JSONDecodeError as e:
         logging.info('Server responded with %s' % e.doc)
         e.doc.lower() | should.contain('unauthorized access')
Exemplo n.º 12
0
 def test_06_create_message_in_public_thread_as_another_not_invited_user(self):
     account_data = SignupMethods().create_test_account(generate_fields=True)
     data_to_encode = account_data[0]['username'] + ':' + account_data[0]['password']
     encoded_credentials = self.encoder.encode_data(data_to_encode)
     thread_auth_headers = {'Authorization': 'Basic ' + encoded_credentials}
     message = self.rand.generate_random_string(50)
     logging.info('Creating sample message as another user in public thread %s' % self.thread_id)
     result = MessageMethods(self.thread_id).send_message_in_thread(authorization=thread_auth_headers,
                                                                    message=message)
     logging.info('Server returned %s' % result)
     result['code'] | should.be.equal.to(403)
     result['response']['message'].lower() | should.contain('is not a member of the thread')
Exemplo n.º 13
0
 def test_11_add_account_pass_too_long(self):
     password = self.rand.generate_random_string(21)
     first_name = self.rand.generate_random_string(5)
     last_name = self.rand.generate_random_string(5)
     logging.info('Trying to create new test user')
     result = self.signup.create_test_account(password=password,
                                              firstname=first_name,
                                              lastname=last_name)
     logging.info('Server responded with %s' % result[1])
     result[1]['code'] | should.be.equal.to(422)
     result[1]['response']['message'].lower() | should.contain(
         'password length must be between 4 and 20 characters')
Exemplo n.º 14
0
 def test_10_create_thread_by_non_existing_user(self):
     sample_thread = self.rand.get_date(
     ) + self.rand.generate_random_string(10)
     logging.info('Trying to create thread with private setting as int')
     thread_headers = {
         'Authorization': 'Basic ' + self.rand.generate_random_string(10)
     }
     try:
         result = ThreadsMethods().create_sample_thread(
             authorization=thread_headers, thread_name=sample_thread)
         result | should.be.none
     except JSONDecodeError as e:
         logging.info('Server responded with %s' % e.doc)
         e.doc.lower() | should.contain('unauthorized access')
 def test_03_view_messages_as_non_invited_user(self):
     account_data = SignupMethods().create_test_account(
         generate_fields=True)
     data_to_encode = account_data[0]['username'] + ':' + account_data[0][
         'password']
     encoded_credentials = self.encoder.encode_data(data_to_encode)
     thread_auth_headers = {'Authorization': 'Basic ' + encoded_credentials}
     logging.info('Getting messages list from thread %s' % self.thread_id)
     result = MessageMethods(
         self.thread_id).view_messages(authorization=thread_auth_headers)
     logging.info('Server returned %s' % result)
     result['code'] | should.be.equal.to(403)
     result['response']['message'].lower() | should.contain(
         'is not a member of the thread')
Exemplo n.º 16
0
    def test_09_create_thread_private_not_bool(self):
        sample_thread = self.rand.get_date(
        ) + self.rand.generate_random_string(10)
        private = int(self.rand.get_date())
        logging.info('Trying to create thread with private setting as int')
        result = ThreadsMethods().create_sample_thread(
            authorization=self.thread_headers,
            thread_name=sample_thread,
            private=private)
        logging.info('Server responded with %s' % result)
        result['code'] | should.be.equal.to(422)
        result['response']['message'].lower() | should.contain(
            'private should be bool')

        private = self.rand.generate_random_string(10)
        logging.info('Trying to create thread with private setting as string')
        result = ThreadsMethods().create_sample_thread(
            authorization=self.thread_headers,
            thread_name=sample_thread,
            private=private)
        logging.info('Server responded with %s' % result)
        result['code'] | should.be.equal.to(422)
        result['response']['message'].lower() | should.contain(
            'private should be bool')
Exemplo n.º 17
0
 def test_16_add_account_username_not_string(self):
     username = self.rand.get_date()
     password = self.rand.generate_random_string(5)
     first_name = self.rand.generate_random_string(5)
     last_name = self.rand.generate_random_string(5)
     logging.info('Trying to create new test user')
     result = self.signup.create_test_account(unique_username=False,
                                              user_name=username,
                                              password=password,
                                              firstname=first_name,
                                              lastname=last_name)
     logging.info('Server responded with %s' % result[1])
     result[1]['code'] | should.be.equal.to(422)
     result[1]['response']['message'].lower() | should.contain(
         'username must not be a number')
Exemplo n.º 18
0
 def test_04_add_account_login_too_short(self):
     username = '******'
     password = self.rand.generate_random_string(5)
     first_name = self.rand.generate_random_string(5)
     last_name = self.rand.generate_random_string(5)
     logging.info('Trying to create new test user with login %s' % username)
     result = self.signup.create_test_account(unique_username=False,
                                              user_name=username,
                                              password=password,
                                              firstname=first_name,
                                              lastname=last_name)
     logging.info('Server responded with %s' % result[1])
     result[1]['code'] | should.be.equal.to(422)
     result[1]['response']['message'].lower() | should.contain(
         'username length must be between 2 and 20 characters')
Exemplo n.º 19
0
def test_parse_diff_1():
    with open("./tests/diff_1.diff") as f:
        diff, md5 = diff_parser.parse_diff(f.read())

        expected_keys = [
            "grappa/operators/__init__.py", "grappa/operators/contain.py",
            "grappa/operators/equal.py", "grappa/operators/only.py",
            "grappa/operators/present.py", 'grappa/reporters/subject.py',
            'requirements-dev.txt', 'tests/operators/only_test.py'
        ]
        list(diff.keys()) | should.be.equal.to(expected_keys)
        # Now let's check some values
        len(diff["grappa/operators/only.py"]) | should.be.equal.to(47)
        diff["grappa/operators/equal.py"][0] | should.contain(
            "a value of type \"{type}\" with data \"{value}\"")
        len(md5) | should.be.equal.to(32)
Exemplo n.º 20
0
 def test_06_create_second_thread_with_same_name(self):
     sample_thread = self.rand.get_date(
     ) + self.rand.generate_random_string(10)
     logging.info('Trying to create sample thread')
     result = ThreadsMethods().create_sample_thread(
         authorization=self.thread_headers,
         thread_name=sample_thread,
         private=False)
     logging.info('Server responded with %s' % result)
     result['code'] | should.be.equal.to(200)
     self.thread_id = result['response']['id']
     logging.info('Trying to create thread with the same name')
     result = ThreadsMethods().create_sample_thread(
         authorization=self.thread_headers,
         thread_name=sample_thread,
         private=False)
     logging.info('Server responded with %s' % result)
     result['code'] = 409
     result['response']['message'].lower() | should.contain(
         'thread name already taken')
Exemplo n.º 21
0
 def test_03_add_account_same_login(self):
     username = '******' + self.rand.get_date()
     password = self.rand.generate_random_string(5)
     first_name = self.rand.generate_random_string(5)
     last_name = self.rand.generate_random_string(5)
     logging.info('Trying to create new test user with login %s' % username)
     result = self.signup.create_test_account(unique_username=False,
                                              user_name=username,
                                              password=password,
                                              firstname=first_name,
                                              lastname=last_name)
     logging.info('Server responded with %s' % result[1])
     logging.info('Trying to create same test user with login %s' %
                  username)
     result = self.signup.create_test_account(unique_username=False,
                                              user_name=username,
                                              password=password,
                                              firstname=first_name,
                                              lastname=last_name)
     logging.info('Server responded with %s' % result[1])
     result[1]['code'] | should.be.equal.to(409)
     result[1]['response']['message'].lower() | should.contain(
         'username already taken')
Exemplo n.º 22
0
 async def test_negative_polling_value(self):
     await self.goto_empty(waitUntil="load")
     with pytest.raises(ValueError) as cm:
         await self.page.waitForFunction("() => true", polling=-100)
     str(cm.value) | should.contain(
         "Cannot poll with non-positive interval")
Exemplo n.º 23
0
 async def test_bad_polling_value(self):
     await self.goto_empty(waitUntil="load")
     with pytest.raises(ValueError) as cm:
         await self.page.waitForFunction("() => true", polling="unknown")
     str(cm.value) | should.contain("polling")
Exemplo n.º 24
0
 def test_05_create_message_no_message(self):
     logging.info('Creating sample message without message in thread %s' % self.thread_id)
     result = MessageMethods(self.thread_id).send_message_in_thread(authorization=self.thread_auth_headers)
     logging.info('Server returned %s' % result)
     result['code'] | should.be.equal.to(409)
     result['response']['message'].lower() | should.contain('text required')
Exemplo n.º 25
0
 async def test_object_handle_as_argument(self):
     await self.goto_empty(waitUntil="load")
     navigator = await self.page.evaluateHandle("() => navigator")
     navigator | should.not_be.none
     text = await self.page.evaluate("(e) => e.userAgent", navigator)
     text | should.contain("Mozilla")
Exemplo n.º 26
0
 async def test_promise_reject(self):
     await self.goto_empty(waitUntil="load")
     with pytest.raises(EvaluationError) as cm:
         await self.page.evaluate("() => not.existing.object.property")
     str(cm.value) | should.contain("not is not defined")