Пример #1
0
 def test_create_status(self):
     print('Testing status for path: /create/<username>/<first_name>/<last_name>/<email>')
     tester = application.test_client(self)
     username = ''.join(choice(ascii_uppercase) for i in range(choice(range(1,33))))
     first_name = ''.join(choice(ascii_uppercase) for i in range(choice(range(1,33))))
     last_name = ''.join(choice(ascii_uppercase) for i in range(choice(range(1,33))))
     email = ''.join(choice(ascii_uppercase) for i in range(23)) + "@gmail.com"
     response = tester.post(f'/create/{username}/{first_name}/{last_name}/{email}')
     self.assertEqual(response.status_code,200)
Пример #2
0
    def setUp(self):
        # First, create an instance of the Testbed class.
        self.testbed = testbed.Testbed()
        self.testbed.setup_env()
        # Then activate the testbed, which prepares the service stubs for use.
        self.testbed.activate()
        # root_path must be set the the location of queue.yaml.
        # Otherwise, only the 'default' queue will be available.
        self.testbed.init_taskqueue_stub()
        self.taskqueue_stub = self.testbed.get_stub(
            testbed.TASKQUEUE_SERVICE_NAME)

        self.testbed.init_blobstore_stub()
        self.testbed.init_search_stub()
        # Create a consistency policy that will simulate the High Replication
        # consistency model.
        self.policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(
            probability=1)
        # Initialize the datastore stub with this policy.
        self.testbed.init_datastore_v3_stub(
            consistency_policy=self.policy,
            use_sqlite=True,
            auto_id_policy=datastore_stub_util.SCATTERED)
        # Next, declare which service stubs you want to use.
        self.testbed.init_memcache_stub()
        self.testbed.init_urlfetch_stub()
        # Clear ndb's in-context cache between tests.
        # This prevents data from leaking between tests.
        # Alternatively, you could disable caching by
        # using ndb.get_context().set_cache_policy(False)
        ndb.get_context().clear_cache()
        application.config.update(SESSION_COOKIE_DOMAIN=None, testing=True)
        self.application = application
        self.test_client = application.test_client()

        # Add task queue processor
        self.task_queue = TaskQueueProcessor(self)

        urlfetch_intercept.install()
        self.addCleanup(urlfetch_intercept.uninstall)

        self.mock_pusher = MockApplication()
        self.mock_pusher.cannedresponse = ((200, {}), json.dumps({}))
        self.add_intercept('api.pusherapp.com:443', self.mock_pusher)

        self.mock_gcm = MockApplication()
        self.mock_gcm.cannedresponse = ((200, {}), json.dumps({}))
        self.add_intercept('gcm-http.googleapis.com', self.mock_gcm)
Пример #3
0
 def test_create_missing_parts(self):
     print('Testing with missing parts into the path: /create/<username>/<first_name>/<last_name>/<email>')
     tester = application.test_client(self)
     username = ''.join(choice(ascii_uppercase) for i in range(choice(range(1,33))))
     first_name = ''.join(choice(ascii_uppercase) for i in range(choice(range(1,33))))
     last_name = ''.join(choice(ascii_uppercase) for i in range(choice(range(1,33))))
     email = ''.join(choice(ascii_uppercase) for i in range(23)) + "@gmail.com"
     paths = [
         f'/create/{username}/{first_name}/{last_name}',
         f'/create/{username}/{first_name}/{email}',
         f'/create/{username}/{last_name}/{email}',
         f'/create/{first_name}/{last_name}/{email}',
         f'/{username}/{first_name}/{last_name}/{email}',
     ]
     response = tester.post(paths[choice(range(len(paths)))])
     self.assertTrue(b'"message":"No such path!"' in response.data)
Пример #4
0
 def test_update_delete(self):
     print('Testing DELETE request at path: /update/<username>/<column>/<value>')
     tester = application.test_client(self)
     random_username = ''.join(choice(ascii_uppercase) for i in range(choice(range(32))))
     cols = [
         "first_name",
         "last_name",
         "email"
     ]
     column = choice(cols)
     if column == "email":
         random_value = ''.join(choice(ascii_uppercase) for i in range(choice(range(23)))) + '@gmail.com'
     else:
         random_value = ''.join(choice(ascii_uppercase) for i in range(choice(range(32))))
     
     response = tester.post(f"/update/{random_username}/{column}/{random_value}")
     self.assertEqual(response.status_code,405)
Пример #5
0
 def test_search_unknown(self):
     print('Testing content for path: /search/POR')
     tester = application.test_client(self)
     response = tester.get("/search/POR", content_type="application/json")
     self.assertIn(b'"message":"No record found!"',response.data)
Пример #6
0
def client():
    app.testing = True
    client = app.test_client()
    yield client
Пример #7
0
def client():
    client = application.test_client()

    yield client
Пример #8
0
 def test_missing_paths_status(self):
     tester = application.test_client(self)
     random_path = ''.join(choice(printable) for i in range(choice(range(100))))
     print(f'Testing missing path: /{random_path}')
     response = tester.get(quote(f'/{random_path}'))
     self.assertTrue(response.status_code == 200)
Пример #9
0
 def test_search_status(self):
     print('Testing status for path: /search/<username>')
     tester = application.test_client(self)
     random_username = ''.join(choice(ascii_uppercase) for i in range(choice(range(32))))
     response = tester.get(f"/search/{random_username}")
     self.assertTrue(response.status_code == 200)
Пример #10
0
 def test_index_patch(self):
     print('Testing PATCH request for path: /')
     tester = application.test_client(self)
     response = tester.patch("/")
     self.assertEqual(response.status_code,405)
Пример #11
0
 def test_delete_content_known(self):
     print('Testing content type for path: /delete/<username>')
     tester = application.test_client(self)
     username = session.query(Contact).filter_by(valid_till_date = None).first().username
     response = tester.delete(f"/delete/{username}")
     self.assertIn(b'"message":"Record deleted!"',response.data)
Пример #12
0
 def test_update_known(self):
     print('Testing with known username for path: /update/<username>/<column>/<value>')
     tester = application.test_client(self)
     response = tester.patch("/update/blag0/first_name/TestName")
     self.assertIn(b'"first_name":"TestName"',response.data)
Пример #13
0
 def test_index_status(self):
     print('Testing status for path: /')
     tester = application.test_client(self)
     response = tester.get("/")
     self.assertTrue(response.status_code == 200)
Пример #14
0
 def test_missing_paths_content(self):
     tester = application.test_client(self)
     random_path = ''.join(choice(printable) for i in range(choice(range(100))))
     print(f'Testing missing path: /{random_path}')
     response = tester.get(quote(f'/{random_path}'))
     self.assertIn(b'"message":"No such path!"',response.data)
Пример #15
0
 def test_delete_delete(self):
     print('Testing DELETE request at path: /delete/<username>')
     tester = application.test_client(self)
     username = session.query(Contact).filter_by(valid_till_date = None).first().username
     response = tester.delete(f"/delete/{username}")
     self.assertTrue(response.status_code,200)
Пример #16
0
 def test_delete_content_type(self):
     print('Testing content type for path: /delete/<username>')
     tester = application.test_client(self)
     username = session.query(Contact).filter_by(valid_till_date = None).first().username
     response = tester.delete(f"/delete/{username}")
     self.assertEqual(response.content_type,"application/json")
Пример #17
0
 def test_update_known(self):
     print('Testing with unknown username for path: /update/<username>/<column>/<value>')
     tester = application.test_client(self)
     response = tester.patch("/update/POR/first_name/TestName")
     self.assertIn(b'"message":"No record found!"',response.data)
Пример #18
0
 def test_delete_content_unknown(self):
     print('Testing content type for path: /delete/<username>')
     tester = application.test_client(self)
     response = tester.delete("/delete/POR")
     self.assertIn(b'"message":"No record found!"',response.data)
Пример #19
0
 def test_mail_status(self):
     print('Testing status code for path: /add_email/<username>/<value>')
     tester = application.test_client(self)
     response = tester.post("/add_email/blag0/[email protected]")
     self.assertTrue(response.status_code,200)
Пример #20
0
 def test_index_delete(self):
     print('Testing DELETE request for path: /')
     tester = application.test_client(self)
     response = tester.delete("/")
     self.assertEqual(response.status_code,405)
Пример #21
0
 def test_mail_delete(self):
     print('Testing DELETE request at path: /add_email/<username>/<value>')
     tester = application.test_client(self)
     response = tester.delete("/add_email/blag0/[email protected]")
     self.assertTrue(response.status_code,405)
Пример #22
0
 def test_search_delete(self):
     print('Testing DELETE request at path: /search/<username>')
     tester = application.test_client(self)
     random_username = ''.join(choice(ascii_uppercase) for i in range(choice(range(32))))
     response = tester.delete(f"/search/{random_username}")
     self.assertEqual(response.status_code,405)
Пример #23
0
 def test_mail_content_type(self):
     print('Testing content type for path: /add_email/<username>/<value>')
     tester = application.test_client(self)
     response = tester.post("/add_email/blag0/[email protected]")
     self.assertEqual(response.content_type,"application/json")
Пример #24
0
 def test_search_status(self):
     print('Testing content type for path: /search/<username>')
     tester = application.test_client(self)
     random_username = ''.join(choice(ascii_uppercase) for i in range(choice(range(32))))
     response = tester.get(f"/search/{random_username}")
     self.assertEqual(response.content_type,"application/json")
Пример #25
0
 def test_mail_content_known(self):
     print('Testing content type for path: /add_email/<username>/<value>')
     tester = application.test_client(self)
     response = tester.post("/add_email/blag0/[email protected]")
     self.assertIn(b'"first_name":"Blagoy"',response.data)
Пример #26
0
 def test_index_content(self):
     print('Testing content type for path: /')
     tester = application.test_client(self)
     response = tester.get("/")
     self.assertEqual(response.content_type,"application/json")
Пример #27
0
 def test_mail_content_unknown(self):
     print('Testing content type for path: /add_email/<username>/<value>')
     tester = application.test_client(self)
     response = tester.post("/add_email/POR/[email protected]")
     self.assertIn(b'"message":"Record not found!"',response.data)
Пример #28
0
 def setUp(self):
     self.app = application.test_client()
Пример #29
0
 def test_search_known(self):
     print('Testing content for path: /search/blag0')
     tester = application.test_client(self)
     response = tester.get("/search/blag0", content_type="application/json")
     self.assertIn(b'"first_name":"Blagoy"',response.data)