def test_get_stats_shortcode_not_found_failure(self): with pytest.raises( Exception ) as exc: # Wide catch, scope narrowed for preventing nested Exception override Stat.get_stats(shortcode='0b0b0b') assert isinstance(exc.type, ShortcodeNotFound.__class__) # Sanity check
def get_stats(shortcode): """ This endpoint method handles the shortcode stats requests, routed to the shortcode specific routing url concatenated with the stats endpoint and being a GET request. The Stat database model specific methods will handle the logic. :param shortcode: The provided shortcode as url parameter. :type shortcode: str :return: The response with the corresponding stats details for the provided shortcode. :rtype: flask.Response .. note:: The Stat database model specific methods handle the logic and exception handling for this endpoint, as the endpoint relies heavily on database specific logic. .. seealso:: See for database model related methods: src/models.py See for exception related exceptions: src/exceptions.py """ stats = Stat.get_stats(shortcode=shortcode) response = jsonify(stats) response.status_code = 200 return response
def test_stat_redirect_is_not_zero(self): stats = Stat.get_stats(shortcode='090909') assert stats['redirectCount'] == 2
def test_get_stats_success(self): stats = Stat.get_stats(shortcode='aqaqaq') assert 'created' in stats assert 'lastRedirect' in stats assert 'redirectCount' in stats