def test_api_search_missing_query(mock_bad_request): # invalid url with query parameter missing url = '/api/v1/search/google' resp = app.test_client().get(url).get_data().decode('utf-8') mock_bad_request.assert_called_with( [400, 'Not Found - missing query', 'json']) assert resp == "Mock Response"
def setUp(self): super().setUp() self.app = app.test_client() u = User('John Novikov', '*****@*****.**', 'login', 'secretpass', 123) u.save() u2 = User('Johnnnn Novikov', '*****@*****.**', 'login', 'secretpass', 123) u.save() db.session.add(Team('Shadow Servants')) db.session.add(Team('Shadow Servants')) db.session.commit() self.sh1 = ScoreHistory(500, datetime.datetime(2018, 1, 1, 00, 00, 00), contestant=1, tournament=1) self.sh2 = ScoreHistory(700, datetime.datetime(2018, 1, 1, 00, 00, 00), contestant=1, tournament=1) self.sh3 = ScoreHistory(700, datetime.datetime(2018, 1, 1, 00, 00, 00), contestant=2, tournament=1) self.sh4 = ScoreHistory(900, datetime.datetime(2018, 1, 1, 00, 00, 00), contestant=2, tournament=1)
def setUp(self) -> None: self._blueprint_url = "/device" app.testing = True app.register_blueprint(device, url_prefix=self._blueprint_url) self.client = app.test_client()
def setUp(self): app.config['TESTING'] = True app.config['CSRF_ENABLED'] = False app.config['DEBUG'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join( BASE_DIR, TEST_DB) self.app = app.test_client() db.create_all() self.invite_link = ''.join( random.choice(string.ascii_lowercase + string.digits) for _ in range(32)) our_time = "2019-01-05 22:14:39" our_time_to_live = "2019-04-05 22:14:39" our_datetime = datetime.strptime(our_time, "%Y-%m-%d %H:%M:%S") our_datetime_to_live = datetime.strptime(our_time_to_live, "%Y-%m-%d %H:%M:%S") self.user = User() self.user.add() print(self.user.id) self.tournament = Tournament("CTF", "description", self.user, our_datetime, our_datetime_to_live, "45.408062, -123.007827", self.invite_link, True, True, False, True) self.tournament.add()
def test_api_search_for_no_response(mock_bad_request): url = '/api/v1/search/google?query=fossasia' with patch('app.server.lookup', return_value=None): with patch('app.server.feed_gen', return_value=None): resp = app.test_client().get(url).get_data().decode('utf-8') mock_bad_request.assert_called_with( [404, 'No response', 'google:fossasia']) assert resp == "Mock Response"
def test_feedback_db(): test_client = app.test_client() expected_feedback_content = 'It was dope food' response = test_client.get('/', data={'Body': 'It was dope food'}) # TODO change this to getting just one feedback in query stored_feedback = Feedback.query.filter_by( content='It was dope food').first() stored_content = stored_feedback.content assert expected_feedback_content == stored_content
def setUp(self): super().setUp() self.app = app.test_client() self.user = User('name', 'test@test', 'login', 'pass', 'code') self.user.save() with self.app.session_transaction() as session: session['id'] = self.user.id self.team = Team("Bushwhackers", 'Moscow', 'qwerty', self.user)
def setUp(self): super().setUp() admin = User(username=Users.ADMIN['username'], email=Users.ADMIN['email'], admin=True) admin.set_password(Users.ADMIN['password']) db.session.add(admin) db.session.commit() self.client = app.test_client()
def setUp(self): app.config['TESTING'] = True app.config['CSRF_ENABLED'] = False app.config['DEBUG'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join( BASE_DIR, TEST_DB) self.app = app.test_client() db.create_all() our_time = "2019-01-05 22:14:39" our_datetime = datetime.strptime(our_time, "%Y-%m-%d %H:%M:%S") self.attemp = Attempt('flag', True, 12, our_datetime, 'user') self.attemp.add()
def test_api_search_for_format(mock_lookup, mock_feed_gen): for qformat in ['json', 'csv', 'xml']: url = '/api/v1/search/google?query=fossasia&format=' + qformat mock_result = [{ 'title': 'mock_title', 'link': 'mock_link', 'desc': 'mock_desc' }] mock_lookup.return_value = None mock_feed_gen.return_value = mock_result resp = app.test_client().get(url).get_data().decode('utf-8') expected_resp = expected_response_for_format(qformat) if qformat == 'json': resp = json.loads(resp) elif qformat == 'xml': resp = resp.replace('\t', '').replace('\n', '') resp = get_json_equivalent_from_xml_feed(resp) expected_resp = get_json_equivalent_from_xml_feed(expected_resp) elif qformat == 'csv': resp = get_json_equivalent_from_csv_feed(resp) expected_resp = get_json_equivalent_from_csv_feed(expected_resp) assert expected_resp == resp
def client(): from app.server import app with app.test_client() as client: yield client
def setUp(self): super().setUp() self.app = app.test_client()
def setUp(self): app.config['TESTING'] = True self.app = app.test_client()
def setUp(self): app.testing = True self.app = app.test_client()
def test_thank_you(): test_client = app.test_client() # TODO: change the test for a random URL in the Media tags expected_response = r"<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><Response><Message><Body>Thank you for your feedback! - Gen</Body><Media>https://media.giphy.com/media/.+</Media></Message></Response>" response = test_client.get('/', data={'Body': 'fjklafd'}) assert re.match(expected_response, response.data)
def test_api_search_for_cache_hit(): url = '/api/v1/search/google?query=fossasia' mock_result = [{'title': 'mock_title', 'link': 'mock_link'}] with patch('app.server.lookup', return_value=mock_result): resp = app.test_client().get(url).get_data().decode('utf-8') assert json.loads(resp) == mock_result
def test_api_index(): assert app.test_client().get('/').status_code == 200
def test_api_search_invalid_engine(mock_bad_request): url = '/api/v1/search/invalid?query=fossasia' resp = app.test_client().get(url).get_data().decode('utf-8') mock_bad_request.assert_called_with( [404, 'Incorrect search engine', 'invalid']) assert resp == "Mock Response"
def test_api_search_invalid_qformat(mock_abort): url = '/api/v1/search/google?query=fossasia&format=invalid' app.test_client().get(url) mock_abort.assert_called_with(400, 'Not Found - undefined format')