diff --git a/docs/uri-scheme-browse-origin.rst b/docs/uri-scheme-browse-origin.rst index 337116ad..731d6754 100644 --- a/docs/uri-scheme-browse-origin.rst +++ b/docs/uri-scheme-browse-origin.rst @@ -1,488 +1,351 @@ Origin ^^^^^^ Origin metadata """"""""""""""" -.. http:get:: /browse/origin/(origin_id)/ - - HTML view that displays a SWH origin identified by its id. - - The view displays the origin metadata and contains links - for browsing its directories and contents for each SWH visit. - - :param int origin_id: the id of a SWH origin - :statuscode 200: no error - :statuscode 404: requested origin can not be found in the SWH archive - - **Examples:** - - .. parsed-literal:: - - :swh_web_browse:`origin/2/` - :swh_web_browse:`origin/13706355/` - .. http:get:: /browse/origin/(origin_type)/url/(origin_url)/ HTML view that displays a SWH origin identified by its type and url. The view displays the origin metadata and contains links for browsing its directories and contents for each SWH visit. - :param string origin_type: the type of the SWH origin (*git*, *svn*, ...) - :param string origin_url: the url of the origin (e.g. https://github.com///) + :param string origin_type: the type of the SWH origin (*git*, *svn*, *deb* ...) + :param string origin_url: the url of the origin (e.g. https://github.com/user/repo) :statuscode 200: no error :statuscode 404: requested origin can not be found in the SWH archive **Examples:** .. parsed-literal:: :swh_web_browse:`origin/git/url/https://github.com/torvalds/linux/` :swh_web_browse:`origin/git/url/https://github.com/python/cpython/` + :swh_web_browse:`origin/deb/url/deb://Debian-Security/packages/mediawiki/` + :swh_web_browse:`origin/git/url/https://gitorious.org/qt/qtbase.git` + Origin directory """""""""""""""" -.. http:get:: /browse/origin/(origin_id)/directory/[(path)/] +.. http:get:: /browse/origin/(origin_type)/url/(origin_url)/directory/[(path)/] HTML view for browsing the content of a directory reachable from the root directory (including itself) associated to the latest visit of a SWH origin. The content of the directory is first sorted in lexicographical order and the sub-directories are displayed before the regular files. The view enables to navigate from the requested directory to directories reachable from it in a recursive way but also up to the origin root directory. A breadcrumb located in the top part of the view allows to keep track of the paths navigated so far. The view also enables to easily switch between the origin branches through a dropdown menu. The origin branch (default to master) from which to retrieve the directory content can also be specified by using the branch query parameter. - :param int origin_id: the id of a SWH origin + :param string origin_type: the type of the SWH origin (*git*, *svn*, *deb* ...) + :param string origin_url: the url of the origin (e.g. https://github.com/user/repo) :param string path: optional parameter used to specify the path of a directory reachable from the origin root one :query string branch: specify the origin branch from which to retrieve the directory :query string revision: specify the origin revision, identified by the hexadecimal representation of its *sha1_git* value, from which to retrieve the directory + :query int visit_id: specify a SWH visit id to retrieve the directory from instead + of using the latest visit by default :statuscode 200: no error :statuscode 404: requested origin can not be found in the SWH archive or the provided path does not exist from the origin root directory **Examples:** .. parsed-literal:: - :swh_web_browse:`origin/2/directory/` - :swh_web_browse:`origin/2/directory/net/ethernet/` - :swh_web_browse:`origin/13706355/directory/` - :swh_web_browse:`origin/13706355/directory/Python/` - :swh_web_browse:`origin/13706355/directory/?branch=refs/heads/2.7` - -.. http:get:: /browse/origin/(origin_id)/visit/(visit_id)/directory/[(path)/] - - HTML view for browsing the content of a directory reachable from the root directory - (including itself) associated to a specific visit (identified by its id) of a SWH origin. - - The content of the directory is first sorted in lexicographical order - and the sub-directories are displayed before the regular files. - - The view enables to navigate from the requested directory to - directories reachable from it in a recursive way but also - up to the origin root directory. - A breadcrumb located in the top part of the view allows - to keep track of the paths navigated so far. - - The view also enables to easily switch between the origin branches - through a dropdown menu. - - The origin branch (default to master) from which to retrieve the directory - content can also be specified by using the branch query parameter. - - :param int origin_id: the id of a SWH origin - :param int visit_id: the id of the origin visit - :param string path: optional parameter used to specify the path of a directory - reachable from the origin root one - :query string branch: specify the origin branch from which - to retrieve the directory - :query string revision: specify the origin revision, identified by the hexadecimal - representation of its *sha1_git* value, from which to retrieve the directory - :statuscode 200: no error - :statuscode 404: requested origin can not be found in the SWH archive, - requested visit id does not exist or the provided path does - not exist from the origin root directory - - **Examples:** - - .. parsed-literal:: + :swh_web_browse:`origin/git/url/https://github.com/torvalds/linux/directory/` + :swh_web_browse:`origin/git/url/https://github.com/torvalds/linux/directory/net/ethernet/` + :swh_web_browse:`origin/git/url/https://github.com/python/cpython/directory/` + :swh_web_browse:`origin/git/url/https://github.com/python/cpython/directory/Python/` + :swh_web_browse:`origin/git/url/https://github.com/python/cpython/directory/?branch=refs/heads/2.7` - :swh_web_browse:`origin/2/visit/2/directory/` - :swh_web_browse:`origin/2/visit/2/directory/net/ethernet/` - :swh_web_browse:`origin/13706355/visit/1/directory/` - :swh_web_browse:`origin/13706355/visit/1/directory/Python/` - :swh_web_browse:`origin/13706355/visit/1/directory/?branch=refs/heads/2.7` -.. http:get:: /browse/origin/(origin_id)/ts/(timestamp)/directory/[(path)/] +.. http:get:: /browse/origin/(origin_type)/url/(origin_url)/visit/(timestamp)/directory/[(path)/] HTML view for browsing the content of a directory reachable from the root directory (including itself) associated to a visitof a SWH origin closest to a provided timestamp. The content of the directory is first sorted in lexicographical order and the sub-directories are displayed before the regular files. The view enables to navigate from the requested directory to directories reachable from it in a recursive way but also up to the origin root directory. A breadcrumb located in the top part of the view allows to keep track of the paths navigated so far. The view also enables to easily switch between the origin branches through a dropdown menu. The origin branch (default to master) from which to retrieve the directory content can also be specified by using the branch query parameter. - :param int origin_id: the id of a SWH origin - :param string timestamp: an ISO date string or Unix timestamp to parse - in order to find the closest SWH visit. + :param string origin_type: the type of the SWH origin (*git*, *svn*, *deb* ...) + :param string origin_url: the url of the origin (e.g. https://github.com/user/repo) + :param string timestamp: a date string (any format parsable by `dateutil.parser.parse`_) + or Unix timestamp to parse in order to find the closest SWH visit. :param path: optional parameter used to specify the path of a directory reachable from the origin root one :type path: string :query string branch: specify the origin branch from which to retrieve the directory :query string revision: specify the origin revision, identified by the hexadecimal representation of its *sha1_git* value, from which to retrieve the directory + :query int visit_id: specify a SWH visit id to retrieve the directory from instead + of using the provided timestamp :statuscode 200: no error :statuscode 404: requested origin can not be found in the SWH archive, requested visit timestamp does not exist or the provided path does not exist from the origin root directory **Examples:** .. parsed-literal:: - :swh_web_browse:`origin/2/ts/1493926809/directory/` - :swh_web_browse:`origin/2/ts/2016-09-14T10:36:21+00:00/directory/net/ethernet/` - :swh_web_browse:`origin/13706355/ts/1474620651/directory/` - :swh_web_browse:`origin/13706355/ts/1474620651/directory/Python/` - :swh_web_browse:`origin/13706355/ts/1474620651/directory/?branch=refs/heads/2.7` - + :swh_web_browse:`origin/git/url/https://github.com/torvalds/linux/visit/1493926809/directory/` + :swh_web_browse:`origin/git/url/https://github.com/torvalds/linux/visit/2016-09-14T10:36:21/directory/net/ethernet/` + :swh_web_browse:`origin/git/url/https://github.com/python/cpython/visit/1474620651/directory/` + :swh_web_browse:`origin/git/url/https://github.com/python/cpython/visit/2017-05-05/directory/Python/` + :swh_web_browse:`origin/git/url/https://github.com/python/cpython/visit/2015-08/directory/?branch=refs/heads/2.7` Origin content """""""""""""" -.. http:get:: /browse/origin/(origin_id)/content/(path)/ +.. http:get:: /browse/origin/(origin_type)/url/(origin_url)/content/(path)/ HTML view that produces a display of a SWH content associated to the latest visit of a SWH origin. If the content to display is textual, it will be highlighted client-side if possible using highlightjs_. The procedure to perform that task is described in :http:get:`/browse/content/[(algo_hash):](hash)/`. It is also possible to highlight specific lines of a textual content (not in terms of syntax highlighting but to emphasize some relevant content part) by either: * clicking on line numbers (holding shift to highlight a lines range) * using an url fragment in the form '#Ln' or '#Lm-Ln' The view displays a breadcrumb on top of the rendered content in order to easily navigate up to the origin root directory. The view also enables to easily switch between the origin branches through a dropdown menu. The origin branch (default to master) from which to retrieve the content can also be specified by using the branch query parameter. - :param int origin_id: the id of a SWH origin + :param string origin_type: the type of the SWH origin (*git*, *svn*, *deb* ...) + :param string origin_url: the url of the origin (e.g. https://github.com/user/repo) :param string path: path of a content reachable from the origin root directory :query string branch: specify the origin branch from which to retrieve the content :query string revision: specify the origin revision, identified by the hexadecimal representation of its *sha1_git* value, from which to retrieve the content + :query int visit_id: specify a SWH visit id to retrieve the content from instead + of using the latest visit by default :statuscode 200: no error :statuscode 404: requested origin can not be found in the SWH archive, or the provided content path does not exist from the origin root directory **Examples:** .. parsed-literal:: - :swh_web_browse:`origin/723566/content/git.c/` - :swh_web_browse:`origin/723566/content/git.c/` - :swh_web_browse:`origin/16297443/content/js/src/json.cpp/` - :swh_web_browse:`origin/723566/content/git.c/?branch=refs/heads/next` - -.. http:get:: /browse/origin/(origin_id)/visit/(visit_id)/content/(path)/ - - HTML view that produces a display of a SWH content - associated to a specific visit (identified by its id) of a SWH origin. - - If the content to display is textual, it will be highlighted client-side - if possible using highlightjs_. The procedure to perform that task is described - in :http:get:`/browse/content/[(algo_hash):](hash)/`. - - It is also possible to highlight specific lines of a textual - content (not in terms of syntax highlighting but to emphasize - some relevant content part) by either: - - * clicking on line numbers (holding shift to highlight a lines range) - - * using an url fragment in the form '#Ln' or '#Lm-Ln' - - The view displays a breadcrumb on top of the rendered - content in order to easily navigate up to the origin root directory. - - The view also enables to easily switch between the origin branches - through a dropdown menu. - - The origin branch (default to master) from which to retrieve the content - can also be specified by using the branch query parameter. - - :param int origin_id: the id of a SWH origin - :param int visit_id: the id of the origin visit - :param string path: path of a content reachable from the origin root directory - :query string branch: specify the origin branch from which - to retrieve the content - :query string revision: specify the origin revision, identified by the hexadecimal - representation of its *sha1_git* value, from which to retrieve the content - :statuscode 200: no error - :statuscode 404: requested origin can not be found in the SWH archive, - requested visit id does not exist or the provided content path does - not exist from the origin root directory - - **Examples:** - - .. parsed-literal:: - - :swh_web_browse:`origin/723566/visit/1/content/git.c/` - :swh_web_browse:`origin/723566/visit/13/content/git.c/#L334-L390` - :swh_web_browse:`origin/16297443/visit/3/content/js/src/json.cpp/` - :swh_web_browse:`origin/723566/visit/1/content/git.c/?branch=refs/heads/next` + :swh_web_browse:`origin/git/url/https://github.com/git/git/content/git.c/` + :swh_web_browse:`origin/git/url/https://github.com/git/git/content/git.c/` + :swh_web_browse:`origin/git/url/https://github.com/mozilla/gecko-dev/content/js/src/json.cpp/` + :swh_web_browse:`origin/git/url/https://github.com/git/git/content/git.c/?branch=refs/heads/next` -.. http:get:: /browse/origin/(origin_id)/ts/(timestamp)/content/(path)/ +.. http:get:: /browse/origin/(origin_type)/url/(origin_url)/visit/(timestamp)/content/(path)/ HTML view that produces a display of a SWH content associated to a visit of a SWH origin closest to a provided timestamp. If the content to display is textual, it will be highlighted client-side if possible using highlightjs_. The procedure to perform that task is described in :http:get:`/browse/content/[(algo_hash):](hash)/`. It is also possible to highlight specific lines of a textual content (not in terms of syntax highlighting but to emphasize some relevant content part) by either: * clicking on line numbers (holding shift to highlight a lines range) * using an url fragment in the form '#Ln' or '#Lm-Ln' The view displays a breadcrumb on top of the rendered content in order to easily navigate up to the origin root directory. The view also enables to easily switch between the origin branches through a dropdown menu. The origin branch (default to master) from which to retrieve the content can also be specified by using the branch query parameter. - :param int origin_id: the id of a SWH origin - :param string timestamp: an ISO date string or Unix timestamp to parse in - order to find the closest SWH visit. + :param string origin_type: the type of the SWH origin (*git*, *svn*, *deb* ...) + :param string origin_url: the url of the origin (e.g. https://github.com/user/repo) + :param string timestamp: a date string (any format parsable by `dateutil.parser.parse`_) + or Unix timestamp to parse in order to find the closest SWH visit. :param string path: path of a content reachable from the origin root directory :query string branch: specify the origin branch from which to retrieve the content :query string revision: specify the origin revision, identified by the hexadecimal representation of its *sha1_git* value, from which to retrieve the content + :query int visit_id: specify a SWH visit id to retrieve the content from instead + of using the provided timestamp :statuscode 200: no error :statuscode 404: requested origin can not be found in the SWH archive, requested visit timestamp does not exist or the provided content path does not exist from the origin root directory **Examples:** .. parsed-literal:: - :swh_web_browse:`origin/723566/ts/1473933564/content/git.c/` - :swh_web_browse:`origin/723566/ts/2016-05-05T00:0:00+00:00/content/git.c/` - :swh_web_browse:`origin/16297443/ts/1490126182/content/js/src/json.cpp/` - :swh_web_browse:`origin/16297443/ts/2017-03-21/content/js/src/json.cpp/#L904-L931` - :swh_web_browse:`origin/723566/ts/2017-09-15/content/git.c/?branch=refs/heads/next` + :swh_web_browse:`origin/git/url/https://github.com/git/git/visit/1473933564/content/git.c/` + :swh_web_browse:`origin/git/url/https://github.com/git/git/visit/2016-05-05T00:0:00+00:00/content/git.c/` + :swh_web_browse:`origin/git/url/https://github.com/mozilla/gecko-dev/visit/1490126182/content/js/src/json.cpp/` + :swh_web_browse:`origin/git/url/https://github.com/mozilla/gecko-dev/visit/2017-03-21/content/js/src/json.cpp/#L904-L931` + :swh_web_browse:`origin/git/url/https://github.com/git/git/visit/2017-09-15/content/git.c/?branch=refs/heads/next` + Origin history """""""""""""" -.. http:get:: /browse/origin/(origin_id)/log/ +.. http:get:: /browse/origin/(origin_type)/url/(origin_url)/log/ HTML view that produces a display of revisions history heading to the last revision found during the latest visit of a SWH origin. In other words, it shows the commit log associated to the latest visit of a SWH origin. The following data are displayed for each log entry: * author of the revision * link to the revision metadata * message associated the revision * date of the revision * link to browse the associated source tree in the origin context N log entries are displayed per page (default is 20). In order to navigate in a large history, two buttons are present at the bottom of the view: * *Newer*: fetch and display if available the N more recent log entries than the ones currently displayed * *Older*: fetch and display if available the N older log entries than the ones currently displayed The view also enables to easily switch between the origin branches through a dropdown menu. The origin branch (default to master) from which to retrieve the content can also be specified by using the branch query parameter. - :param int origin_id: the id of a SWH origin + :param string origin_type: the type of the SWH origin (*git*, *svn*, *deb* ...) + :param string origin_url: the url of the origin (e.g. https://github.com/user/repo) :query string revs_breadcrumb: used internally to store the navigation breadcrumbs (i.e. the list of descendant revisions visited so far). It must be a string in the form - "[//.../]" where rev_i corresponds to a + "(rev_1)[/(rev_2)/.../(rev_n)]" where rev_i corresponds to a revision sha1_git. :query int per_page: the number of log entries to display per page (default is 20, max is 50) :query string branch: specify the origin branch from which to retrieve the commit log :query string revision: specify the origin revision, identified by the hexadecimal representation of its *sha1_git* value, from which to retrieve the commit log + :query int visit_id: specify a SWH visit id to retrieve the history log from instead + of using the latest visit by default :statuscode 200: no error :statuscode 404: requested origin can not be found in the SWH archive **Examples:** .. parsed-literal:: - :swh_web_browse:`origin/12215444/log/` - :swh_web_browse:`origin/2081083/log/` - :swh_web_browse:`origin/12081083/log/?branch=refs/heads/release` - -.. http:get:: /browse/origin/(origin_id)/visit/(visit_id)/log/ - - HTML view that produces a display of revisions history heading - to the last revision found during a specific visit of a SWH origin. - In other words, it shows the commit log associated to a specific - visit of a SWH origin. - - The following data are displayed for each log entry: - - * author of the revision - * link to the revision metadata - * message associated the revision - * date of the revision - * link to browse the associated source tree in the origin context - - N log entries are displayed per page (default is 20). In order to navigate - in a large history, two buttons are present at the bottom of the view: - - * *Newer*: fetch and display if available the N more recent log entries - than the ones currently displayed - * *Older*: fetch and display if available the N older log entries - than the ones currently displayed - - The view also enables to easily switch between the origin branches - through a dropdown menu. - - The origin branch (default to master) from which to retrieve the content - can also be specified by using the branch query parameter. - - :param int origin_id: the id of a SWH origin - :param int visit_id: the id of the origin visit - :query string revs_breadcrumb: used internally to store - the navigation breadcrumbs (i.e. the list of descendant revisions - visited so far). It must be a string in the form - "[//.../]" where rev_i corresponds to a - revision sha1_git. - :query int per_page: the number of log entries to display per page - (default is 20, max is 50) - :query string branch: specify the origin branch from which - to retrieve the commit log - :query string revision: specify the origin revision, identified by the hexadecimal - representation of its *sha1_git* value, from which to retrieve the commit log - :statuscode 200: no error - :statuscode 404: requested origin can not be found in the SWH archive - - **Examples:** - - .. parsed-literal:: + :swh_web_browse:`origin/git/url/https://github.com/videolan/vlc/log/` + :swh_web_browse:`origin/git/url/https://github.com/Kitware/CMake/log/` + :swh_web_browse:`origin/git/url/https://github.com/Kitware/CMake/log/?branch=refs/heads/release` - :swh_web_browse:`origin/12215444/visit/2/log/` - :swh_web_browse:`origin/12081083/visit/10/log/` - :swh_web_browse:`origin/12081083/visit/10/log/?branch=refs/heads/release` -.. http:get:: /browse/origin/(origin_id)/ts/(timestamp)/log/ +.. http:get:: /browse/origin/(origin_type)/url/(origin_url)/visit/(timestamp)/log/ HTML view that produces a display of revisions history heading to the last revision found during a visit of a SWH origin closest to the provided timestamp. In other words, it shows the commit log associated to a visit of - a SWH origin. closest to a provided timestamp. + a SWH origin closest to a provided timestamp. The following data are displayed for each log entry: * author of the revision * link to the revision metadata * message associated the revision * date of the revision * link to browse the associated source tree in the origin context N log entries are displayed per page (default is 20). In order to navigate in a large history, two buttons are present at the bottom of the view: * *Newer*: fetch and display if available the N more recent log entries than the ones currently displayed * *Older*: fetch and display if available the N older log entries than the ones currently displayed The view also enables to easily switch between the origin branches through a dropdown menu. The origin branch (default to master) from which to retrieve the content can also be specified by using the branch query parameter. - :param int origin_id: the id of a SWH origin - :param string timestamp: an ISO date string or Unix timestamp to parse - in order to find the closest SWH visit. + :param string origin_type: the type of the SWH origin (*git*, *svn*, *deb* ...) + :param string origin_url: the url of the origin (e.g. https://github.com/user/repo) + :param string timestamp: a date string (any format parsable by `dateutil.parser.parse`_) + or Unix timestamp to parse in order to find the closest SWH visit. :query string revs_breadcrumb: used internally to store the navigation breadcrumbs (i.e. the list of descendant revisions visited so far). It must be a string in the form - "[//.../]" where rev_i corresponds to a + "(rev_1)[/(rev_2)/.../(rev_n)]" where rev_i corresponds to a revision sha1_git. :query int per_page: the number of log entries to display per page (default is 20, max is 50) :query string branch: specify the origin branch from which to retrieve the commit log :query string revision: specify the origin revision, identified by the hexadecimal representation of its *sha1_git* value, from which to retrieve the commit log + :query int visit_id: specify a SWH visit id to retrieve the history log from instead + of using the provided timestamp :statuscode 200: no error :statuscode 404: requested origin can not be found in the SWH archive **Examples:** .. parsed-literal:: - :swh_web_browse:`origin/12215444/ts/1459651262/log/` - :swh_web_browse:`origin/12081083/ts/2016-04-01/log/` - :swh_web_browse:`origin/12081083/ts/1438116814/log/?branch=refs/heads/release` - :swh_web_browse:`origin/12081083/ts/2017-05-05T03:14:23/log/?branch=refs/heads/release` + :swh_web_browse:`origin/git/url/https://github.com/videolan/vlc/visit/1459651262/log/` + :swh_web_browse:`origin/git/url/https://github.com/Kitware/CMake/visit/2016-04-01/log/` + :swh_web_browse:`origin/git/url/https://github.com/Kitware/CMake/visit/1438116814/log/?branch=refs/heads/release` + :swh_web_browse:`origin/git/url/https://github.com/Kitware/CMake/visit/2017-05-05T03:14:23/log/?branch=refs/heads/release` .. _highlightjs: https://highlightjs.org/ +.. _dateutil.parser.parse: http://dateutil.readthedocs.io/en/stable/parser.html diff --git a/swh/web/browse/urls.py b/swh/web/browse/urls.py index da2b8716..b91c77ff 100644 --- a/swh/web/browse/urls.py +++ b/swh/web/browse/urls.py @@ -1,42 +1,43 @@ # Copyright (C) 2017 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information from django.conf.urls import url from django.shortcuts import redirect import swh.web.browse.views.directory # noqa import swh.web.browse.views.content # noqa import swh.web.browse.views.origin # noqa import swh.web.browse.views.person # noqa import swh.web.browse.views.revision # noqa from swh.web.browse.browseurls import BrowseUrls from swh.web.common.utils import reverse def default_browse_view(request): """Default django view used as an entry point for the swh browse ui web application. The url that point to it is /browse/. Currently, it points to the origin view for the linux kernel source tree github mirror. Args: request: input django http request """ - linux_origin_id = '2' - linux_origin_url = reverse('browse-origin', - kwargs={'origin_id': linux_origin_id}) - return redirect(linux_origin_url) + linux_origin_url = 'https://github.com/torvalds/linux' + default_url = reverse('browse-origin', + kwargs={'origin_type': 'git', + 'origin_url': linux_origin_url}) + return redirect(default_url) urlpatterns = [ url(r'^$', default_browse_view, name='browse-homepage') ] urlpatterns += BrowseUrls.get_url_patterns() diff --git a/swh/web/browse/utils.py b/swh/web/browse/utils.py index e34102d6..a09fec06 100644 --- a/swh/web/browse/utils.py +++ b/swh/web/browse/utils.py @@ -1,495 +1,531 @@ # Copyright (C) 2017 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information import base64 +import dateutil import magic import math import stat import textwrap from django.core.cache import cache from django.utils.safestring import mark_safe from swh.web.common import highlightjs, service from swh.web.common.exc import NotFoundExc from swh.web.common.utils import ( reverse, format_utc_iso_date, parse_timestamp ) def get_directory_entries(sha1_git): """Function that retrieves the content of a SWH directory from the SWH archive. The directories entries are first sorted in lexicographical order. Sub-directories and regular files are then extracted. Args: sha1_git: sha1_git identifier of the directory Returns: A tuple whose first member corresponds to the sub-directories list and second member the regular files list Raises: NotFoundExc if the directory is not found """ cache_entry_id = 'directory_entries_%s' % sha1_git cache_entry = cache.get(cache_entry_id) if cache_entry: return cache_entry entries = list(service.lookup_directory(sha1_git)) entries = sorted(entries, key=lambda e: e['name']) for entry in entries: entry['perms'] = stat.filemode(entry['perms']) dirs = [e for e in entries if e['type'] == 'dir'] files = [e for e in entries if e['type'] == 'file'] cache.set(cache_entry_id, (dirs, files)) return dirs, files def get_mimetype_and_encoding_for_content(content): """Function that returns the mime type and the encoding associated to a content buffer using the magic module under the hood. Args: content (bytes): a content buffer Returns: A tuple (mimetype, encoding), for instance ('text/plain', 'us-ascii'), associated to the provided content. """ magic_result = magic.detect_from_content(content) return magic_result.mime_type, magic_result.encoding def request_content(query_string): """Function that retrieves a SWH content from the SWH archive. Raw bytes content is first retrieved, then the content mime type. If the mime type is not stored in the archive, it will be computed using Python magic module. Args: query_string: a string of the form "[ALGO_HASH:]HASH" where optional ALGO_HASH can be either *sha1*, *sha1_git*, *sha256*, or *blake2s256* (default to *sha1*) and HASH the hexadecimal representation of the hash value Returns: A tuple whose first member corresponds to the content raw bytes and second member the content mime type Raises: NotFoundExc if the content is not found """ content_data = service.lookup_content(query_string) content_raw = service.lookup_content_raw(query_string) content_data['raw_data'] = content_raw['data'] filetype = service.lookup_content_filetype(query_string) language = service.lookup_content_language(query_string) license = service.lookup_content_license(query_string) if filetype: mimetype = filetype['mimetype'] encoding = filetype['encoding'] else: mimetype, encoding = \ get_mimetype_and_encoding_for_content(content_data['raw_data']) content_data['mimetype'] = mimetype content_data['encoding'] = encoding # encode textual content to utf-8 if needed if mimetype.startswith('text/') and 'ascii' not in encoding \ and 'utf-8' not in encoding: content_data['raw_data'] = \ content_data['raw_data'].decode(encoding).encode('utf-8') if language: content_data['language'] = language['lang'] else: content_data['language'] = 'not detected' if license: content_data['licenses'] = ', '.join(license['licenses']) else: content_data['licenses'] = 'not detected' return content_data _browsers_supported_image_mimes = set(['image/gif', 'image/png', 'image/jpeg', 'image/bmp', 'image/webp']) def prepare_content_for_display(content_data, mime_type, path): """Function that prepares a content for HTML display. The function tries to associate a programming language to a content in order to perform syntax highlighting client-side using highlightjs. The language is determined using either the content filename or its mime type. If the mime type corresponds to an image format supported by web browsers, the content will be encoded in base64 for displaying the image. Args: content_data (bytes): raw bytes of the content mime_type (string): mime type of the content path (string): path of the content including filename Returns: A dict containing the content bytes (possibly different from the one provided as parameter if it is an image) under the key 'content_data and the corresponding highlightjs language class under the key 'language'. """ language = highlightjs.get_hljs_language_from_filename(path) if not language: language = highlightjs.get_hljs_language_from_mime_type(mime_type) if not language: language = 'nohighlight-swh' elif mime_type.startswith('application/'): mime_type = mime_type.replace('application/', 'text/') if mime_type.startswith('image/'): if mime_type in _browsers_supported_image_mimes: content_data = base64.b64encode(content_data) else: content_data = None return {'content_data': content_data, 'language': language} -def get_origin_visits(origin_id): +def get_origin_visits(origin_info): """Function that returns the list of visits for a swh origin. That list is put in cache in order to speedup the navigation in the swh web browse ui. Args: origin_id (int): the id of the swh origin to fetch visits from Returns: A list of dict describing the origin visits:: [{'date': , 'origin': , 'status': <'full' | 'partial'>, 'visit': }, ... ] Raises: NotFoundExc if the origin is not found """ - cache_entry_id = 'origin_%s_visits' % origin_id + cache_entry_id = 'origin_%s_visits' % origin_info['id'] cache_entry = cache.get(cache_entry_id) if cache_entry: return cache_entry origin_visits = [] per_page = service.MAX_LIMIT last_visit = None while 1: - visits = list(service.lookup_origin_visits(origin_id, + visits = list(service.lookup_origin_visits(origin_info['id'], last_visit=last_visit, per_page=per_page)) origin_visits += visits if len(visits) < per_page: break else: if not last_visit: last_visit = per_page else: last_visit += per_page + def _visit_sort_key(visit): + ts = dateutil.parser.parse(visit['date']).timestamp() + return ts + (float(visit['visit']) / 10e3) + + for v in origin_visits: + del v['metadata'] + origin_visits = [dict(t) for t in set([tuple(d.items()) + for d in origin_visits])] + origin_visits = sorted(origin_visits, key=lambda v: _visit_sort_key(v)) + cache.set(cache_entry_id, origin_visits) return origin_visits -def get_origin_visit(origin_id, visit_id=None, visit_ts=None): +def get_origin_visit(origin_info, visit_ts=None, visit_id=None): """Function that returns information about a SWH visit for a given origin. - The visit is retrieved from the visits list using either: - * a visit id - * a provided timestamp, in that case, the closest visit from - that timestamp is selected + The visit is retrieved from a provided timestamp. + The closest visit from that timestamp is selected. Args: - origin_id (int): the id of the swh origin to fetch branches from - visit_id (int): the id of the origin visit + origin_info (dict): a dict filled with origin information + (id, url, type) visit_ts (int or str): an ISO date string or Unix timestamp to parse Returns: A dict containing the visit info as described below:: {'origin': 2, 'date': '2017-10-08T11:54:25.582463+00:00', 'metadata': {}, 'visit': 25, 'status': 'full'} """ - visits = get_origin_visits(origin_id) - if not visit_id and visit_ts: - parsed_visit_ts = math.floor(parse_timestamp(visit_ts).timestamp()) - for i, visit in enumerate(visits): - ts = math.floor(parse_timestamp(visit['date']).timestamp()) - if i == 0 and parsed_visit_ts <= ts: + visits = get_origin_visits(origin_info) + + if not visits: + raise NotFoundExc('No SWH visit associated to origin with' + ' type %s and url %s!' % (origin_info['type'], + origin_info['url'])) + + if visit_id: + visit = [v for v in visits if v['visit'] == int(visit_id)] + if len(visit) == 0: + raise NotFoundExc( + 'Visit with id %s for origin with type %s' + ' and url %s not found!' % (visit_id, origin_info['type'], + origin_info['url'])) + return visit[0] + + if not visit_ts: + return visits[-1] + + parsed_visit_ts = math.floor(parse_timestamp(visit_ts).timestamp()) + + visit_idx = None + for i, visit in enumerate(visits): + ts = math.floor(parse_timestamp(visit['date']).timestamp()) + if i == 0 and parsed_visit_ts <= ts: + return visit + elif i == len(visits) - 1: + if parsed_visit_ts >= ts: return visit - elif i == len(visits) - 1: - if parsed_visit_ts >= ts: - return visit - else: - next_ts = math.floor( - parse_timestamp(visits[i+1]['date']).timestamp()) - if parsed_visit_ts >= ts and parsed_visit_ts < next_ts: - if (parsed_visit_ts - ts) < (next_ts - parsed_visit_ts): - return visit - else: - return visits[i+1] - raise NotFoundExc( - 'Visit with timestamp %s for origin with id %s not found!' % - (visit_ts, origin_id)) - - visit = [v for v in visits if v['visit'] == int(visit_id)] - if len(visit) == 0: + else: + next_ts = math.floor( + parse_timestamp(visits[i+1]['date']).timestamp()) + if parsed_visit_ts >= ts and parsed_visit_ts < next_ts: + if (parsed_visit_ts - ts) < (next_ts - parsed_visit_ts): + visit_idx = i + break + else: + visit_idx = i+1 + break + + if visit_idx: + visit = visits[visit_idx] + while visit_idx < len(visits) - 1 and \ + visit['date'] == visits[visit_idx+1]['date']: + visit_idx = visit_idx + 1 + visit = visits[visit_idx] + return visit + else: raise NotFoundExc( - 'Visit with id %s for origin with id %s not found!' % - (visit_id, origin_id)) + 'Visit with timestamp %s for origin with type %s and url %s not found!' % # noqa + (visit_ts, origin_info['type'], origin_info['url'])) - return visit[0] - -def get_origin_visit_branches(origin_id, visit_id=None, visit_ts=None): +def get_origin_visit_branches(origin_info, visit_ts=None, visit_id=None): """Function that returns the list of branches associated to a swh origin for a given visit. - The visit can be expressed by its id or a timestamp. In the latter case, + The visit is expressed by a timestamp. In the latter case, the closest visit from the provided timestamp will be used. If no visit parameter is provided, it returns the list of branches found for the latest visit. That list is put in cache in order to speedup the navigation in the swh web browse ui. Args: - origin_id (int): the id of the swh origin to fetch branches from - visit_id (int): the id of the origin visit + origin_info (dict): a dict filled with origin information + (id, url, type) visit_ts (int or str): an ISO date string or Unix timestamp to parse Returns: A tuple with two members. The first one is a list of dict describing the origin branches for the given visit:: [{'name': , 'revision': , 'directory': }, ... ] The second one is the ISO date string corresponding to the associated SWH visit. Raises: NotFoundExc if the origin or its visit are not found """ - visit_info = get_origin_visit(origin_id, visit_id, visit_ts) + visit_info = get_origin_visit(origin_info, visit_ts, visit_id) + visit_id = visit_info['visit'] - cache_entry_id = 'origin_%s_visit_%s_branches' % (origin_id, visit_id) + cache_entry_id = 'origin_%s_visit_%s_branches' % (origin_info['id'], + visit_id) cache_entry = cache.get(cache_entry_id) if cache_entry: return cache_entry - origin_visit_data = service.lookup_origin_visit(origin_id, visit_id) + origin_visit_data = service.lookup_origin_visit(origin_info['id'], + visit_id) branches = [] revision_ids = [] occurrences = origin_visit_data['occurrences'] for key in sorted(occurrences.keys()): if occurrences[key]['target_type'] == 'revision': branches.append({'name': key, 'revision': occurrences[key]['target']}) revision_ids.append(occurrences[key]['target']) revisions = service.lookup_revision_multiple(revision_ids) branches_to_remove = [] for idx, revision in enumerate(revisions): if revision: branches[idx]['directory'] = revision['directory'] else: branches_to_remove.append(branches[idx]) for b in branches_to_remove: branches.remove(b) cache.set(cache_entry_id, branches) return branches def gen_link(url, link_text): """ Utility function for generating an HTML link to insert in Django templates. Args: url (str): an url link_text (str): the text for the produced link Returns: An HTML link in the form 'link_text' """ link = '%s' % (url, link_text) return mark_safe(link) def gen_person_link(person_id, person_name): """ Utility function for generating a link to a SWH person HTML view to insert in Django templates. Args: person_id (int): a SWH person id person_name (str): the associated person name Returns: An HTML link in the form 'person_name' """ person_url = reverse('browse-person', kwargs={'person_id': person_id}) return gen_link(person_url, person_name) -def gen_revision_link(revision_id, shorten_id=False, origin_id=None): +def gen_revision_link(revision_id, shorten_id=False, origin_info=None): """ Utility function for generating a link to a SWH revision HTML view to insert in Django templates. Args: revision_id (int): a SWH revision id shorten_id (boolean): wheter to shorten the revision id to 7 characters for the link text Returns: An HTML link in the form 'revision_id' """ query_params = None - if origin_id: - query_params = {'origin_id': origin_id} + if origin_info: + query_params = {'origin_type': origin_info['type'], + 'origin_url': origin_info['url']} revision_url = reverse('browse-revision', kwargs={'sha1_git': revision_id}, query_params=query_params) if shorten_id: return gen_link(revision_url, revision_id[:7]) else: return gen_link(revision_url, revision_id) -def gen_origin_link(origin_id, origin_url): +def gen_origin_link(origin_info): """ Utility function for generating a link to a SWH origin HTML view to insert in Django templates. Args: - origin_id (int): a SWH origin id - origin_url (str): the url of the origin + origin_info (dict): a dicted filled with origin information + (id, type, url) Returns: An HTML link in the form 'Origin: origin_url' """ # noqa origin_browse_url = reverse('browse-origin', - kwargs={'origin_id': origin_id}) + kwargs={'origin_type': origin_info['type'], + 'origin_url': origin_info['url']}) return gen_link(origin_browse_url, - 'Origin: ' + origin_url) + 'Origin: ' + origin_info['url']) -def _format_log_entries(revision_log, per_page, origin_id=None): +def _format_log_entries(revision_log, per_page, origin_info=None): revision_log_data = [] for i, log in enumerate(revision_log): if i == per_page: break revision_log_data.append( {'author': gen_person_link(log['author']['id'], log['author']['name']), - 'revision': gen_revision_link(log['id'], True, origin_id), + 'revision': gen_revision_link(log['id'], True, origin_info), 'message': log['message'], 'message_shorten': textwrap.shorten(log['message'], width=80, placeholder='...'), 'date': format_utc_iso_date(log['date']), 'directory': log['directory']}) return revision_log_data def prepare_revision_log_for_display(revision_log, per_page, revs_breadcrumb, - origin_context=False, origin_id=None): + origin_context=False, origin_info=None): """ Utility functions that process raw revision log data for HTML display. Its purpose is to: * add links to relevant SWH browse views * format date in human readable format * truncate the message log It also computes the data needed to generate the links for navigating back and forth in the history log. Args: revision_log (list): raw revision log as returned by the SWH web api per_page (int): number of log entries per page revs_breadcrumb (str): breadcrumbs of revisions navigated so far, in the form 'rev1[/rev2/../revN]'. Each revision corresponds to the first one displayed in the HTML view for history log. origin_context (boolean): wheter or not the revision log is browsed from an origin view. """ current_rev = revision_log[0]['id'] next_rev = None prev_rev = None next_revs_breadcrumb = None prev_revs_breadcrumb = None if len(revision_log) == per_page + 1: prev_rev = revision_log[-1]['id'] prev_rev_bc = current_rev if origin_context: prev_rev_bc = prev_rev if revs_breadcrumb: revs = revs_breadcrumb.split('/') next_rev = revs[-1] if len(revs) > 1: next_revs_breadcrumb = '/'.join(revs[:-1]) if len(revision_log) == per_page + 1: prev_revs_breadcrumb = revs_breadcrumb + '/' + prev_rev_bc else: prev_revs_breadcrumb = prev_rev_bc return {'revision_log_data': _format_log_entries(revision_log, per_page, - origin_id), + origin_info), 'prev_rev': prev_rev, 'prev_revs_breadcrumb': prev_revs_breadcrumb, 'next_rev': next_rev, 'next_revs_breadcrumb': next_revs_breadcrumb} diff --git a/swh/web/browse/views/origin.py b/swh/web/browse/views/origin.py index 042209fb..1a4aa86f 100644 --- a/swh/web/browse/views/origin.py +++ b/swh/web/browse/views/origin.py @@ -1,667 +1,670 @@ # Copyright (C) 2017 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information import dateutil import json from distutils.util import strtobool from django.http import HttpResponse from django.shortcuts import render from django.utils.safestring import mark_safe from django.template.defaultfilters import filesizeformat from swh.web.common import service from swh.web.common.utils import ( gen_path_info, reverse, format_utc_iso_date ) from swh.web.common.exc import NotFoundExc, handle_view_exception from swh.web.browse.utils import ( get_origin_visits, get_origin_visit, get_origin_visit_branches, get_directory_entries, request_content, prepare_content_for_display, gen_link, prepare_revision_log_for_display, gen_origin_link ) from swh.web.browse.browseurls import browse_route -@browse_route(r'origin/(?P[0-9]+)/', - r'origin/(?P[a-z]+)/url/(?P.+)/', - view_name='browse-origin') -def origin_browse(request, origin_id=None, origin_type=None, - origin_url=None): - """Django view that produces an HTML display of a swh origin identified - by its id or its url. - - The url scheme that points to it is :http:get:`/browse/origin/(origin_id)/`. - - Args: - request: input django http request - origin_id: a swh origin id - origin_type: type of origin (git, svn, ...) - origin_url: url of the origin (e.g. https://github.com//) - - Returns: - The HMTL rendering for the metadata of the provided origin. - """ # noqa - try: - if origin_id: - origin_request_params = { - 'id': origin_id, - } - else: - origin_request_params = { - 'type': origin_type, - 'url': origin_url - } - origin_info = service.lookup_origin(origin_request_params) - origin_id = origin_info['id'] - origin_visits = get_origin_visits(origin_id) - except Exception as exc: - return handle_view_exception(request, exc) - - origin_info['last swh visit browse url'] = \ - reverse('browse-origin-directory', - kwargs={'origin_id': origin_id}) - - origin_visits_data = [] - for visit in origin_visits: - visit_date = dateutil.parser.parse(visit['date']) - visit['date'] = format_utc_iso_date(visit['date']) - visit['browse_url'] = reverse('browse-origin-directory', - kwargs={'origin_id': origin_id, - 'visit_id': visit['visit']}) - origin_visits_data.append( - {'date': visit_date.timestamp()}) +def _get_origin_branches_and_url_args(origin_info, timestamp, visit_id): + branches = get_origin_visit_branches(origin_info, timestamp, visit_id) + url_args = {'origin_type': origin_info['type'], + 'origin_url': origin_info['url']} + if timestamp: + url_args['timestamp'] = format_utc_iso_date(timestamp, + '%Y-%m-%dT%H:%M:%S') - return render(request, 'origin.html', - {'heading': 'Origin information', - 'top_panel_visible': True, - 'top_panel_collapsible': True, - 'top_panel_text_left': 'SWH object: Origin', - 'top_panel_text_right': 'Url: ' + origin_info['url'], - 'swh_object_metadata': origin_info, - 'main_panel_visible': True, - 'origin_visits_data': origin_visits_data, - 'visits': list(reversed(origin_visits)), - 'browse_url_base': '/browse/origin/%s/' % - origin_id}) - - -def _get_origin_branches_and_url_args(origin_id, visit_id, ts): - if not visit_id and ts: - branches = get_origin_visit_branches(origin_id, visit_ts=ts) - url_args = {'origin_id': origin_id, - 'timestamp': ts} - else: - branches = get_origin_visit_branches(origin_id, visit_id) - url_args = {'origin_id': origin_id, - 'visit_id': visit_id} return branches, url_args -def _raise_exception_if_branch_not_found(origin_id, visit_id, ts, - branch, branches): +def _raise_exception_if_branch_not_found(origin_info, timestamp, + branch, branches, visit_id=None): if visit_id: if len(branches) == 0: - raise NotFoundExc('Origin with id %s is empty for visit' - ' with id %s! No existing branches were found!' % - (origin_id, visit_id)) + raise NotFoundExc('Origin with type %s and url %s is empty' + ' for visit with id %s! No existing branches' + ' were found!' % (origin_info['type'], + origin_info['url'], visit_id)) else: raise NotFoundExc('Branch %s associated to visit with' - ' id %s for origin with id %s' - ' not found!' % - (branch, visit_id, origin_id)) + ' id %s for origin with type %s and url %s' + ' not found!' % (branch, visit_id, + origin_info['type'], + origin_info['url'])) else: if len(branches) == 0: - raise NotFoundExc('Origin with id %s is empty for visit' - ' with timestamp %s! No existing branches' - ' were found!' % - (origin_id, ts)) + raise NotFoundExc('Origin with type %s and url %s is empty' + ' for visit with timestamp %s! No existing' + ' branches were found!' % (origin_info['type'], + origin_info['url'], + timestamp)) else: raise NotFoundExc('Branch %s associated to visit with' - ' timestamp %s for origin with id %s' - ' not found!' % - (branch, ts, origin_id)) + ' timestamp %s for origin with type %s' + ' and url %s not found!' % (branch, timestamp, + origin_info['type'], + origin_info['url'])) def _get_branch(branches, branch_name): """ Utility function to get a specific branch from an origin branches list. Its purpose is to get the default HEAD branch as some SWH origin (e.g those with svn type) does not have it. In that latter case, check if there is a master branch instead and returns it. """ - filtered_branches = [b for b in branches if b['name'].endswith(branch_name)] # noqa + filtered_branches = \ + [b for b in branches if b['name'].endswith(branch_name)] if len(filtered_branches) > 0: return filtered_branches[0] elif branch_name == 'HEAD': - filtered_branches = [b for b in branches if b['name'].endswith('master')] # noqa + filtered_branches = \ + [b for b in branches if b['name'].endswith('master')] if len(filtered_branches) > 0: return filtered_branches[0] elif len(branches) > 0: return branches[0] return None -@browse_route(r'origin/(?P[0-9]+)/directory/', - r'origin/(?P[0-9]+)/directory/(?P.+)/', - r'origin/(?P[0-9]+)/visit/(?P[0-9]+)/directory/', # noqa - r'origin/(?P[0-9]+)/visit/(?P[0-9]+)/directory/(?P.+)/', # noqa - r'origin/(?P[0-9]+)/ts/(?P.+)/directory/', # noqa - r'origin/(?P[0-9]+)/ts/(?P.+)/directory/(?P.+)/', # noqa +@browse_route(r'origin/(?P[a-z]+)/url/(?P.+)/visit/(?P.+)/directory/', # noqa + r'origin/(?P[a-z]+)/url/(?P.+)/visit/(?P.+)/directory/(?P.+)/', # noqa + r'origin/(?P[a-z]+)/url/(?P.+)/directory/', # noqa + r'origin/(?P[a-z]+)/url/(?P.+)/directory/(?P.+)/', # noqa view_name='browse-origin-directory') -def origin_directory_browse(request, origin_id, visit_id=None, +def origin_directory_browse(request, origin_type, origin_url, timestamp=None, path=None): """Django view for browsing the content of a swh directory associated to an origin for a given visit. The url scheme that points to it is the following: - * :http:get:`/browse/origin/(origin_id)/directory/[(path)/]` - * :http:get:`/browse/origin/(origin_id)/visit/(visit_id)/directory/[(path)/]` - * :http:get:`/browse/origin/(origin_id)/ts/(timestamp)/directory/[(path)/]` + * :http:get:`/browse/origin/(origin_type)/url/(origin_url)/directory/[(path)/]` + * :http:get:`/browse/origin/(origin_type)/url/(origin_type)/visit/(timestamp)/directory/[(path)/]` Args: request: input django http request - origin_id: a swh origin id - visit_id: optionnal visit id parameter + origin_type: the type of swh origin (git, svn, hg, ...) + origin_url: the url of the swh origin + timestamp: optional swh visit timestamp parameter (the last one will be used by default) - timestamp: optionnal visit timestamp parameter - (the last one will be used by default) - path: optionnal path parameter used to navigate in directories + path: optional path parameter used to navigate in directories reachable from the origin root one - branch: optionnal query parameter that specifies the origin branch + branch: optional query parameter that specifies the origin branch from which to retrieve the directory revision: optional query parameter to specify the origin revision from which to retrieve the directory Returns: The HTML rendering for the content of the directory associated to the provided origin and visit. """ # noqa try: - if not visit_id and not timestamp: - origin_visits = get_origin_visits(origin_id) - if not origin_visits: - raise NotFoundExc('No SWH visit associated to ' - 'origin with id %s' % origin_id) - return origin_directory_browse(request, origin_id, - origin_visits[-1]['visit'], - path=path) + origin_info = service.lookup_origin({ + 'type': origin_type, + 'url': origin_url + }) + + visit_id = request.GET.get('visit_id', None) + + visit_info = get_origin_visit(origin_info, timestamp, visit_id) + + if timestamp: + timestamp = visit_info['date'] - origin_info = service.lookup_origin({'id': origin_id}) branches, url_args = \ - _get_origin_branches_and_url_args(origin_id, visit_id, timestamp) - visit_info = get_origin_visit(origin_id, visit_id, timestamp) + _get_origin_branches_and_url_args(origin_info, timestamp, visit_id) for b in branches: branch_url_args = dict(url_args) if path: b['path'] = path branch_url_args['path'] = path b['url'] = reverse('browse-origin-directory', kwargs=branch_url_args, - query_params={'branch': b['name']}) + query_params={'branch': b['name'], + 'visit_id': visit_id}) + + query_params = {'visit_id': visit_id} revision_id = request.GET.get('revision', None) if revision_id: revision = service.lookup_revision(revision_id) root_sha1_git = revision['directory'] branches.append({'name': revision_id, 'revision': revision_id, 'directory': root_sha1_git, 'url': None}) branch_name = revision_id + query_params['revision'] = revision_id else: branch_name = request.GET.get('branch', 'HEAD') branch = _get_branch(branches, branch_name) if branch: branch_name = branch['name'] root_sha1_git = branch['directory'] + query_params['branch'] = branch_name else: - _raise_exception_if_branch_not_found(origin_id, visit_id, - timestamp, branch_name, - branches) + _raise_exception_if_branch_not_found(origin_info, timestamp, + branch_name, branches, + visit_id) sha1_git = root_sha1_git if path: dir_info = service.lookup_directory_with_path(root_sha1_git, path) sha1_git = dir_info['target'] dirs, files = get_directory_entries(sha1_git) except Exception as exc: return handle_view_exception(request, exc) - if revision_id: - query_params = {'revision': revision_id} - else: - query_params = {'branch': branch_name} - path_info = gen_path_info(path) breadcrumbs = [] breadcrumbs.append({'name': root_sha1_git[:7], 'url': reverse('browse-origin-directory', kwargs=url_args, query_params=query_params)}) for pi in path_info: bc_url_args = dict(url_args) bc_url_args['path'] = pi['path'] breadcrumbs.append({'name': pi['name'], 'url': reverse('browse-origin-directory', kwargs=bc_url_args, query_params=query_params)}) path = '' if path is None else (path + '/') for d in dirs: bc_url_args = dict(url_args) bc_url_args['path'] = path + d['name'] d['url'] = reverse('browse-origin-directory', kwargs=bc_url_args, query_params=query_params) sum_file_sizes = 0 readme_name = None readme_url = None for f in files: bc_url_args = dict(url_args) bc_url_args['path'] = path + f['name'] f['url'] = reverse('browse-origin-content', kwargs=bc_url_args, query_params=query_params) sum_file_sizes += f['length'] f['length'] = filesizeformat(f['length']) if f['name'].lower().startswith('readme'): readme_name = f['name'] readme_sha1 = f['checksums']['sha1'] readme_url = reverse('browse-content-raw', kwargs={'query_string': readme_sha1}) history_url = reverse('browse-origin-log', kwargs=url_args, query_params=query_params) sum_file_sizes = filesizeformat(sum_file_sizes) dir_metadata = {'id': sha1_git, 'number of regular files': len(files), 'number of subdirectories': len(dirs), 'sum of regular file sizes': sum_file_sizes, 'origin id': origin_info['id'], 'origin type': origin_info['type'], 'origin url': origin_info['url'], - 'origin visit': format_utc_iso_date(visit_info['date']), + 'origin visit date': format_utc_iso_date(visit_info['date']), # noqa + 'origin visit id': visit_info['visit'], 'path': '/' + path} return render(request, 'directory.html', {'heading': 'Directory information', 'top_panel_visible': True, 'top_panel_collapsible': True, 'top_panel_text_left': 'SWH object: Directory', - 'top_panel_text_right': gen_origin_link( - origin_id, origin_info['url']), + 'top_panel_text_right': gen_origin_link(origin_info), 'swh_object_metadata': dir_metadata, 'main_panel_visible': True, 'dirs': dirs, 'files': files, 'breadcrumbs': breadcrumbs, 'branches': branches, 'branch': branch_name, 'top_right_link': history_url, 'top_right_link_text': mark_safe( '' 'History' ), 'readme_name': readme_name, 'readme_url': readme_url}) -@browse_route(r'origin/(?P[0-9]+)/content/(?P.+)/', - r'origin/(?P[0-9]+)/visit/(?P[0-9]+)/content/(?P.+)/', # noqa - r'origin/(?P[0-9]+)/ts/(?P.+)/content/(?P.+)/', # noqa +@browse_route(r'origin/(?P[a-z]+)/url/(?P.+)/visit/(?P.+)/content/(?P.+)/', # noqa + r'origin/(?P[a-z]+)/url/(?P.+)/content/(?P.+)/', # noqa view_name='browse-origin-content') -def origin_content_display(request, origin_id, path, - visit_id=None, timestamp=None): +def origin_content_display(request, origin_type, origin_url, path, + timestamp=None): """Django view that produces an HTML display of a swh content associated to an origin for a given visit. The url scheme that points to it is the following: - * :http:get:`/browse/origin/(origin_id)/content/(path)/` - * :http:get:`/browse/origin/(origin_id)/visit/(visit_id)/content/(path)/` - * :http:get:`/browse/origin/(origin_id)/ts/(timestamp)/content/(path)/` + * :http:get:`/browse/origin/(origin_type)/url/(origin_url)/content/(path)/` + * :http:get:`/browse/origin/(origin_type)/url/(origin_url)/visit/(timestamp)/content/(path)/` Args: request: input django http request - origin_id: id of a swh origin + origin_type: the type of swh origin (git, svn, hg, ...) + origin_url: the url of the swh origin path: path of the content relative to the origin root directory - visit_id: optionnal visit id parameter + timestamp: optional swh visit timestamp parameter (the last one will be used by default) - timestamp: optionnal visit timestamp parameter - (the last one will be used by default) - branch: optionnal query parameter that specifies the origin branch + branch: optional query parameter that specifies the origin branch from which to retrieve the content revision: optional query parameter to specify the origin revision from which to retrieve the content Returns: The HTML rendering of the requested content associated to the provided origin and visit. """ # noqa try: - if not visit_id and not timestamp: - origin_visits = get_origin_visits(origin_id) - if not origin_visits: - raise NotFoundExc('No SWH visit associated to ' - 'origin with id %s' % origin_id) - return origin_content_display(request, origin_id, path, - origin_visits[-1]['visit']) + origin_info = service.lookup_origin({ + 'type': origin_type, + 'url': origin_url + }) - origin_info = service.lookup_origin({'id': origin_id}) - branches, url_args = \ - _get_origin_branches_and_url_args(origin_id, visit_id, timestamp) + visit_id = request.GET.get('visit_id', None) + + visit_info = get_origin_visit(origin_info, timestamp, visit_id) + if timestamp: + timestamp = visit_info['date'] - visit_info = get_origin_visit(origin_id, visit_id, timestamp) + branches, url_args = \ + _get_origin_branches_and_url_args(origin_info, timestamp, visit_id) for b in branches: bc_url_args = dict(url_args) bc_url_args['path'] = path b['url'] = reverse('browse-origin-content', kwargs=bc_url_args, - query_params={'branch': b['name']}) + query_params={'branch': b['name'], + 'visit_id': visit_id}) + + query_params = {'visit_id': visit_id} revision_id = request.GET.get('revision', None) if revision_id: revision = service.lookup_revision(revision_id) root_sha1_git = revision['directory'] branches.append({'name': revision_id, 'revision': revision_id, 'directory': root_sha1_git, 'url': None}) branch_name = revision_id + query_params['revision'] = revision_id else: branch_name = request.GET.get('branch', 'HEAD') branch = _get_branch(branches, branch_name) if branch: branch_name = branch['name'] root_sha1_git = branch['directory'] + query_params['branch'] = branch_name else: - _raise_exception_if_branch_not_found(origin_id, visit_id, - timestamp, branch_name, - branches) + _raise_exception_if_branch_not_found(origin_info, timestamp, + branch_name, branches, + visit_id) content_info = service.lookup_directory_with_path(root_sha1_git, path) sha1_git = content_info['target'] query_string = 'sha1_git:' + sha1_git content_data = request_content(query_string) except Exception as exc: return handle_view_exception(request, exc) - if revision_id: - query_params = {'revision': revision_id} - else: - query_params = {'branch': branch_name} - content_display_data = prepare_content_for_display( content_data['raw_data'], content_data['mimetype'], path) filename = None path_info = None breadcrumbs = [] split_path = path.split('/') filename = split_path[-1] path = path.replace(filename, '') path_info = gen_path_info(path) breadcrumbs.append({'name': root_sha1_git[:7], 'url': reverse('browse-origin-directory', kwargs=url_args, query_params=query_params)}) for pi in path_info: bc_url_args = dict(url_args) bc_url_args['path'] = pi['path'] breadcrumbs.append({'name': pi['name'], 'url': reverse('browse-origin-directory', kwargs=bc_url_args, query_params=query_params)}) breadcrumbs.append({'name': filename, 'url': None}) content_raw_url = reverse('browse-content-raw', kwargs={'query_string': query_string}, query_params={'filename': filename}) content_metadata = { 'sha1 checksum': content_data['checksums']['sha1'], 'sha1_git checksum': content_data['checksums']['sha1_git'], 'sha256 checksum': content_data['checksums']['sha256'], 'blake2s256 checksum': content_data['checksums']['blake2s256'], 'mime type': content_data['mimetype'], 'encoding': content_data['encoding'], 'size': filesizeformat(content_data['length']), 'language': content_data['language'], 'licenses': content_data['licenses'], 'origin id': origin_info['id'], 'origin type': origin_info['type'], 'origin url': origin_info['url'], - 'origin visit': format_utc_iso_date(visit_info['date']), + 'origin visit date': format_utc_iso_date(visit_info['date']), + 'origin visit id': visit_info['visit'], 'path': '/' + path, 'filename': filename } return render(request, 'content.html', {'heading': 'Content information', 'top_panel_visible': True, 'top_panel_collapsible': True, 'top_panel_text_left': 'SWH object: Content', - 'top_panel_text_right': gen_origin_link( - origin_id, origin_info['url']), + 'top_panel_text_right': gen_origin_link(origin_info), 'swh_object_metadata': content_metadata, 'main_panel_visible': True, 'content': content_display_data['content_data'], 'mimetype': content_data['mimetype'], 'language': content_display_data['language'], 'breadcrumbs': breadcrumbs, 'branches': branches, 'branch': branch_name, 'top_right_link': content_raw_url, 'top_right_link_text': mark_safe( 'Raw File') }) -def _gen_directory_link(url_args, revision, link_text): +def _gen_directory_link(url_args, query_params, link_text): directory_url = reverse('browse-origin-directory', kwargs=url_args, - query_params={'revision': revision}) + query_params=query_params) return gen_link(directory_url, link_text) NB_LOG_ENTRIES = 20 -@browse_route(r'origin/(?P[0-9]+)/log/', - r'origin/(?P[0-9]+)/visit/(?P[0-9]+)/log/', # noqa - r'origin/(?P[0-9]+)/ts/(?P.+)/log/', +@browse_route(r'origin/(?P[a-z]+)/url/(?P.+)/visit/(?P.+)/log/', # noqa + r'origin/(?P[a-z]+)/url/(?P.+)/log/', view_name='browse-origin-log') -def origin_log_browse(request, origin_id, visit_id=None, timestamp=None): +def origin_log_browse(request, origin_type, origin_url, timestamp=None): """Django view that produces an HTML display of revisions history (aka the commit log) associated to a SWH origin. The url scheme that points to it is the following: - * :http:get:`/browse/origin/(origin_id)/log/` - * :http:get:`/browse/origin/(origin_id)/visit/(visit_id)/log/` - * :http:get:`/browse/origin/(origin_id)/ts/(timestamp)/log/` + * :http:get:`/browse/origin/(origin_type)/url/(origin_url)/log/` + * :http:get:`/browse/origin/(origin_type)/url/(origin_url)/visit/(timestamp)/log/` Args: request: input django http request - origin_id: id of a swh origin - visit_id: optionnal visit id parameter - (the last one will be used by default) + origin_type: the type of swh origin (git, svn, hg, ...) + origin_url: the url of the swh origin timestamp: optionnal visit timestamp parameter (the last one will be used by default) revs_breadcrumb: query parameter used internally to store the navigation breadcrumbs (i.e. the list of descendant revisions visited so far). per_page: optionnal query parameter used to specify the number of log entries per page branch: optionnal query parameter that specifies the origin branch from which to retrieve the content revision: optional query parameter to specify the origin revision from which to retrieve the directory Returns: The HTML rendering of revisions history for a given SWH visit. """ # noqa try: - if not visit_id and not timestamp: - origin_visits = get_origin_visits(origin_id) - if not origin_visits: - raise NotFoundExc('No SWH visit associated to ' - 'origin with id %s' % origin_id) - return origin_log_browse(request, origin_id, - origin_visits[-1]['visit']) + origin_info = service.lookup_origin({ + 'type': origin_type, + 'url': origin_url + }) - branches, url_args = \ - _get_origin_branches_and_url_args(origin_id, visit_id, timestamp) + visit_id = request.GET.get('visit_id', None) + + visit_info = get_origin_visit(origin_info, timestamp, visit_id) + if timestamp: + timestamp = visit_info['date'] - visit_info = get_origin_visit(origin_id, visit_id, timestamp) + branches, url_args = \ + _get_origin_branches_and_url_args(origin_info, timestamp, visit_id) for b in branches: b['url'] = reverse('browse-origin-log', kwargs=url_args, - query_params={'branch': b['name']}) + query_params={'branch': b['name'], + 'visit_id': visit_id}) revision_id = request.GET.get('revision', None) revs_breadcrumb = request.GET.get('revs_breadcrumb', None) branch_name = request.GET.get('branch', 'HEAD') if revision_id: revision = service.lookup_revision(revision_id) branches.append({'name': revision_id, 'revision': revision_id, 'directory': revision['directory']}) revision = revision_id branch_name = revision_id elif revs_breadcrumb: revs = revs_breadcrumb.split('/') revision = revs[-1] else: branch = _get_branch(branches, branch_name) if branch: branch_name = branch['name'] revision = branch['revision'] else: - _raise_exception_if_branch_not_found(origin_id, visit_id, - timestamp, branch_name, - branches) + _raise_exception_if_branch_not_found(origin_info, timestamp, + branch_name, branches, + visit_id) per_page = int(request.GET.get('per_page', NB_LOG_ENTRIES)) revision_log = service.lookup_revision_log(revision, limit=per_page+1) revision_log = list(revision_log) except Exception as exc: return handle_view_exception(request, exc) revision_log_display_data = prepare_revision_log_for_display( revision_log, per_page, revs_breadcrumb, origin_context=True, - origin_id=origin_id) + origin_info=origin_info) prev_rev = revision_log_display_data['prev_rev'] prev_revs_breadcrumb = revision_log_display_data['prev_revs_breadcrumb'] prev_log_url = None if prev_rev: prev_log_url = \ reverse('browse-origin-log', kwargs=url_args, query_params={'revs_breadcrumb': prev_revs_breadcrumb, 'per_page': per_page, - 'branch': branch_name}) + 'branch': branch_name, + 'visit_id': visit_id}) next_rev = revision_log_display_data['next_rev'] next_revs_breadcrumb = revision_log_display_data['next_revs_breadcrumb'] next_log_url = None if next_rev: next_log_url = \ reverse('browse-origin-log', kwargs=url_args, query_params={'revs_breadcrumb': next_revs_breadcrumb, 'per_page': per_page, - 'branch': branch_name}) + 'branch': branch_name, + 'visit_id': visit_id}) revision_log_data = revision_log_display_data['revision_log_data'] for i, log in enumerate(revision_log_data): - log['directory'] = _gen_directory_link(url_args, revision_log[i]['id'], - 'Tree') - - origin_info = service.lookup_origin({'id': origin_id}) + query_params = { + 'revision': revision_log[i]['id'], + 'visit_id': visit_id + } + log['directory'] = _gen_directory_link(url_args, query_params, 'Tree') revision_metadata = { 'origin id': origin_info['id'], 'origin type': origin_info['type'], 'origin url': origin_info['url'], - 'origin visit': format_utc_iso_date(visit_info['date']) + 'origin visit date': format_utc_iso_date(visit_info['date']), + 'origin visit id': visit_info['visit'] } return render(request, 'revision-log.html', {'heading': 'Revision history information', 'top_panel_visible': True, 'top_panel_collapsible': True, 'top_panel_text_left': 'SWH object: Revision history', - 'top_panel_text_right': gen_origin_link( - origin_id, origin_info['url']), + 'top_panel_text_right': gen_origin_link(origin_info), 'swh_object_metadata': revision_metadata, 'main_panel_visible': True, 'revision_log': revision_log_data, 'next_log_url': next_log_url, 'prev_log_url': prev_log_url, 'breadcrumbs': None, 'branches': branches, 'branch': branch_name, 'top_right_link': None, 'top_right_link_text': None, 'include_top_navigation': True, 'no_origin_context': False}) +@browse_route(r'origin/(?P[a-z]+)/url/(?P.+)/', + view_name='browse-origin') +def origin_browse(request, origin_type=None, origin_url=None): + """Django view that produces an HTML display of a swh origin identified + by its id or its url. + + The url scheme that points to it is :http:get:`/browse/origin/(origin_type)/url/(origin_url)/`. + + Args: + request: input django http request + origin_type: type of origin (git, svn, ...) + origin_url: url of the origin (e.g. https://github.com//) + + Returns: + The HMTL rendering for the metadata of the provided origin. + """ # noqa + try: + origin_info = service.lookup_origin({ + 'type': origin_type, + 'url': origin_url + }) + origin_visits = get_origin_visits(origin_info) + except Exception as exc: + return handle_view_exception(request, exc) + + origin_info['last swh visit browse url'] = \ + reverse('browse-origin-directory', + kwargs={'origin_type': origin_type, + 'origin_url': origin_url}) + + origin_visits_data = [] + for i, visit in enumerate(origin_visits): + visit_date = dateutil.parser.parse(visit['date']) + url_date = format_utc_iso_date(visit['date'], '%Y-%m-%dT%H:%M:%S') + visit['fmt_date'] = format_utc_iso_date(visit['date']) + query_params = {} + if i < len(origin_visits) - 1: + if visit['date'] == origin_visits[i+1]['date']: + query_params = {'visit_id': visit['visit']} + if i > 0: + if visit['date'] == origin_visits[i-1]['date']: + query_params = {'visit_id': visit['visit']} + + visit['browse_url'] = reverse('browse-origin-directory', + kwargs={'origin_type': origin_type, + 'origin_url': origin_url, + 'timestamp': url_date}, + query_params=query_params) + origin_visits_data.append( + {'date': visit_date.timestamp()}) + + return render(request, 'origin.html', + {'heading': 'Origin information', + 'top_panel_visible': True, + 'top_panel_collapsible': True, + 'top_panel_text_left': 'SWH object: Origin', + 'top_panel_text_right': 'Url: ' + origin_info['url'], + 'swh_object_metadata': origin_info, + 'main_panel_visible': True, + 'origin_visits_data': origin_visits_data, + 'visits': list(reversed(origin_visits)), + 'browse_url_base': '/browse/origin/%s/url/%s/' % + (origin_type, origin_url)}) + + @browse_route(r'origin/search/(?P.+)/', view_name='browse-origin-search') def origin_search(request, url_pattern): """Search for origins whose urls contain a provided string pattern or match a provided regular expression. The search is performed in a case insensitive way. """ offset = int(request.GET.get('offset', '0')) limit = int(request.GET.get('limit', '50')) regexp = request.GET.get('regexp', 'false') results = service.search_origin(url_pattern, offset, limit, bool(strtobool(regexp))) results = json.dumps(list(results), sort_keys=True, indent=4, separators=(',', ': ')) return HttpResponse(results, content_type='application/json') diff --git a/swh/web/browse/views/revision.py b/swh/web/browse/views/revision.py index fed62cb5..d624c07e 100644 --- a/swh/web/browse/views/revision.py +++ b/swh/web/browse/views/revision.py @@ -1,206 +1,204 @@ # Copyright (C) 2017 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information import json from django.shortcuts import render from django.utils.safestring import mark_safe from swh.web.common import service from swh.web.common.utils import reverse, format_utc_iso_date from swh.web.common.exc import handle_view_exception from swh.web.browse.browseurls import browse_route from swh.web.browse.utils import ( gen_link, gen_person_link, gen_revision_link, prepare_revision_log_for_display, gen_origin_link ) def _gen_directory_link(sha1_git, link_text=None): directory_url = reverse('browse-directory', kwargs={'sha1_git': sha1_git}) if not link_text: link_text = directory_url return gen_link(directory_url, link_text) -def _gen_origin_directory_link(origin_id, revision_id): +def _gen_origin_directory_link(origin_info, revision_id): directory_url = reverse('browse-origin-directory', - kwargs={'origin_id': origin_id}, + kwargs={'origin_type': origin_info['type'], + 'origin_url': origin_info['url']}, query_params={'revision': revision_id}) return gen_link(directory_url, directory_url) -def _gen_revision_log_link(revision_id, origin_id=None, link_text=None): - if origin_id: +def _gen_revision_log_link(revision_id, origin_info=None, link_text=None): + if origin_info: revision_log_url = reverse('browse-origin-log', - kwargs={'origin_id': origin_id}, + kwargs={'origin_type': origin_info['type'], + 'origin_url': origin_info['url']}, query_params={'revision': revision_id}) else: revision_log_url = reverse('browse-revision-log', kwargs={'sha1_git': revision_id}) if not link_text: link_text = revision_log_url return gen_link(revision_log_url, link_text) @browse_route(r'revision/(?P[0-9a-f]+)/', view_name='browse-revision') def revision_browse(request, sha1_git): """ Django view that produces an HTML display of a SWH revision identified by its id. The url that points to it is :http:get:`/browse/revision/(sha1_git)/`. Args: request: input django http request sha1_git: a SWH revision id Returns: The HMTL rendering for the metadata of the provided revision. """ try: revision = service.lookup_revision(sha1_git) origin_info = None - origin_id = request.GET.get('origin_id', None) origin_type = request.GET.get('origin_type', None) origin_url = request.GET.get('origin_url', None) - if origin_id: - origin_info = service.lookup_origin({'id': origin_id}) - elif origin_type and origin_url: + if origin_type and origin_url: origin_info = service.lookup_origin({'type': origin_type, 'url': origin_url}) except Exception as exc: return handle_view_exception(request, exc) revision_data = {} revision_data['author'] = gen_person_link( revision['author']['id'], revision['author']['name']) revision_data['committer'] = gen_person_link( revision['committer']['id'], revision['committer']['name']) revision_data['committer date'] = format_utc_iso_date( revision['committer_date']) revision_data['date'] = format_utc_iso_date(revision['date']) if origin_info: revision_data['directory'] = _gen_origin_directory_link( - origin_info['id'], sha1_git) + origin_info, sha1_git) revision_data['history log'] = _gen_revision_log_link( - sha1_git, origin_info['id']) + sha1_git, origin_info) else: revision_data['directory'] = _gen_directory_link(revision['directory']) revision_data['history log'] = _gen_revision_log_link(sha1_git) revision_data['id'] = sha1_git revision_data['merge'] = revision['merge'] revision_data['message'] = revision['message'] revision_data['metadata'] = json.dumps(revision['metadata'], sort_keys=True, indent=4, separators=(',', ': ')) if origin_info: revision_data['origin id'] = origin_info['id'] revision_data['origin type'] = origin_info['type'] revision_data['origin url'] = gen_link(origin_info['url'], origin_info['url']) - top_panel_text_right = gen_origin_link(origin_info['id'], - origin_info['url']) + top_panel_text_right = gen_origin_link(origin_info) else: top_panel_text_right = 'Sha1 git: ' + sha1_git parents = '' for p in revision['parents']: - parent_link = gen_revision_link(p, origin_id=origin_id) + parent_link = gen_revision_link(p, origin_info=origin_info) parents += parent_link + '
' revision_data['parents'] = mark_safe(parents) revision_data['synthetic'] = revision['synthetic'] revision_data['type'] = revision['type'] return render(request, 'revision.html', {'heading': 'Revision information', 'top_panel_visible': False, 'top_panel_collapsible': False, 'top_panel_text_left': 'SWH object: Revision', 'top_panel_text_right': top_panel_text_right, 'swh_object_metadata': None, 'main_panel_visible': True, 'revision': revision_data}) NB_LOG_ENTRIES = 20 @browse_route(r'revision/(?P[0-9a-f]+)/log/', view_name='browse-revision-log') def revision_log_browse(request, sha1_git): """ Django view that produces an HTML display of the history log for a SWH revision identified by its id. The url that points to it is :http:get:`/browse/revision/(sha1_git)/log/`. Args: request: input django http request sha1_git: a SWH revision id Returns: The HMTL rendering of the revision history log. """ # noqa try: per_page = int(request.GET.get('per_page', NB_LOG_ENTRIES)) revision_log = service.lookup_revision_log(sha1_git, limit=per_page+1) revision_log = list(revision_log) except Exception as exc: return handle_view_exception(request, exc) revs_breadcrumb = request.GET.get('revs_breadcrumb', None) revision_log_display_data = prepare_revision_log_for_display( revision_log, per_page, revs_breadcrumb) prev_rev = revision_log_display_data['prev_rev'] prev_revs_breadcrumb = revision_log_display_data['prev_revs_breadcrumb'] prev_log_url = None if prev_rev: prev_log_url = \ reverse('browse-revision-log', kwargs={'sha1_git': prev_rev}, query_params={'revs_breadcrumb': prev_revs_breadcrumb, 'per_page': per_page}) next_rev = revision_log_display_data['next_rev'] next_revs_breadcrumb = revision_log_display_data['next_revs_breadcrumb'] next_log_url = None if next_rev: next_log_url = \ reverse('browse-revision-log', kwargs={'sha1_git': next_rev}, query_params={'revs_breadcrumb': next_revs_breadcrumb, 'per_page': per_page}) revision_log_data = revision_log_display_data['revision_log_data'] for log in revision_log_data: log['directory'] = _gen_directory_link(log['directory'], 'Tree') return render(request, 'revision-log.html', {'heading': 'Revision history information', 'top_panel_visible': False, 'top_panel_collapsible': False, 'top_panel_text_left': 'SWH object: Revision history', 'top_panel_text_right': 'Sha1 git: ' + sha1_git, 'swh_object_metadata': None, 'main_panel_visible': True, 'revision_log': revision_log_data, 'next_log_url': next_log_url, 'prev_log_url': prev_log_url, 'breadcrumbs': None, 'branches': None, 'branch': None, 'top_right_link': None, 'top_right_link_text': None, 'include_top_navigation': False, 'no_origin_context': True}) diff --git a/swh/web/common/utils.py b/swh/web/common/utils.py index c4720ffc..1a0a0c46 100644 --- a/swh/web/common/utils.py +++ b/swh/web/common/utils.py @@ -1,162 +1,165 @@ # Copyright (C) 2017 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information import re from datetime import datetime, timezone from dateutil import parser as date_parser from swh.web.common.exc import BadInputExc from django.core import urlresolvers from django.http import QueryDict def reverse(viewname, args=None, kwargs=None, query_params=None, - current_app=None, urlconf=None): + current_app=None, urlconf=None): """An override of django reverse function supporting query parameters. Args: viewname: the name of the django view from which to compute a url args: list of url arguments ordered according to their position it kwargs: dictionnary of url arguments indexed by their names query_params: dictionnary of query parameters to append to the reversed url current_app: the name of the django app tighted to the view urlconf: url configuration module Returns: The url of the requested view with processed arguments and query parameters """ url = urlresolvers.reverse( viewname, urlconf=urlconf, args=args, kwargs=kwargs, current_app=current_app) if query_params: query_params = {k: v for k, v in query_params.items() if v is not None} if query_params and len(query_params) > 0: query_dict = QueryDict('', mutable=True) - for k, v in query_params.items(): - query_dict[k] = v + for k in sorted(query_params.keys()): + query_dict[k] = query_params[k] url += ('?' + query_dict.urlencode(safe='/')) return url def fmap(f, data): """Map f to data at each level. This must keep the origin data structure type: - map -> map - dict -> dict - list -> list - None -> None Args: f: function that expects one argument. data: data to traverse to apply the f function. list, map, dict or bare value. Returns: The same data-structure with modified values by the f function. """ if data is None: return data if isinstance(data, map): return map(lambda y: fmap(f, y), (x for x in data)) if isinstance(data, list): return [fmap(f, x) for x in data] if isinstance(data, dict): return {k: fmap(f, v) for (k, v) in data.items()} return f(data) def parse_timestamp(timestamp): """Given a time or timestamp (as string), parse the result as datetime. Returns: a timezone-aware datetime representing the parsed value. None if the parsing fails. Samples: - 2016-01-12 - 2016-01-12T09:19:12+0100 - Today is January 1, 2047 at 8:21:00AM - 1452591542 """ if not timestamp: return None try: return date_parser.parse(timestamp, ignoretz=False, fuzzy=True) except: try: return datetime.utcfromtimestamp(float(timestamp)).replace( tzinfo=timezone.utc) except (ValueError, OverflowError) as e: raise BadInputExc(e) def shorten_path(path): """Shorten the given path: for each hash present, only return the first 8 characters followed by an ellipsis""" sha256_re = r'([0-9a-f]{8})[0-9a-z]{56}' sha1_re = r'([0-9a-f]{8})[0-9a-f]{32}' ret = re.sub(sha256_re, r'\1...', path) return re.sub(sha1_re, r'\1...', ret) -def format_utc_iso_date(iso_date): +def format_utc_iso_date(iso_date, fmt='%d %B %Y, %H:%M UTC'): """Turns a string reprensation of an UTC iso date into a more human readable one. - More precisely, from the following input + By default, from the following input string: '2017-05-04T13:27:13+02:00' the following one is returned: '04 May 2017, 13:27 UTC'. + Custom format string may also be provided + as parameter Args: iso_date (str): a string representation of an UTC iso date + fmt (str): optional date formatting string Returns: - A human readable string representation of the input iso date + A formatted string representation of the input iso date """ date = date_parser.parse(iso_date) - return date.strftime('%d %B %Y, %H:%M UTC') + return date.strftime(fmt) def gen_path_info(path): """Function to generate path data navigation for use with a breadcrumb in the swh web ui. For instance, from a path /folder1/folder2/folder3, it returns the following list:: [{'name': 'folder1', 'path': 'folder1'}, {'name': 'folder2', 'path': 'folder1/folder2'}, {'name': 'folder3', 'path': 'folder1/folder2/folder3'}] Args: path: a filesystem path Returns: A list of path data for navigation as illustrated above. """ path_info = [] if path: sub_paths = path.strip('/').split('/') path_from_root = '' for p in sub_paths: path_from_root += '/' + p path_info.append({'name': p, 'path': path_from_root.strip('/')}) return path_info diff --git a/swh/web/static/js/calendar.js b/swh/web/static/js/calendar.js index c9faa307..06fa65d8 100644 --- a/swh/web/static/js/calendar.js +++ b/swh/web/static/js/calendar.js @@ -1,379 +1,379 @@ /** * Calendar: * A one-off object that makes an AJAX call to the API's visit stats * endpoint, then displays these statistics in a zoomable timeline-like * format. * Args: * browse_url: the relative URL for browsing a revision via the web ui, * accurate up to the origin * visit_url: the complete relative URL for getting the origin's visit * stats * origin_id: the origin being browsed * zoomw: the element that should contain the zoomable part of the calendar * staticw: the element that should contain the static part of the calendar * reset: the element that should reset the zoom level on click */ var Calendar = function(browse_url, data, origin_id, zoomw, staticw, reset) { /** Constants **/ this.month_names = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; /** Display **/ this.desiredPxWidth = 7; /** Object vars **/ this.origin_id = origin_id; this.zoomw = zoomw; this.staticw = staticw; /** Calendar data **/ this.cal_data = null; this.static = { group_factor: 3600 * 1000, group_data: null, plot_data: null }; this.zoom = { group_factor: 3600 * 1000, group_data: null, plot_data: null }; zoomw.css('height', '100%'); /** * Keep a reference to the Calendar object context. * Otherwise, 'this' changes to represent current function caller scope */ var self = this; /** * Group the plot's base data according to the grouping ratio and the * range required * Args: * groupFactor: the amount the data should be grouped by * range: * Returns: * A dictionary containing timestamps divided by the grouping ratio as * keys, a list of the corresponding complete timestamps as values */ this.dataGroupedRange = function(groupFactor, range) { var group_dict = {}; var start = range.xaxis.from; var end = range.xaxis.to; var range_data = self.cal_data.filter(function(item, index, arr) { return item >= start && item <= end; }); for (var date_idx in range_data) { var date = range_data[date_idx]; var floor = Math.floor(date / groupFactor); if (group_dict[floor] == undefined) group_dict[floor] = [date]; else group_dict[floor].push(date); } return group_dict; }; /** * Update the ratio that governs how the data is grouped based on changes * in the data range or the display size, and regroup the plot's data * according to this value. * * Args: * element: the element in which the plot is displayed * plotprops: the properties corresponding to that plot * range: the range of the data displayed */ this.updateGroupFactorAndData = function(element, plotprops, range) { var milli_length = range.xaxis.to - range.xaxis.from; var px_length = element.width(); plotprops.group_factor = Math.floor( self.desiredPxWidth * (milli_length / px_length)); plotprops.group_data = self.dataGroupedRange( plotprops.group_factor, range); }; /** Get plot data from the group data **/ this.getPlotData = function(grouped_data) { var plot_data = []; if (self.cal_data.length == 1) { plot_data = [[self.cal_data[0] - 3600*1000*24*30, 0], [self.cal_data[0], 1], [self.cal_data[0] + 3600*1000*24*30, 0]]; } else { $.each(grouped_data, function(key, value) { plot_data.push([value[0], value.length]); }); } return [{ label: 'Calendar', data: plot_data }]; }; this.plotZoom = function(zoom_options) { return $.plot(self.zoomw, self.zoom.plot_data, zoom_options); }; this.plotStatic = function(static_options) { return $.plot(self.staticw, self.static.plot_data, static_options); }; /** * Display a zoomable calendar with click-through links to revisions * of the same origin * * Args: * data: the data that the calendar should present, as a list of * POSIX second-since-epoch timestamps */ this.calendar = function(data) { // POSIX timestamps to JS timestamps self.cal_data = data.map(function(e) { return Math.floor(e['date'] * 1000); }); /** Bootstrap the group ratio **/ var cal_data_range = null; if (self.cal_data.length == 1) { var padding_qty = 3600*1000*24*30; cal_data_range = {xaxis: {from: self.cal_data[0] - padding_qty, to: self.cal_data[0] + padding_qty}}; } else cal_data_range = {xaxis: {from: self.cal_data[0], to: self.cal_data[self.cal_data.length -1] } }; self.updateGroupFactorAndData(self.zoomw, self.zoom, cal_data_range); self.updateGroupFactorAndData(self.staticw, self.static, cal_data_range); /** Bootstrap the plot data **/ self.zoom.plot_data = self.getPlotData(self.zoom.group_data); self.static.plot_data = self.getPlotData(self.zoom.group_data); /** * Return the flot-required function for displaying tooltips, according to * the group we want to display the tooltip for * Args: * group_options: the group we want to display the tooltip for (self.static * or self.zoom) */ function tooltip_fn(group_options) { return function (label, x_timestamp, y_hits, item) { var floor_index = Math.floor( item.datapoint[0] / group_options.group_factor); var tooltip_text = group_options.group_data[floor_index].map( function(elem) { var date = new Date(elem); var year = date.getUTCFullYear(); var month = self.month_names[date.getUTCMonth()]; var day = date.getUTCDate(); var hr = date.getUTCHours(); var min = date.getUTCMinutes(); if (min < 10) min = '0'+min; return [day, month, year + ',', hr+':'+min, 'UTC'].join(' '); } ); return tooltip_text.join('
'); }; } /** Plot options for both graph windows **/ var zoom_options = { legend: { show: false }, series: { clickable: true, bars: { show: true, lineWidth: 1, barWidth: self.zoom.group_factor } }, xaxis: { mode: 'time', minTickSize: [1, 'day'], // monthNames: self.month_names, position: 'top', timeformat: "%e %b %Y" }, yaxis: { show: false }, selection: { mode: 'x' }, grid: { clickable: true, hoverable: true, margin: { left: 30, right: 30 } }, tooltip: { show: true, content: tooltip_fn(self.zoom) } }; var overview_options = { legend: { show: false }, series: { clickable: true, bars: { show: true, lineWidth: 1, barWidth: self.static.group_factor }, shadowSize: 0 }, yaxis: { show: false }, xaxis: { mode: 'time', minTickSize: [1, 'day'] }, grid: { clickable: true, hoverable: true, color: '#999', margin: { left: 30, right: 30 } }, selection: { mode: 'x' }, tooltip: { show: true, content: tooltip_fn(self.static) } }; /** draw the windows **/ var plot = self.plotZoom(zoom_options); var overview = self.plotStatic(overview_options); var current_ranges = $.extend(true, {}, cal_data_range); /** * Zoom to the mouse-selected range in the given window * * Args: * plotzone: the jQuery-selected element the zoomed plot should be * in (usually the same as the original 'zoom plot' element) * range: the data range as a dict {xaxis: {from:, to:}, * yaxis:{from:, to:}} */ function zoom(ranges) { current_ranges.xaxis.from = ranges.xaxis.from; current_ranges.xaxis.to = ranges.xaxis.to; self.updateGroupFactorAndData( self.zoomw, self.zoom, current_ranges); self.zoom.plot_data = self.getPlotData(self.zoom.group_data); var zoomedopts = $.extend(true, {}, zoom_options, { xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to }, series: { bars: {barWidth: self.zoom.group_factor} } }); return self.plotZoom(zoomedopts); } function resetZoomW(plot_options) { self.zoom.group_data = self.static.group_data; self.zoom.plot_data = self.static.plot_data; self.updateGroupFactorAndData(zoomw, self.zoom, cal_data_range); plot = self.plotZoom(plot_options); } // now connect the two self.zoomw.bind('plotselected', function (event, ranges) { zoomw.css('height', '60%'); staticw.show(); reset.show(); // clamp the zooming to prevent eternal zoom if (ranges.xaxis.to - ranges.xaxis.from < 0.00001) ranges.xaxis.to = ranges.xaxis.from + 0.00001; // do the zooming plot = zoom(ranges); // don't fire event on the overview to prevent eternal loop overview.setSelection(ranges, true); }); self.staticw_just_selected = false; self.staticw.bind('plotselected', function (event, ranges) { plot.setSelection(ranges); self.staticw_just_selected = true; }); function unbindClick() { self.zoomw.unbind('plotclick'); self.staticw.unbind('plotclick'); } function bindClick() { self.zoomw.bind('plotclick', redirect_to_revision); self.staticw.bind('plotclick', redirect_to_revision); } function redirect_to_revision(event, pos, item) { if (item && !self.staticw_just_selected) { var js_date = new Date(item.datapoint[0]); js_date.setUTCSeconds(0); js_date.setUTCMilliseconds(0); var date = js_date.toISOString(); - var url = browse_url + 'ts/' + date + '/directory/'; + var url = browse_url + 'visit/' + date + '/directory/'; window.location.href = url; } self.staticw_just_selected = false; } reset.click(function(event) { plot.clearSelection(); overview.clearSelection(); current_ranges = $.extend(true, {}, cal_data_range); zoomw.css('height', '100%'); resetZoomW(zoom_options); staticw.hide(); reset.hide(); }); $(window).resize(function(event) { /** Update zoom display **/ self.updateGroupFactorAndData(zoomw, self.zoom, current_ranges); self.zoom.plot_data = self.getPlotData(self.zoom.group_data); /** Update static display **/ self.updateGroupFactorAndData(staticw, self.static, cal_data_range); self.static.plot_data = self.getPlotData(self.static.group_data); /** Replot **/ plot = self.plotZoom(zoom_options); overview = self.plotStatic(overview_options); }); bindClick(); staticw.hide(); reset.hide(); }; self.calendar(data); }; diff --git a/swh/web/templates/directory.html b/swh/web/templates/directory.html index d0b06570..8696ad62 100644 --- a/swh/web/templates/directory.html +++ b/swh/web/templates/directory.html @@ -1,75 +1,75 @@ {% extends "browse.html" %} {% load static %} {% block header %} {% endblock %} {% block swh-browse-main-panel-content %} {% include "includes/top-navigation.html" %}
{% for d in dirs %} {% endfor %} {% for f in files %} {% endfor %}
File Mode Size Sha1 git
- {{ d.name }} + {{ d.name }} {{ d.perms }} {{ d.target }}
- {{ f.name }} + {{ f.name }} {{ f.perms }} {{ f.length }} {{ f.target }}
{% endblock %} {% block swh-browse-panels-group-end %} {% if readme_name %}

{{ readme_name }}

{% endif %} {% endblock %} diff --git a/swh/web/templates/includes/origins-search.html b/swh/web/templates/includes/origins-search.html index 948ea81f..b98acd96 100644 --- a/swh/web/templates/includes/origins-search.html +++ b/swh/web/templates/includes/origins-search.html @@ -1,166 +1,166 @@ {% load static %}

Search Software Heritage origins to browse:

Searching origins ...

Origin id Origin type Origin url
\ No newline at end of file diff --git a/swh/web/templates/includes/top-navigation.html b/swh/web/templates/includes/top-navigation.html index b659e447..b99e7b6d 100644 --- a/swh/web/templates/includes/top-navigation.html +++ b/swh/web/templates/includes/top-navigation.html @@ -1,44 +1,44 @@
{% if branches %} {% endif %} {% if top_right_link %} - {{ top_right_link_text }} + {{ top_right_link_text }} {% endif %}
diff --git a/swh/web/templates/origin.html b/swh/web/templates/origin.html index 3b9d8731..7931750a 100644 --- a/swh/web/templates/origin.html +++ b/swh/web/templates/origin.html @@ -1,58 +1,58 @@ {% extends "browse.html" %} {% load static %} {% load swh_templatetags %} {% block swh-browse-main-panel-content %}

Visits history

Calendar

List

{% for v in visits %} - + {% endfor %}
Visit id Visit date Visit status Tree
{{ v.visit }}{{ v.date }}{{ v.fmt_date }} {{ v.status }} {{ v.browse_url }}
{% endblock %} diff --git a/swh/web/tests/browse/test_utils.py b/swh/web/tests/browse/test_utils.py index 1b0dc63f..82b5fa4f 100644 --- a/swh/web/tests/browse/test_utils.py +++ b/swh/web/tests/browse/test_utils.py @@ -1,362 +1,388 @@ # Copyright (C) 2017 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information import unittest from unittest.mock import patch from nose.tools import istest from swh.web.browse import utils from swh.web.common.exc import NotFoundExc from swh.web.common.utils import reverse from swh.web.tests.testbase import SWHWebTestBase from .views.data.revision_test_data import revision_history_log_test class SwhBrowseUtilsTestCase(SWHWebTestBase, unittest.TestCase): @istest def get_mimetype_and_encoding_for_content(self): text = b'Hello world!' self.assertEqual(utils.get_mimetype_and_encoding_for_content(text), ('text/plain', 'us-ascii')) @patch('swh.web.browse.utils.service') @istest def get_origin_visits(self, mock_service): mock_service.MAX_LIMIT = 2 def _lookup_origin_visits(*args, **kwargs): if kwargs['last_visit'] is None: - return [{'visit': 1}, {'visit': 2}] + return [{'visit': 1, + 'date': '2017-05-06T00:59:10+00:00', + 'metadata': {}}, + {'visit': 2, + 'date': '2017-08-06T00:59:10+00:00', + 'metadata': {}} + ] else: - return [{'visit': 3}] + return [{'visit': 3, + 'date': '2017-09-06T00:59:10+00:00', + 'metadata': {}} + ] mock_service.lookup_origin_visits.side_effect = _lookup_origin_visits - origin_visits = utils.get_origin_visits(1) + origin_info = { + 'id': 1, + 'type': 'git', + 'url': 'https://github.com/foo/bar', + } + + origin_visits = utils.get_origin_visits(origin_info) self.assertEqual(len(origin_visits), 3) @patch('swh.web.browse.utils.get_origin_visits') @istest def get_origin_visit(self, mock_origin_visits): - origin_id = 2 + origin_info = { + 'id': 2, + 'type': 'git', + 'url': 'https://github.com/foo/bar', + } visits = \ [{'status': 'full', 'date': '2015-07-09T21:09:24+00:00', 'visit': 1, - 'origin': origin_id + 'origin': origin_info['id'] }, {'status': 'full', 'date': '2016-02-23T18:05:23.312045+00:00', 'visit': 2, - 'origin': origin_id + 'origin': origin_info['id'] }, {'status': 'full', 'date': '2016-03-28T01:35:06.554111+00:00', 'visit': 3, - 'origin': origin_id + 'origin': origin_info['id'] }, {'status': 'full', 'date': '2016-06-18T01:22:24.808485+00:00', 'visit': 4, - 'origin': origin_id + 'origin': origin_info['id'] }, {'status': 'full', 'date': '2016-08-14T12:10:00.536702+00:00', 'visit': 5, - 'origin': origin_id + 'origin': origin_info['id'] }] mock_origin_visits.return_value = visits with self.assertRaises(NotFoundExc) as cm: visit_id = 12 - visit = utils.get_origin_visit(origin_id, visit_id=visit_id) + visit = utils.get_origin_visit(origin_info, + visit_id=visit_id) self.assertIn('Visit with id %s for origin with id %s not found' % - (origin_id, visit_id), + (origin_info['id'], visit_id), cm.exception.args[0]) - visit = utils.get_origin_visit(origin_id, visit_id=2) + visit = utils.get_origin_visit(origin_info, visit_id=2) self.assertEqual(visit, visits[1]) visit = utils.get_origin_visit( - origin_id, visit_ts='2016-02-23T18:05:23.312045+00:00') + origin_info, visit_ts='2016-02-23T18:05:23.312045+00:00') self.assertEqual(visit, visits[1]) visit = utils.get_origin_visit( - origin_id, visit_ts='2016-02-20') + origin_info, visit_ts='2016-02-20') self.assertEqual(visit, visits[1]) visit = utils.get_origin_visit( - origin_id, visit_ts='2016-06-18T01:22') + origin_info, visit_ts='2016-06-18T01:22') self.assertEqual(visit, visits[3]) visit = utils.get_origin_visit( - origin_id, visit_ts='2016-06-18 01:22') + origin_info, visit_ts='2016-06-18 01:22') self.assertEqual(visit, visits[3]) visit = utils.get_origin_visit( - origin_id, visit_ts=1466208000) + origin_info, visit_ts=1466208000) self.assertEqual(visit, visits[3]) visit = utils.get_origin_visit( - origin_id, visit_ts='2014-01-01') + origin_info, visit_ts='2014-01-01') self.assertEqual(visit, visits[0]) visit = utils.get_origin_visit( - origin_id, visit_ts='2018-01-01') + origin_info, visit_ts='2018-01-01') self.assertEqual(visit, visits[-1]) @patch('swh.web.browse.utils.service') @patch('swh.web.browse.utils.get_origin_visit') @istest def get_origin_visit_branches(self, mock_get_origin_visit, mock_service): mock_get_origin_visit.return_value = \ {'status': 'full', 'date': '2015-08-04T22:26:14.804009+00:00', 'visit': 1, 'origin': 1} mock_service.lookup_origin_visit.return_value = \ {'date': '2015-08-04T22:26:14.804009+00:00', 'metadata': {}, 'occurrences': { 'refs/heads/master': { 'target': '9fbd21adbac36be869514e82e2e98505dc47219c', 'target_type': 'revision', 'target_url': '/api/1/revision/9fbd21adbac36be869514e82e2e98505dc47219c/' # noqa }, 'refs/tags/0.10.0': { 'target': '6072557b6c10cd9a21145781e26ad1f978ed14b9', 'target_type': 'revision', 'target_url': '/api/1/revision/6072557b6c10cd9a21145781e26ad1f978ed14b9/' # noqa }, 'refs/tags/0.10.1': { 'target': 'ecc003b43433e5b46511157598e4857a761007bf', 'target_type': 'revision', 'target_url': '/api/1/revision/ecc003b43433e5b46511157598e4857a761007bf/' # noqa } }, 'origin': 1, 'origin_url': '/api/1/origin/1/', 'status': 'full', 'visit': 1} mock_service.lookup_revision_multiple.return_value = \ [{'directory': '828da2b80e41aa958b2c98526f4a1d2cc7d298b7'}, {'directory': '2df4cd84ecc65b50b1d5318d3727e02a39b8a4cf'}, {'directory': '28ba64f97ef709e54838ae482c2da2619a74a0bd'}] expected_result = [ {'name': 'refs/heads/master', 'revision': '9fbd21adbac36be869514e82e2e98505dc47219c', 'directory': '828da2b80e41aa958b2c98526f4a1d2cc7d298b7'}, {'name': 'refs/tags/0.10.0', 'revision': '6072557b6c10cd9a21145781e26ad1f978ed14b9', 'directory': '2df4cd84ecc65b50b1d5318d3727e02a39b8a4cf'}, {'name': 'refs/tags/0.10.1', 'revision': 'ecc003b43433e5b46511157598e4857a761007bf', 'directory': '28ba64f97ef709e54838ae482c2da2619a74a0bd'} ] - origin_visit_branches = utils.get_origin_visit_branches(1, 1) + origin_info = { + 'id': 1, + 'type': 'git', + 'url': 'https://github.com/hylang/hy' + } + + origin_visit_branches = utils.get_origin_visit_branches(origin_info, 1) self.assertEqual(origin_visit_branches, expected_result) @istest def gen_link(self): self.assertEqual(utils.gen_link('https://www.softwareheritage.org/', 'SWH'), # noqa 'SWH') @istest def gen_person_link(self): person_id = 8221896 person_name = 'Antoine Lambert' person_url = reverse('browse-person', kwargs={'person_id': person_id}) self.assertEqual(utils.gen_person_link(person_id, person_name), '%s' % (person_url, person_name)) @istest def gen_revision_link(self): revision_id = '28a0bc4120d38a394499382ba21d6965a67a3703' revision_url = reverse('browse-revision', kwargs={'sha1_git': revision_id}) self.assertEqual(utils.gen_revision_link(revision_id), '%s' % (revision_url, revision_id)) self.assertEqual(utils.gen_revision_link(revision_id, shorten_id=True), '%s' % (revision_url, revision_id[:7])) # noqa @istest def prepare_revision_log_for_display_no_contex(self): per_page = 10 first_page_logs_data = revision_history_log_test[:per_page+1] second_page_logs_data = revision_history_log_test[per_page:2*per_page+1] # noqa third_page_logs_data = revision_history_log_test[2*per_page:3*per_page+1] # noqa last_page_logs_data = revision_history_log_test[3*per_page:3*per_page+5] # noqa revision_log_display_data = utils.prepare_revision_log_for_display( first_page_logs_data, per_page, None) self.assertEqual(revision_log_display_data['revision_log_data'], utils._format_log_entries(first_page_logs_data, per_page)) self.assertEqual(revision_log_display_data['prev_rev'], first_page_logs_data[-1]['id']) self.assertEqual(revision_log_display_data['prev_revs_breadcrumb'], first_page_logs_data[0]['id']) self.assertEqual(revision_log_display_data['next_rev'], None) self.assertEqual(revision_log_display_data['next_revs_breadcrumb'], None) old_prev_revs_bc = str(revision_log_display_data['prev_revs_breadcrumb']) # noqa revision_log_display_data = utils.prepare_revision_log_for_display( second_page_logs_data, per_page, old_prev_revs_bc) self.assertEqual(revision_log_display_data['revision_log_data'], utils._format_log_entries(second_page_logs_data, per_page)) self.assertEqual(revision_log_display_data['prev_rev'], second_page_logs_data[-1]['id']) self.assertEqual(revision_log_display_data['prev_revs_breadcrumb'], old_prev_revs_bc + '/' + second_page_logs_data[0]['id']) # noqa self.assertEqual(revision_log_display_data['next_rev'], old_prev_revs_bc) self.assertEqual(revision_log_display_data['next_revs_breadcrumb'], None) old_prev_revs_bc = str(revision_log_display_data['prev_revs_breadcrumb']) # noqa revision_log_display_data = utils.prepare_revision_log_for_display( third_page_logs_data, per_page, old_prev_revs_bc) self.assertEqual(revision_log_display_data['revision_log_data'], utils._format_log_entries(third_page_logs_data, per_page)) # noqa self.assertEqual(revision_log_display_data['prev_rev'], third_page_logs_data[-1]['id']) self.assertEqual(revision_log_display_data['prev_revs_breadcrumb'], old_prev_revs_bc + '/' + third_page_logs_data[0]['id']) # noqa self.assertEqual(revision_log_display_data['next_rev'], old_prev_revs_bc.split('/')[-1]) self.assertEqual(revision_log_display_data['next_revs_breadcrumb'], '/'.join(old_prev_revs_bc.split('/')[:-1])) old_prev_revs_bc = str(revision_log_display_data['prev_revs_breadcrumb']) # noqa revision_log_display_data = utils.prepare_revision_log_for_display( last_page_logs_data, per_page, old_prev_revs_bc) self.assertEqual(revision_log_display_data['revision_log_data'], utils._format_log_entries(last_page_logs_data, per_page)) # noqa self.assertEqual(revision_log_display_data['prev_rev'], None) self.assertEqual(revision_log_display_data['prev_revs_breadcrumb'], None) # noqa self.assertEqual(revision_log_display_data['next_rev'], old_prev_revs_bc.split('/')[-1]) # noqa self.assertEqual(revision_log_display_data['next_revs_breadcrumb'], '/'.join(old_prev_revs_bc.split('/')[:-1])) @istest def prepare_revision_log_for_display_origin_contex(self): per_page = 10 first_page_logs_data = revision_history_log_test[:per_page+1] second_page_logs_data = revision_history_log_test[per_page:2*per_page+1] # noqa third_page_logs_data = revision_history_log_test[2*per_page:3*per_page+1] # noqa last_page_logs_data = revision_history_log_test[3*per_page:3*per_page+5] # noqa revision_log_display_data = utils.prepare_revision_log_for_display( first_page_logs_data, per_page, None, origin_context=True) self.assertEqual(revision_log_display_data['revision_log_data'], utils._format_log_entries(first_page_logs_data, per_page)) self.assertEqual(revision_log_display_data['prev_rev'], first_page_logs_data[-1]['id']) self.assertEqual(revision_log_display_data['prev_revs_breadcrumb'], first_page_logs_data[-1]['id']) self.assertEqual(revision_log_display_data['next_rev'], None) self.assertEqual(revision_log_display_data['next_revs_breadcrumb'], None) old_prev_revs_bc = str(revision_log_display_data['prev_revs_breadcrumb']) # noqa revision_log_display_data = utils.prepare_revision_log_for_display( second_page_logs_data, per_page, old_prev_revs_bc, origin_context=True) # noqa self.assertEqual(revision_log_display_data['revision_log_data'], utils._format_log_entries(second_page_logs_data, per_page)) self.assertEqual(revision_log_display_data['prev_rev'], second_page_logs_data[-1]['id']) self.assertEqual(revision_log_display_data['prev_revs_breadcrumb'], old_prev_revs_bc + '/' + second_page_logs_data[-1]['id']) # noqa self.assertEqual(revision_log_display_data['next_rev'], old_prev_revs_bc) self.assertEqual(revision_log_display_data['next_revs_breadcrumb'], None) old_prev_revs_bc = str(revision_log_display_data['prev_revs_breadcrumb']) # noqa revision_log_display_data = utils.prepare_revision_log_for_display( third_page_logs_data, per_page, old_prev_revs_bc, origin_context=True) # noqa self.assertEqual(revision_log_display_data['revision_log_data'], utils._format_log_entries(third_page_logs_data, per_page)) # noqa self.assertEqual(revision_log_display_data['prev_rev'], third_page_logs_data[-1]['id']) self.assertEqual(revision_log_display_data['prev_revs_breadcrumb'], old_prev_revs_bc + '/' + third_page_logs_data[-1]['id']) # noqa self.assertEqual(revision_log_display_data['next_rev'], old_prev_revs_bc.split('/')[-1]) self.assertEqual(revision_log_display_data['next_revs_breadcrumb'], '/'.join(old_prev_revs_bc.split('/')[:-1])) old_prev_revs_bc = str(revision_log_display_data['prev_revs_breadcrumb']) # noqa revision_log_display_data = utils.prepare_revision_log_for_display( last_page_logs_data, per_page, old_prev_revs_bc, origin_context=True) # noqa self.assertEqual(revision_log_display_data['revision_log_data'], utils._format_log_entries(last_page_logs_data, per_page)) # noqa self.assertEqual(revision_log_display_data['prev_rev'], None) self.assertEqual(revision_log_display_data['prev_revs_breadcrumb'], None) # noqa self.assertEqual(revision_log_display_data['next_rev'], old_prev_revs_bc.split('/')[-1]) # noqa self.assertEqual(revision_log_display_data['next_revs_breadcrumb'], '/'.join(old_prev_revs_bc.split('/')[:-1])) diff --git a/swh/web/tests/browse/views/data/origin_test_data.py b/swh/web/tests/browse/views/data/origin_test_data.py index 54340ec5..25527a0b 100644 --- a/swh/web/tests/browse/views/data/origin_test_data.py +++ b/swh/web/tests/browse/views/data/origin_test_data.py @@ -1,754 +1,761 @@ # Copyright (C) 2017 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information # flake8: noqa origin_info_test_data = { - 'id': 2, - 'type': 'git', + 'id': 2, + 'type': 'git', 'url': 'https://github.com/torvalds/linux' } origin_visits_test_data = [ {'date': '2015-07-09T21:09:24+00:00', 'metadata': {}, 'origin': 2, 'status': 'full', 'visit': 1}, {'date': '2016-02-23T18:05:23.312045+00:00', 'metadata': {}, 'origin': 2, 'status': 'full', 'visit': 2}, {'date': '2016-03-28T01:35:06.554111+00:00', 'metadata': {}, 'origin': 2, 'status': 'full', 'visit': 3}, {'date': '2016-06-18T01:22:24.808485+00:00', 'metadata': {}, 'origin': 2, 'status': 'full', 'visit': 4}, {'date': '2016-08-14T12:10:00.536702+00:00', 'metadata': {}, 'origin': 2, 'status': 'full', 'visit': 5}, {'date': '2016-08-17T09:16:22.052065+00:00', 'metadata': {}, 'origin': 2, 'status': 'full', 'visit': 6}, {'date': '2016-08-29T18:55:54.153721+00:00', 'metadata': {}, 'origin': 2, 'status': 'full', 'visit': 7}, {'date': '2016-09-07T08:44:47.861875+00:00', 'metadata': {}, 'origin': 2, 'status': 'full', 'visit': 8}, {'date': '2016-09-14T10:36:21.505296+00:00', 'metadata': {}, 'origin': 2, 'status': 'full', 'visit': 9}, {'date': '2016-09-23T10:14:02.169862+00:00', 'metadata': {}, 'origin': 2, 'status': 'full', 'visit': 10}, {'date': '2017-02-16T07:53:39.467657+00:00', 'metadata': {}, 'origin': 2, 'status': 'partial', 'visit': 11}, {'date': '2017-05-04T19:40:09.336451+00:00', 'metadata': {}, 'origin': 2, 'status': 'full', 'visit': 12}, {'date': '2017-09-07T18:43:13.021746+00:00', 'metadata': {}, 'origin': 2, 'status': 'full', 'visit': 13}, {'date': '2017-09-09T05:14:33.466107+00:00', 'metadata': {}, 'origin': 2, 'status': 'full', 'visit': 14}, {'date': '2017-09-09T17:18:54.307789+00:00', 'metadata': {}, 'origin': 2, 'status': 'full', 'visit': 15}, {'date': '2017-09-10T05:29:01.462971+00:00', 'metadata': {}, 'origin': 2, 'status': 'full', 'visit': 16}, {'date': '2017-09-10T17:35:20.158515+00:00', 'metadata': {}, 'origin': 2, 'status': 'full', 'visit': 17}, {'date': '2017-09-11T05:49:58.300518+00:00', 'metadata': {}, 'origin': 2, 'status': 'full', 'visit': 18}, {'date': '2017-09-11T18:00:15.037345+00:00', 'metadata': {}, 'origin': 2, 'status': 'full', 'visit': 19}, {'date': '2017-09-12T06:06:34.703343+00:00', 'metadata': {}, 'origin': 2, 'status': 'full', 'visit': 20}, {'date': '2017-09-12T18:12:35.344511+00:00', 'metadata': {}, 'origin': 2, 'status': 'full', 'visit': 21}, {'date': '2017-09-13T06:26:36.580675+00:00', 'metadata': {}, 'origin': 2, 'status': 'full', 'visit': 22} ] -stub_origin_id = 7416001 +stub_origin_info = { + 'id': 7416001, + 'type': 'git', + 'url': 'https://github.com/webpack/webpack' +} stub_visit_id = 10 stub_visit_unix_ts = 1493909263 stub_visit_iso_date = '2017-05-04T14:47:43+00:00' stub_origin_visits = [ {'date': '2015-08-05T18:55:20.899865+00:00', 'metadata': {}, 'origin': 7416001, 'status': 'full', 'visit': 1}, {'date': '2016-03-06T12:16:26.240919+00:00', 'metadata': {}, 'origin': 7416001, 'status': 'full', 'visit': 2}, {'date': '2016-03-21T11:40:10.329221+00:00', 'metadata': {}, 'origin': 7416001, 'status': 'full', 'visit': 3}, {'date': '2016-03-29T08:05:17.602649+00:00', 'metadata': {}, 'origin': 7416001, 'status': 'full', 'visit': 4}, {'date': '2016-07-26T20:11:03.827577+00:00', 'metadata': {}, 'origin': 7416001, 'status': 'full', 'visit': 5}, {'date': '2016-08-13T04:10:22.142897+00:00', 'metadata': {}, 'origin': 7416001, 'status': 'full', 'visit': 6}, {'date': '2016-08-16T22:57:46.201737+00:00', 'metadata': {}, 'origin': 7416001, 'status': 'full', 'visit': 7}, {'date': '2016-08-17T17:58:43.346437+00:00', 'metadata': {}, 'origin': 7416001, 'status': 'full', 'visit': 8}, {'date': '2016-08-29T23:29:09.445945+00:00', 'metadata': {}, 'origin': 7416001, 'status': 'full', 'visit': 9}, {'date': '2016-09-07T13:49:15.096109+00:00', 'metadata': {}, 'origin': 7416001, 'status': 'full', 'visit': 10}, {'date': '2016-09-14T15:01:09.017257+00:00', 'metadata': {}, 'origin': 7416001, 'status': 'full', 'visit': 11}, {'date': '2016-09-23T12:29:15.921727+00:00', 'metadata': {}, 'origin': 7416001, 'status': 'full', 'visit': 12}, {'date': '2017-02-16T07:44:23.302439+00:00', 'metadata': {}, 'origin': 7416001, 'status': 'partial', 'visit': 13}, {'date': '2017-05-04T14:47:43.228455+00:00', 'metadata': {}, 'origin': 7416001, 'status': 'full', 'visit': 14} ] stub_origin_branches = [ {'directory': 'ae59ceecf46367e8e4ad800e231fc76adc3afffb', 'name': 'HEAD', 'revision': '7bc08e1aa0b08cb23e18715a32aa38517ad34672'}, {'directory': 'c47a824f95109ca7cafdd1c3206332a0d10df55d', 'name': 'refs/heads/0.10', 'revision': 'f944553c77254732c4ce22c0add32aa1f641959d'}, {'directory': '45e31184ebb7699cd74175145c7eb11cce3f085e', 'name': 'refs/heads/0.11', 'revision': '0a29109a6e4579926ebc9b03a6301c61861cce62'}, {'directory': '42346b33e2d16019490c273ff586ee88817327b3', 'name': 'refs/heads/0.8', 'revision': 'e42701dc6f9b035bfbb5d0fffded905d8b456db4'}, {'directory': '828c7e9385523f852f8d4dac3cb241e319a9ce61', 'name': 'refs/heads/0.9', 'revision': '6c3f51e6d9491a2463ad099a2ca49255ec83ff00'}, {'directory': '2c50e78d63bdc4441c8d2691f5729b04f0ab3ecd', 'name': 'refs/heads/1.0', 'revision': 'fb7958d172e1ef6fb77f23bf56818ad24e896e5c'}, {'directory': '31a3355c4d0a464aa311c5fa11c7f8b20aede6b4', 'name': 'refs/heads/IgnorePluginHotfix', 'revision': 'fdc922a2fa007e71b7ec07252012ffab9a178d4a'}, {'directory': 'e566db1fc65cb61b3799c6e0f0ad06b2406f095f', 'name': 'refs/heads/beta', 'revision': '40428853da5d9ce6a8751e13b5e54145337b6a7e'}, {'directory': '0f3cf363d4184a2cc36fdbebe1657d40fad6a591', 'name': 'refs/heads/break/add-timeout', 'revision': '14c43e0cc54af67344f8304708ccdd7b8ab91110'}, {'directory': '8dc14b0625b2280d630aeae9dd424054c37db820', 'name': 'refs/heads/bugfix/child-records-cache', 'revision': '101850c5a90dbc51f1a95813fe1fece42bc1b9dc'}, {'directory': '08c703fdf5cdb4f9321a1e1ad616eeeb78c96670', 'name': 'refs/heads/bugfix/disable-module-in-harmony', 'revision': 'bebe688e6cd0cfe35b967069ddfe1ca42a83f99b'}, {'directory': '2378f4c463a54f057e42b2e489cd641645f82517', 'name': 'refs/heads/bugfix/dll-extension', 'revision': '38264a092e130b83bfe521e6e35a3b3e7600f183'}, {'directory': 'def1489e00e12ed6ed2515c782da4ed29bf7a2dc', 'name': 'refs/heads/bugfix/order', 'revision': '089356faa3d27c1ef4d5c9eee1c235bc8ea505ea'}, {'directory': 'fe1f7ebe60b771b6494be316fc01c305e0ba5c3c', 'name': 'refs/heads/bugfix/status', 'revision': '206ef6d079515a57fbca113cbdcb53cec3def4d6'}, {'directory': '4cb66b94d3f2438fc095271f7184ca643ce1cdc4', 'name': 'refs/heads/ci/bench', 'revision': '21af9e96908e62616eaf04337dfc1b69630765d9'}, {'directory': 'c1aff7c49f9a38edb1d2e037cc401a9f9e2366ff', 'name': 'refs/heads/dep/dependency-update', 'revision': '0bb4b14118ce8ce745222c89c75c166f219a6193'}, {'directory': 'b4db55e82f9d7b7a9ebc8ce6a2b511d86efb3012', 'name': 'refs/heads/feature/emoji_presets_to_options', 'revision': 'a6ebd61bb967d66e1573562f58b2d36893cf338d'}, {'directory': '676474786d3e6334f1a71bf49adb1e53b0681d34', 'name': 'refs/heads/feature/fix_errors_only_bug', 'revision': '5dd1d0cb130032fe176e70b770c38e7df3d804d2'}, {'directory': '8c8576394828f016d7981e10199ba7a4dee58cf8', 'name': 'refs/heads/feature/fix_watch_test_cases_timeout_for_caching_harmony', 'revision': 'd507632afaa4ec2257601e58e17b455ab2491a58'}, {'directory': 'b1968bb5bbbd604ef52b10668b04869f5790f7c2', 'name': 'refs/heads/feature/jsonp-to-push', 'revision': 'cc26df3dd65062d19fca6268adb866dbf9ec0d8e'}, {'directory': '2a13a1b4e098680cfc4a3a9a103873a0fce232c4', 'name': 'refs/heads/feature/postinstall-autolink', 'revision': '7d4e0b72491819e51e84a8747ebcb07bebcf0f6a'}, {'directory': '27226447d3a8e6de4dec3878eac3617f922b358c', 'name': 'refs/heads/feature/travis_yarn_command', 'revision': 'd370967ac8874214023aa69a22c120d4a0cbdef9'}, {'directory': '4bd9839b5ade32398ff62a7aced9a32cf89981d0', 'name': 'refs/heads/feature/webpack_analytics', 'revision': 'a3461fdc6232bef3e4df3bab5079ab5323df1216'}, {'directory': '1d427c810ab43e1abfdda73a09af41ea4e314a9f', 'name': 'refs/heads/feature/webpack_options_apply_coverage_increase', 'revision': 'b92f3fd3ab21959fcdfe492fb927c70014f16def'}, {'directory': 'fe6b88dd54f3c1043d32e8af812655ea9b8ba000', 'name': 'refs/heads/fix/node_modules_mangle', 'revision': '26f79f5b30ba51afae6219ba53bf52be138c2fd3'}, {'directory': 'b01142c405b9dba0d73dd8232a310ec469c89379', 'name': 'refs/heads/inline', 'revision': '427798d4f0e6b72ca3ecb4bfe849b3a17de08729'}, {'directory': 'ae59ceecf46367e8e4ad800e231fc76adc3afffb', 'name': 'refs/heads/master', 'revision': '7bc08e1aa0b08cb23e18715a32aa38517ad34672'}, {'directory': '63fe66a1ecbb35be33f617f96080a78463f89948', 'name': 'refs/heads/perf/chunks-set', 'revision': 'f6f22ef0a733931e217050ad9c3b95265978a556'}, {'directory': '6b813dd7a42991507ef11bc347d53a28340f563c', 'name': 'refs/heads/perf/modules-set', 'revision': 'df44599731b4b1d185b20ccd36e9d37d817ad8c2'}, {'directory': '29cf488a00126c0e45c78b92f97cdbc733f4d07e', 'name': 'refs/heads/test/circleci', 'revision': '0f91f949e2d41ef5cb92493bcc6c1fa7578ac27d'}, {'directory': 'ea3a49842790b4eb8c3805a3318d8ade15cea6c8', 'name': 'refs/heads/test/dependency-upgrade', 'revision': 'c6265492ec886405256e23b9fe4de6dfd1e39c49'}, {'directory': '4de09be1628ed81def03f78d8d832c93efdf0af4', 'name': 'refs/heads/test/move-entry', 'revision': 'a244879a07e04e6b5951520ca3cd80c3ef160f8e'}, {'directory': '0fa77c20564364056319570bd46607111c97cb42', 'name': 'refs/heads/webpack-1', 'revision': 'd4878a55be7a4b7ac4e5db1ae5eef89e15811072'} ] stub_origin_master_branch = 'HEAD' stub_origin_root_directory_sha1 = 'ae59ceecf46367e8e4ad800e231fc76adc3afffb' stub_origin_root_directory_entries = [ {'checksums': {'sha1': '1a17dd2c8245559b43a90aa7c084572e917effff', 'sha1_git': '012966bd94e648f23b53e71a3f9918e28abc5d81', 'sha256': 'd65ab1f8cdb323e2b568a8e99814b1b986a38beed85a380981b383c0feb93525'}, 'dir_id': 'ae59ceecf46367e8e4ad800e231fc76adc3afffb', 'length': 394, 'name': '.editorconfig', 'perms': 33188, 'status': 'visible', 'target': '012966bd94e648f23b53e71a3f9918e28abc5d81', 'type': 'file'}, {'checksums': {'sha1': '2e727ec452dc592ae6038d3e09cd35d83d7ea265', 'sha1_git': '291a4e25598633cd7c286ad8d6cbe9eee5a6291a', 'sha256': 'd5951c8b796288e0dae1da50575d1b8619462a8df2272cd250146872a1fe804a'}, 'dir_id': 'ae59ceecf46367e8e4ad800e231fc76adc3afffb', 'length': 1839, 'name': '.eslintrc.js', 'perms': 33188, 'status': 'visible', 'target': '291a4e25598633cd7c286ad8d6cbe9eee5a6291a', 'type': 'file'}, {'checksums': {'sha1': '5c59880c0576b2789ec126b61b09fad7a982763b', 'sha1_git': 'ac579eb7bc04ba44fe84f3c8d1082573e9f4f514', 'sha256': '8a59a61ff6c0f568a8f76bab434baf3318c80a75ef6fb1b6eb861a0c97518de0'}, 'dir_id': 'ae59ceecf46367e8e4ad800e231fc76adc3afffb', 'length': 67, 'name': '.gitattributes', 'perms': 33188, 'status': 'visible', 'target': 'ac579eb7bc04ba44fe84f3c8d1082573e9f4f514', 'type': 'file'}, {'dir_id': 'ae59ceecf46367e8e4ad800e231fc76adc3afffb', 'length': None, 'name': '.github', 'perms': 16384, 'target': '93bdcf98e9c05307b39a9d9e00e48cda6dbd036c', 'type': 'dir'}, {'checksums': {'sha1': '7e1008eee2a373f0db7746d0416856aec6b95c22', 'sha1_git': '84bc35a3abab38bdf87a8f32cc82ce9c136d331e', 'sha256': '7de369f1d26bc34c7b6329de78973db07e341320eace6a8704a65d4c5bf5993f'}, 'dir_id': 'ae59ceecf46367e8e4ad800e231fc76adc3afffb', 'length': 167, 'name': '.gitignore', 'perms': 33188, 'status': 'visible', 'target': '84bc35a3abab38bdf87a8f32cc82ce9c136d331e', 'type': 'file'}, {'checksums': {'sha1': '06d96508b7d343ff42868f9b6406864517935da7', 'sha1_git': '79b049846744a2da3eb1c4ac3b01543f2bdca44a', 'sha256': '697733061d96dd2e061df04dcd86392bb792e2dbe5725a6cb14a436d3c8b76f1'}, 'dir_id': 'ae59ceecf46367e8e4ad800e231fc76adc3afffb', 'length': 706, 'name': '.jsbeautifyrc', 'perms': 33188, 'status': 'visible', 'target': '79b049846744a2da3eb1c4ac3b01543f2bdca44a', 'type': 'file'}, {'checksums': {'sha1': '8041a4a66f46e615c99a850700850a8bd1079dce', 'sha1_git': '90e4f1ef5beb167891b2e029da6eb9b14ab17add', 'sha256': '3d6a76a57351b9e3acc5843ff2127dc2cf70c023133312143f86ee74ba9ef6d3'}, 'dir_id': 'ae59ceecf46367e8e4ad800e231fc76adc3afffb', 'length': 1059, 'name': '.travis.yml', 'perms': 33188, 'status': 'visible', 'target': '90e4f1ef5beb167891b2e029da6eb9b14ab17add', 'type': 'file'}, {'checksums': {'sha1': 'cd52973e43c6f4294e8cdfd3106df602b9993f20', 'sha1_git': 'e5279ebcecd87445648d003c36e6abfebed0ed73', 'sha256': '130672b16dff61b1541b6d26c2e568ac11830a31d04faace1583d3ad4a38720e'}, 'dir_id': 'ae59ceecf46367e8e4ad800e231fc76adc3afffb', 'length': 2058, 'name': 'CONTRIBUTING.md', 'perms': 33188, 'status': 'visible', 'target': 'e5279ebcecd87445648d003c36e6abfebed0ed73', 'type': 'file'}, {'checksums': {'sha1': '3bebb9ba92e45dd02a0512e144f6a46b14a9b8ab', 'sha1_git': '8c11fc7289b75463fe07534fcc8224e333feb7ff', 'sha256': '9068a8782d2fb4c6e432cfa25334efa56f722822180570802bf86e71b6003b1e'}, 'dir_id': 'ae59ceecf46367e8e4ad800e231fc76adc3afffb', 'length': 1071, 'name': 'LICENSE', 'perms': 33188, 'status': 'visible', 'target': '8c11fc7289b75463fe07534fcc8224e333feb7ff', 'type': 'file'}, {'checksums': {'sha1': '6892825420196e84c7104a7ff71ec75db20a1fca', 'sha1_git': '8f96a0a6d3bfe7183765938483585f3981151553', 'sha256': 'b0170cfc28f56ca718b43ab086ca5428f853268687c8c033b4fbf028c66d663e'}, 'dir_id': 'ae59ceecf46367e8e4ad800e231fc76adc3afffb', 'length': 46700, 'name': 'README.md', 'perms': 33188, 'status': 'visible', 'target': '8f96a0a6d3bfe7183765938483585f3981151553', 'type': 'file'}, {'checksums': {'sha1': '9bc4902b282f9f1c9f8f885a6947f3bf0f6e6e5f', 'sha1_git': 'dd6912c8fc97eff255d64da84cfd9837ebf0a05a', 'sha256': 'e06dbc101195ec7ea0b9aa236be4bdc03784a01f64d6e11846ce3a3f6e1080c6'}, 'dir_id': 'ae59ceecf46367e8e4ad800e231fc76adc3afffb', 'length': 590, 'name': 'appveyor.yml', 'perms': 33188, 'status': 'visible', 'target': 'dd6912c8fc97eff255d64da84cfd9837ebf0a05a', 'type': 'file'}, {'dir_id': 'ae59ceecf46367e8e4ad800e231fc76adc3afffb', 'length': None, 'name': 'benchmark', 'perms': 16384, 'target': '6bd2996b76e051982aa86499a2b485594e607fe3', 'type': 'dir'}, {'dir_id': 'ae59ceecf46367e8e4ad800e231fc76adc3afffb', 'length': None, 'name': 'bin', 'perms': 16384, 'target': '681da97ea1ce9a2bd29e3e72781d80e8b961cd51', 'type': 'dir'}, {'dir_id': 'ae59ceecf46367e8e4ad800e231fc76adc3afffb', 'length': None, 'name': 'buildin', 'perms': 16384, 'target': '35cfb25d1b3a4063bf04a43f9cbb7e1e87703708', 'type': 'dir'}, {'dir_id': 'ae59ceecf46367e8e4ad800e231fc76adc3afffb', 'length': None, 'name': 'ci', 'perms': 16384, 'target': 'efccd3ce0a0304c8cbcffcfdfcafcf1e598819b8', 'type': 'dir'}, {'checksums': {'sha1': '9eb3d0e3711f68f82d29785e64ebff2c0d7cec7a', 'sha1_git': '1ecf877e445bcf865ef53cfcecadda7e9691aace', 'sha256': '2007e0883c2784bb82584a10d53a0f0c36286dd913741bfd5e4d22b812db529c'}, 'dir_id': 'ae59ceecf46367e8e4ad800e231fc76adc3afffb', 'length': 529, 'name': 'circle.yml', 'perms': 33188, 'status': 'visible', 'target': '1ecf877e445bcf865ef53cfcecadda7e9691aace', 'type': 'file'}, {'checksums': {'sha1': '63209428718e101492c3bb91509f1b4e319b0d7d', 'sha1_git': 'b3fa4e6abe22977e6267e9969a593e790bf2cd36', 'sha256': '5d14c8d70215f46a9722d29c7ebff8cc9bd24509650d7ee601fd461e52a52f7f'}, 'dir_id': 'ae59ceecf46367e8e4ad800e231fc76adc3afffb', 'length': 254, 'name': 'codecov.yml', 'perms': 33188, 'status': 'visible', 'target': 'b3fa4e6abe22977e6267e9969a593e790bf2cd36', 'type': 'file'}, {'dir_id': 'ae59ceecf46367e8e4ad800e231fc76adc3afffb', 'length': None, 'name': 'examples', 'perms': 16384, 'target': '7e3ac01795317fbc36a031a9117e7963d6c7da90', 'type': 'dir'}, {'dir_id': 'ae59ceecf46367e8e4ad800e231fc76adc3afffb', 'length': None, 'name': 'hot', 'perms': 16384, 'target': 'a5eea6ca952fba9f7ae4177627ed5e22754df9f5', 'type': 'dir'}, {'checksums': {'sha1': '92d9367db4ba049f698f5bf78b6946b8e2d91345', 'sha1_git': 'eaa9cc4a247b01d6a9c0adc91997fefe6a62be1f', 'sha256': 'd4b42fa0651cf3d99dea0ca5bd6ba64cc21e80be7d9ea05b2b4423ef8f16ec36'}, 'dir_id': 'ae59ceecf46367e8e4ad800e231fc76adc3afffb', 'length': 19, 'name': 'input.js', 'perms': 33188, 'status': 'visible', 'target': 'eaa9cc4a247b01d6a9c0adc91997fefe6a62be1f', 'type': 'file'}, {'dir_id': 'ae59ceecf46367e8e4ad800e231fc76adc3afffb', 'length': None, 'name': 'lib', 'perms': 16384, 'target': '187d40104aa21475d8af88ccd77fc582cf6ac7a6', 'type': 'dir'}, {'checksums': {'sha1': 'f17ffa2dc14262292e2275efa3730a96fe060c44', 'sha1_git': 'd55b7110929cbba3d94da01494a272b39878ac0f', 'sha256': '012d4446ef8ab6656251b1b7f8e0217a5666ec04ad952e8a617b70946de17166'}, 'dir_id': 'ae59ceecf46367e8e4ad800e231fc76adc3afffb', 'length': 9132, 'name': 'open-bot.yaml', 'perms': 33188, 'status': 'visible', 'target': 'd55b7110929cbba3d94da01494a272b39878ac0f', 'type': 'file'}, {'checksums': {'sha1': '3a6638e72fcc2499f1a4c9b46d4d00d239bbe1c8', 'sha1_git': '6d1aa82c90ecd184d136151eb81d240e1fea723e', 'sha256': '00faf7dde1eb0742f3ca567af4dbcd8c01a38cf30d8faa7f0208f46dbc6b5201'}, 'dir_id': 'ae59ceecf46367e8e4ad800e231fc76adc3afffb', 'length': 4034, 'name': 'package.json', 'perms': 33188, 'status': 'visible', 'target': '6d1aa82c90ecd184d136151eb81d240e1fea723e', 'type': 'file'}, {'dir_id': 'ae59ceecf46367e8e4ad800e231fc76adc3afffb', 'length': None, 'name': 'schemas', 'perms': 16384, 'target': 'f1f89c389f73c29e7a5d1a0ce5f9e0f166857815', 'type': 'dir'}, {'dir_id': 'ae59ceecf46367e8e4ad800e231fc76adc3afffb', 'length': None, 'name': 'test', 'perms': 16384, 'target': '318c279189d186a1e06653fc5c78c539878c4d7d', 'type': 'dir'}, {'dir_id': 'ae59ceecf46367e8e4ad800e231fc76adc3afffb', 'length': None, 'name': 'web_modules', 'perms': 16384, 'target': '93a5cc8e492d0b0323386814a72536381019ef7b', 'type': 'dir'}, {'checksums': {'sha1': '8047389fcc8e286ceed5536c677c2e803032cf84', 'sha1_git': 'eb8509f70158c231a3fd864aecf2649590bbedf3', 'sha256': '8cbe1ce94349ac3bc6cbcc952efd45d838c6b4524af8a773b18e1ebe8b4f936b'}, 'dir_id': 'ae59ceecf46367e8e4ad800e231fc76adc3afffb', 'length': 141192, 'name': 'yarn.lock', 'perms': 33188, 'status': 'visible', 'target': 'eb8509f70158c231a3fd864aecf2649590bbedf3', 'type': 'file'} ] stub_origin_sub_directory_path = 'lib/webworker' stub_origin_sub_directory_entries = [ {'checksums': {'sha1': '7bf366cd9f4a9835c73aafb70e44f640bab7ad16', 'sha1_git': '870252b7a175ee5ec2edfe2c22b2d56aa04bece4', 'sha256': 'e0af438932627dd9d53b36bfe69c3dbad6dc4d4569f6cdb29d606c9df2b128fa'}, 'dir_id': '02b626051e0935ecd28f50337f452db76803f980', 'length': 921, 'name': 'WebWorkerChunkTemplatePlugin.js', 'perms': 33188, 'status': 'visible', 'target': '870252b7a175ee5ec2edfe2c22b2d56aa04bece4', 'type': 'file'}, {'checksums': {'sha1': 'e2862b2787702bd3eb856f73627d5d8df5a8b550', 'sha1_git': 'b3e90d26a68ad9da0a7cc97a262db585fa4c73ba', 'sha256': '1c254e76248ff5ec7e2185cdb1cfd2e0338087244d2d617a868c346317b7646b'}, 'dir_id': '02b626051e0935ecd28f50337f452db76803f980', 'length': 1039, 'name': 'WebWorkerHotUpdateChunkTemplatePlugin.js', 'perms': 33188, 'status': 'visible', 'target': 'b3e90d26a68ad9da0a7cc97a262db585fa4c73ba', 'type': 'file'}, {'checksums': {'sha1': 'a1e04061d3e50bb8c024b07e9464da7392f37bf1', 'sha1_git': '1e503e028fdd5322c9f7d8ec50f54006cacf334e', 'sha256': '72dea06510d1a4435346f8dca20d8898a394c52c7382a97bd73d1840e31f90b3'}, 'dir_id': '02b626051e0935ecd28f50337f452db76803f980', 'length': 1888, 'name': 'WebWorkerMainTemplate.runtime.js', 'perms': 33188, 'status': 'visible', 'target': '1e503e028fdd5322c9f7d8ec50f54006cacf334e', 'type': 'file'}, {'checksums': {'sha1': 'b95c16e90784cf7025352839133b482149526da0', 'sha1_git': '46c9fe382d606ce19e556deeae6a23af47a8027d', 'sha256': 'c78c7ca9ee0aa341f843a431ef27c75c386607be3037d44ff530bfe3218edb3c'}, 'dir_id': '02b626051e0935ecd28f50337f452db76803f980', 'length': 4051, 'name': 'WebWorkerMainTemplatePlugin.js', 'perms': 33188, 'status': 'visible', 'target': '46c9fe382d606ce19e556deeae6a23af47a8027d', 'type': 'file'}, {'checksums': {'sha1': 'ec9df36b1e8dd689d84dbeeeb9f45fe9f9d96605', 'sha1_git': 'd850018bb0d2ad41dd0ae9e5c887dff8a23601e9', 'sha256': 'f995f6a13511955244850c2344c6cef09c10ab24c49f8448544e2b34aa69d03c'}, 'dir_id': '02b626051e0935ecd28f50337f452db76803f980', 'length': 763, 'name': 'WebWorkerTemplatePlugin.js', 'perms': 33188, 'status': 'visible', 'target': 'd850018bb0d2ad41dd0ae9e5c887dff8a23601e9', 'type': 'file'} ] -stub_content_origin_id = 10357753 +stub_content_origin_info = { + 'id': 10357753, + 'type': 'git', + 'url': 'https://github.com/KDE/kate' +} stub_content_origin_visit_id = 10 - stub_content_origin_visit_unix_ts = 1494032350 stub_content_origin_visit_iso_date = '2017-05-06T00:59:10+00:00' stub_content_origin_branch = 'HEAD' stub_content_origin_visits = [ {'date': '2015-09-26T09:30:52.373449+00:00', 'metadata': {}, 'origin': 10357753, 'status': 'full', 'visit': 1}, {'date': '2016-03-10T05:36:11.118989+00:00', 'metadata': {}, 'origin': 10357753, 'status': 'full', 'visit': 2}, {'date': '2016-03-24T07:39:29.727793+00:00', 'metadata': {}, 'origin': 10357753, 'status': 'full', 'visit': 3}, {'date': '2016-03-31T22:55:31.402863+00:00', 'metadata': {}, 'origin': 10357753, 'status': 'full', 'visit': 4}, {'date': '2016-05-26T06:25:54.879676+00:00', 'metadata': {}, 'origin': 10357753, 'status': 'full', 'visit': 5}, {'date': '2016-06-07T17:16:33.964164+00:00', 'metadata': {}, 'origin': 10357753, 'status': 'full', 'visit': 6}, {'date': '2016-07-27T01:38:20.345358+00:00', 'metadata': {}, 'origin': 10357753, 'status': 'full', 'visit': 7}, {'date': '2016-08-13T04:46:45.987508+00:00', 'metadata': {}, 'origin': 10357753, 'status': 'full', 'visit': 8}, {'date': '2016-08-16T23:24:13.214496+00:00', 'metadata': {}, 'origin': 10357753, 'status': 'full', 'visit': 9}, {'date': '2016-08-17T18:10:39.841005+00:00', 'metadata': {}, 'origin': 10357753, 'status': 'full', 'visit': 10}, {'date': '2016-08-30T17:28:02.476486+00:00', 'metadata': {}, 'origin': 10357753, 'status': 'full', 'visit': 11}, {'date': '2016-09-08T09:32:37.152054+00:00', 'metadata': {}, 'origin': 10357753, 'status': 'full', 'visit': 12}, {'date': '2016-09-15T09:47:37.758093+00:00', 'metadata': {}, 'origin': 10357753, 'status': 'full', 'visit': 13}, {'date': '2016-12-04T06:14:02.688518+00:00', 'metadata': {}, 'origin': 10357753, 'status': 'full', 'visit': 14}, {'date': '2017-02-16T08:45:57.719974+00:00', 'metadata': {}, 'origin': 10357753, 'status': 'partial', 'visit': 15}, {'date': '2017-05-06T00:59:10.495727+00:00', 'metadata': {}, 'origin': 10357753, 'status': 'full', 'visit': 16} ] stub_content_origin_branches = [ {'directory': '08e8329257dad3a3ef7adea48aa6e576cd82de5b', 'name': 'HEAD', 'revision': '11f15b0789344427ddf17b8d75f38577c4395ce0'}, {'directory': '2371baf0411e3adf12d65daf86c3b135633dd5e4', 'name': 'refs/heads/Applications/14.12', 'revision': '5b27ad32f8c8da9b6fc898186d59079488fb74c9'}, {'directory': '5d024d33a218eeb164936301a2f89231d1f0854a', 'name': 'refs/heads/Applications/15.04', 'revision': '4f1e29120795ac643044991e91f24d02c9980202'}, {'directory': 'f33984df50ec29dbbc86295adb81ebb831e3b86d', 'name': 'refs/heads/Applications/15.08', 'revision': '52722e588f46a32b480b5f304ba21480fc8234b1'}, {'directory': 'e706b836cf32929a48b6f92c07766f237f9d068f', 'name': 'refs/heads/Applications/15.12', 'revision': '38c4e42c4a653453fc668c704bb8995ae31b5baf'}, {'directory': 'ebf8ae783b44df5c827bfa46227e5dbe98f25eb4', 'name': 'refs/heads/Applications/16.04', 'revision': 'd0fce3b880ab37a551d75ec940137e0f46bf2143'}, {'directory': '68ea0543fa80cc512d969fc2294d391a904e04fa', 'name': 'refs/heads/Applications/16.08', 'revision': '0b05000bfdde06aec2dc6528411ec24c9e20e672'}, {'directory': 'b9481c652d57b2e0e36c63f2bf795bc6ffa0b6a1', 'name': 'refs/heads/Applications/16.12', 'revision': '2a52ca09fce28e29f5afd0ba4622635679036837'}, {'directory': '415ea4716870c59feabde3210da6f60bcf897479', 'name': 'refs/heads/Applications/17.04', 'revision': 'c7ba6cef1ebfdb743e4f3f53f51f44917981524a'}, {'directory': 'a9d27a5cd354f2f1e50304ef72818141231f7876', 'name': 'refs/heads/KDE/4.10', 'revision': 'e0bc3d8ab537d06c817c459f0be7c7f21d670b6e'}, {'directory': 'a273331f42e6998099ac98934f33431eb244b222', 'name': 'refs/heads/KDE/4.11', 'revision': 'e9db108b584aabe88eff1969f408146b0b9eac32'}, {'directory': '00be5902593157c55a9888b9e5c17c3b416d1f89', 'name': 'refs/heads/KDE/4.12', 'revision': 'c2a1c24f28613342985aa40573fb922370900a3a'}, {'directory': 'f25aa509cc4ad99478a71407850575d267ae4106', 'name': 'refs/heads/KDE/4.13', 'revision': 'b739b7a67882408b4378d901c38b2c88108f1312'}, {'directory': 'e39f1a6967c33635c9e0c3ee627fbd987612417b', 'name': 'refs/heads/KDE/4.14', 'revision': 'dd6530d110b165dfeed8dc1b20b8cfab0e4bd25b'}, {'directory': '5ac8842a402fe3136be5e2ddd31cb24232152994', 'name': 'refs/heads/KDE/4.7', 'revision': '776b581f5f724b1179f2fe013c2da835bb0d5cfc'}, {'directory': '1e6d88a64ecfa70a6883efd977bfd6248344b108', 'name': 'refs/heads/KDE/4.8', 'revision': 'fe3723f6ab789ecf21864e198c91092d10a5289b'}, {'directory': 'aa03927b4d5738c67646509b4b5d55faef03f024', 'name': 'refs/heads/KDE/4.9', 'revision': '69121e434e25f8f4c8ee92a1771a8e87913b3559'}, {'directory': '57844f10b9ade482ece88ae07a406570e5c0b35d', 'name': 'refs/heads/goinnn-kate-plugins', 'revision': 'f51e7810338fe5648319a88712d0ce560cc5f847'}, {'directory': 'eed636cada058599df292eb59180896cd8aeceac', 'name': 'refs/heads/kfunk/fix-katecompletionmodel', 'revision': 'dbf7cae67c5db0737fcf37235000b867cd839f3e'}, {'directory': '08e8329257dad3a3ef7adea48aa6e576cd82de5b', 'name': 'refs/heads/master', 'revision': '11f15b0789344427ddf17b8d75f38577c4395ce0'}, {'directory': '7b5bdcb46cfaa25229af6b038190b004a26397ff', 'name': 'refs/heads/plasma/sreich/declarative-kate-applet', 'revision': '51ab3ea145abd3219c3fae06ff99fa911a6a8993'}, {'directory': 'e39f1a6967c33635c9e0c3ee627fbd987612417b', 'name': 'refs/pull/1/head', 'revision': 'dd6530d110b165dfeed8dc1b20b8cfab0e4bd25b'} ] \ No newline at end of file diff --git a/swh/web/tests/browse/views/test_origin.py b/swh/web/tests/browse/views/test_origin.py index 966390b1..6575cb49 100644 --- a/swh/web/tests/browse/views/test_origin.py +++ b/swh/web/tests/browse/views/test_origin.py @@ -1,509 +1,536 @@ # Copyright (C) 2017 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information +# flake8: noqa + from unittest.mock import patch from nose.tools import istest, nottest from django.test import TestCase from django.utils.html import escape from swh.web.common.exc import NotFoundExc -from swh.web.common.utils import reverse, gen_path_info +from swh.web.common.utils import ( + reverse, gen_path_info, format_utc_iso_date, + parse_timestamp +) from swh.web.tests.testbase import SWHWebTestBase from .data.origin_test_data import ( origin_info_test_data, origin_visits_test_data, - stub_content_origin_id, stub_content_origin_visit_id, + stub_content_origin_info, stub_content_origin_visit_id, stub_content_origin_visit_unix_ts, stub_content_origin_visit_iso_date, stub_content_origin_branch, stub_content_origin_visits, stub_content_origin_branches, - stub_origin_id, stub_visit_id, + stub_origin_info, stub_visit_id, stub_origin_visits, stub_origin_branches, stub_origin_root_directory_entries, stub_origin_master_branch, stub_origin_root_directory_sha1, stub_origin_sub_directory_path, stub_origin_sub_directory_entries, stub_visit_unix_ts, stub_visit_iso_date ) from .data.content_test_data import ( stub_content_root_dir, stub_content_text_data, stub_content_text_path ) class SwhBrowseOriginTest(SWHWebTestBase, TestCase): @patch('swh.web.browse.views.origin.get_origin_visits') @patch('swh.web.browse.views.origin.service') @istest def origin_browse(self, mock_service, mock_get_origin_visits): mock_service.lookup_origin.return_value = origin_info_test_data mock_get_origin_visits.return_value = origin_visits_test_data url = reverse('browse-origin', - kwargs={'origin_id': origin_info_test_data['id']}) + kwargs={'origin_type': origin_info_test_data['type'], + 'origin_url': origin_info_test_data['url']}) resp = self.client.get(url) self.assertEquals(resp.status_code, 200) self.assertTemplateUsed('origin.html') self.assertContains(resp, '%s' % origin_info_test_data['id']) - self.assertContains(resp, '
%s
' % origin_info_test_data['type']) # noqa + self.assertContains(resp, '
%s
' % origin_info_test_data['type']) self.assertContains(resp, '
%s
' % (origin_info_test_data['url'], origin_info_test_data['url'])) self.assertContains(resp, '', count=len(origin_visits_test_data)) for visit in origin_visits_test_data: + visit_date = format_utc_iso_date(visit['date'], '%Y-%m-%dT%H:%M:%S') browse_url = reverse('browse-origin-directory', - kwargs={'origin_id': visit['origin'], - 'visit_id': visit['visit']}) + kwargs={'origin_type': origin_info_test_data['type'], + 'origin_url': origin_info_test_data['url'], + 'timestamp': visit_date}) self.assertContains(resp, '%s' % (browse_url, browse_url)) @nottest - def origin_content_view_test(self, origin_id, origin_visits, + def origin_content_view_test(self, origin_info, origin_visits, origin_branches, origin_branch, root_dir_sha1, content_sha1, content_path, content_data, content_language, - visit_id=None, ts=None): + visit_id=None, timestamp=None): - url_args = {'origin_id': origin_id, + url_args = {'origin_type': origin_info['type'], + 'origin_url': origin_info['url'], 'path': content_path} if not visit_id: visit_id = origin_visits[-1]['visit'] - if ts: - url_args['timestamp'] = ts + query_params = {} + + if timestamp: + url_args['timestamp'] = timestamp else: - url_args['visit_id'] = visit_id + query_params['visit_id'] = visit_id url = reverse('browse-origin-content', - kwargs=url_args) + kwargs=url_args, + query_params=query_params) resp = self.client.get(url) self.assertEquals(resp.status_code, 200) self.assertTemplateUsed('content.html') self.assertContains(resp, '' % content_language) self.assertContains(resp, escape(content_data)) split_path = content_path.split('/') filename = split_path[-1] path = content_path.replace(filename, '')[:-1] path_info = gen_path_info(path) del url_args['path'] + query_params['branch'] = origin_branch + if timestamp: + url_args['timestamp'] = \ + format_utc_iso_date(parse_timestamp(timestamp).isoformat(), + '%Y-%m-%dT%H:%M:%S') + root_dir_url = reverse('browse-origin-directory', kwargs=url_args, - query_params={'branch': origin_branch}) + query_params=query_params) self.assertContains(resp, '
  • ', count=len(path_info)+1) + self.assertContains(resp, '%s' % (root_dir_url, root_dir_sha1[:7])) for p in path_info: url_args['path'] = p['path'] dir_url = reverse('browse-origin-directory', kwargs=url_args, - query_params={'branch': origin_branch}) + query_params=query_params) self.assertContains(resp, '%s' % (dir_url, p['name'])) self.assertContains(resp, '
  • %s
  • ' % filename) query_string = 'sha1_git:' + content_sha1 url_raw = reverse('browse-content-raw', kwargs={'query_string': query_string}, query_params={'filename': filename}) self.assertContains(resp, url_raw) self.assertContains(resp, '
  • ', count=len(origin_branches)) url_args['path'] = content_path for branch in origin_branches: + query_params['branch'] = branch['name'] root_dir_branch_url = \ reverse('browse-origin-content', kwargs=url_args, - query_params={'branch': branch['name']}) + query_params=query_params) self.assertContains(resp, '' % root_dir_branch_url) - @patch('swh.web.browse.views.origin.get_origin_visit') - @patch('swh.web.browse.views.origin.get_origin_visits') + @patch('swh.web.browse.utils.get_origin_visits') @patch('swh.web.browse.views.origin.get_origin_visit_branches') @patch('swh.web.browse.views.origin.service') @patch('swh.web.browse.views.origin.request_content') @istest def origin_content_view(self, mock_request_content, mock_service, - mock_get_origin_visit_branches, - mock_get_origin_visits, - mock_get_origin_visit): + mock_get_origin_visit_branches, + mock_get_origin_visits): stub_content_text_sha1 = stub_content_text_data['checksums']['sha1'] - mock_get_origin_visit.return_value = stub_content_origin_visits[0] mock_get_origin_visits.return_value = stub_content_origin_visits - mock_get_origin_visit_branches.return_value = stub_content_origin_branches # noqa + mock_get_origin_visit_branches.return_value = stub_content_origin_branches mock_service.lookup_directory_with_path.return_value = \ {'target': stub_content_text_sha1} mock_request_content.return_value = stub_content_text_data + mock_service.lookup_origin.return_value = stub_content_origin_info - self.origin_content_view_test(stub_content_origin_id, + self.origin_content_view_test(stub_content_origin_info, stub_content_origin_visits, stub_content_origin_branches, stub_content_origin_branch, stub_content_root_dir, stub_content_text_sha1, stub_content_text_path, stub_content_text_data['raw_data'], 'cpp') - self.origin_content_view_test(stub_content_origin_id, + self.origin_content_view_test(stub_content_origin_info, stub_content_origin_visits, stub_content_origin_branches, stub_content_origin_branch, stub_content_root_dir, stub_content_text_sha1, stub_content_text_path, stub_content_text_data['raw_data'], 'cpp', visit_id=stub_content_origin_visit_id) - self.origin_content_view_test(stub_content_origin_id, + self.origin_content_view_test(stub_content_origin_info, stub_content_origin_visits, stub_content_origin_branches, stub_content_origin_branch, stub_content_root_dir, stub_content_text_sha1, stub_content_text_path, stub_content_text_data['raw_data'], 'cpp', - ts=stub_content_origin_visit_unix_ts) + timestamp=stub_content_origin_visit_unix_ts) - self.origin_content_view_test(stub_content_origin_id, + self.origin_content_view_test(stub_content_origin_info, stub_content_origin_visits, stub_content_origin_branches, stub_content_origin_branch, stub_content_root_dir, stub_content_text_sha1, stub_content_text_path, stub_content_text_data['raw_data'], 'cpp', - ts=stub_content_origin_visit_iso_date) + timestamp=stub_content_origin_visit_iso_date) @nottest - def origin_directory_view(self, origin_id, origin_visits, - origin_branches, origin_branch, - root_directory_sha1, directory_entries, - visit_id=None, ts=None, path=None): + def origin_directory_view(self, origin_info, origin_visits, + origin_branches, origin_branch, + root_directory_sha1, directory_entries, + visit_id=None, timestamp=None, path=None): dirs = [e for e in directory_entries if e['type'] == 'dir'] files = [e for e in directory_entries if e['type'] == 'file'] if not visit_id: visit_id = origin_visits[-1]['visit'] - url_args = {'origin_id': origin_id} + url_args = {'origin_type': origin_info['type'], + 'origin_url': origin_info['url']} - if ts: - url_args['timestamp'] = ts + query_params = {} + + if timestamp: + url_args['timestamp'] = timestamp else: - url_args['visit_id'] = visit_id + query_params['visit_id'] = visit_id if path: url_args['path'] = path url = reverse('browse-origin-directory', - kwargs=url_args) + kwargs=url_args, + query_params=query_params) resp = self.client.get(url) self.assertEquals(resp.status_code, 200) self.assertTemplateUsed('directory.html') self.assertContains(resp, '', count=len(dirs)) self.assertContains(resp, '', count=len(files)) + query_params['branch'] = origin_branch + if timestamp: + url_args['timestamp'] = \ + format_utc_iso_date(parse_timestamp(timestamp).isoformat(), + '%Y-%m-%dT%H:%M:%S') + for d in dirs: dir_path = d['name'] if path: dir_path = "%s/%s" % (path, d['name']) dir_url_args = dict(url_args) dir_url_args['path'] = dir_path dir_url = reverse('browse-origin-directory', kwargs=dir_url_args, - query_params={'branch': origin_branch}) # noqa + query_params=query_params) self.assertContains(resp, dir_url) for f in files: file_path = f['name'] if path: file_path = "%s/%s" % (path, f['name']) file_url_args = dict(url_args) file_url_args['path'] = file_path file_url = reverse('browse-origin-content', kwargs=file_url_args, - query_params={'branch': origin_branch}) # noqa + query_params=query_params) self.assertContains(resp, file_url) if 'path' in url_args: del url_args['path'] root_dir_branch_url = \ reverse('browse-origin-directory', kwargs=url_args, - query_params={'branch': origin_branch}) + query_params=query_params) nb_bc_paths = 1 if path: nb_bc_paths = len(path.split('/')) + 1 self.assertContains(resp, '
  • ', count=nb_bc_paths) self.assertContains(resp, '%s' % (root_dir_branch_url, root_directory_sha1[:7])) self.assertContains(resp, '
  • ', count=len(origin_branches)) if path: url_args['path'] = path for branch in origin_branches: + query_params['branch'] = branch['name'] root_dir_branch_url = \ reverse('browse-origin-directory', kwargs=url_args, - query_params={'branch': branch['name']}) + query_params=query_params) self.assertContains(resp, '' % root_dir_branch_url) - @patch('swh.web.browse.views.origin.get_origin_visit') - @patch('swh.web.browse.views.origin.get_origin_visits') + @patch('swh.web.browse.utils.get_origin_visits') @patch('swh.web.browse.views.origin.get_origin_visit_branches') @patch('swh.web.browse.utils.service') @patch('swh.web.browse.views.origin.service') @istest def origin_root_directory_view(self, mock_origin_service, mock_utils_service, mock_get_origin_visit_branches, - mock_get_origin_visits, - mock_get_origin_visit): - - mock_get_origin_visit.return_value = stub_origin_visits[0] + mock_get_origin_visits): mock_get_origin_visits.return_value = stub_origin_visits mock_get_origin_visit_branches.return_value = stub_origin_branches mock_utils_service.lookup_directory.return_value = \ stub_origin_root_directory_entries - mock_origin_service.lookup_origin.return_value = origin_info_test_data + mock_origin_service.lookup_origin.return_value = stub_origin_info - self.origin_directory_view(stub_origin_id, stub_origin_visits, + self.origin_directory_view(stub_origin_info, stub_origin_visits, stub_origin_branches, stub_origin_master_branch, stub_origin_root_directory_sha1, stub_origin_root_directory_entries) - self.origin_directory_view(stub_origin_id, stub_origin_visits, + self.origin_directory_view(stub_origin_info, stub_origin_visits, stub_origin_branches, stub_origin_master_branch, stub_origin_root_directory_sha1, stub_origin_root_directory_entries, visit_id=stub_visit_id) - self.origin_directory_view(stub_origin_id, stub_origin_visits, + self.origin_directory_view(stub_origin_info, stub_origin_visits, stub_origin_branches, stub_origin_master_branch, stub_origin_root_directory_sha1, stub_origin_root_directory_entries, - ts=stub_visit_unix_ts) + timestamp=stub_visit_unix_ts) - self.origin_directory_view(stub_origin_id, stub_origin_visits, + self.origin_directory_view(stub_origin_info, stub_origin_visits, stub_origin_branches, stub_origin_master_branch, stub_origin_root_directory_sha1, stub_origin_root_directory_entries, - ts=stub_visit_iso_date) + timestamp=stub_visit_iso_date) - @patch('swh.web.browse.views.origin.get_origin_visit') - @patch('swh.web.browse.views.origin.get_origin_visits') + @patch('swh.web.browse.utils.get_origin_visits') @patch('swh.web.browse.views.origin.get_origin_visit_branches') @patch('swh.web.browse.utils.service') @patch('swh.web.browse.views.origin.service') @istest def origin_sub_directory_view(self, mock_origin_service, mock_utils_service, mock_get_origin_visit_branches, - mock_get_origin_visits, - mock_get_origin_visit): - - mock_get_origin_visit.return_value = stub_origin_visits[0] + mock_get_origin_visits): mock_get_origin_visits.return_value = stub_origin_visits mock_get_origin_visit_branches.return_value = stub_origin_branches mock_utils_service.lookup_directory.return_value = \ stub_origin_sub_directory_entries mock_origin_service.lookup_directory_with_path.return_value = \ {'target': '120c39eeb566c66a77ce0e904d29dfde42228adb'} + mock_origin_service.lookup_origin.return_value = stub_origin_info - self.origin_directory_view(stub_origin_id, stub_origin_visits, + self.origin_directory_view(stub_origin_info, stub_origin_visits, stub_origin_branches, stub_origin_master_branch, stub_origin_root_directory_sha1, stub_origin_sub_directory_entries, path=stub_origin_sub_directory_path) - self.origin_directory_view(stub_origin_id, stub_origin_visits, + self.origin_directory_view(stub_origin_info, stub_origin_visits, stub_origin_branches, stub_origin_master_branch, stub_origin_root_directory_sha1, stub_origin_sub_directory_entries, visit_id=stub_visit_id, path=stub_origin_sub_directory_path) - self.origin_directory_view(stub_origin_id, stub_origin_visits, + self.origin_directory_view(stub_origin_info, stub_origin_visits, stub_origin_branches, stub_origin_master_branch, stub_origin_root_directory_sha1, stub_origin_sub_directory_entries, - ts=stub_visit_unix_ts, + timestamp=stub_visit_unix_ts, path=stub_origin_sub_directory_path) - self.origin_directory_view(stub_origin_id, stub_origin_visits, + self.origin_directory_view(stub_origin_info, stub_origin_visits, stub_origin_branches, stub_origin_master_branch, stub_origin_root_directory_sha1, stub_origin_sub_directory_entries, - ts=stub_visit_iso_date, + timestamp=stub_visit_iso_date, path=stub_origin_sub_directory_path) - @patch('swh.web.browse.views.origin.get_origin_visit') @patch('swh.web.browse.views.origin.request_content') - @patch('swh.web.browse.views.origin.get_origin_visits') + @patch('swh.web.browse.utils.get_origin_visits') @patch('swh.web.browse.views.origin.get_origin_visit_branches') @patch('swh.web.browse.utils.service') @patch('swh.web.browse.views.origin.service') @istest - def origin_request_errors(self, mock_origin_service, - mock_utils_service, - mock_get_origin_visit_branches, - mock_get_origin_visits, - mock_request_content, - mock_get_origin_visit): - - mock_get_origin_visit.return_value = stub_origin_visits[0] + def test_origin_request_errors(self, mock_origin_service, + mock_utils_service, + mock_get_origin_visit_branches, + mock_get_origin_visits, + mock_request_content): mock_origin_service.lookup_origin.side_effect = \ NotFoundExc('origin not found') url = reverse('browse-origin', - kwargs={'origin_id': '1'}) + kwargs={'origin_type': 'foo', + 'origin_url': 'bar'}) resp = self.client.get(url) self.assertEquals(resp.status_code, 404) self.assertTemplateUsed('error.html') self.assertContains(resp, "origin not found", status_code=404) mock_origin_service.lookup_origin.side_effect = None mock_origin_service.lookup_origin.return_value = origin_info_test_data mock_get_origin_visits.return_value = [] url = reverse('browse-origin-directory', - kwargs={'origin_id': '1'}) + kwargs={'origin_type': 'foo', + 'origin_url': 'bar'}) resp = self.client.get(url) self.assertEquals(resp.status_code, 404) self.assertTemplateUsed('error.html') self.assertContains(resp, "No SWH visit", status_code=404) mock_get_origin_visits.return_value = stub_origin_visits mock_get_origin_visit_branches.side_effect = \ NotFoundExc('visit not found') url = reverse('browse-origin-directory', - kwargs={'origin_id': '1', - 'visit_id': len(stub_origin_visits)+1}) + kwargs={'origin_type': 'foo', + 'origin_url': 'bar'}, + query_params={'visit_id': len(stub_origin_visits)+1}) resp = self.client.get(url) self.assertEquals(resp.status_code, 404) self.assertTemplateUsed('error.html') - self.assertContains(resp, 'visit not found', status_code=404) + self.assertRegex(resp.content.decode('utf-8'), 'Visit.*not found') mock_get_origin_visits.return_value = stub_origin_visits mock_get_origin_visit_branches.side_effect = None mock_get_origin_visit_branches.return_value = [] url = reverse('browse-origin-directory', - kwargs={'origin_id': '1'}) + kwargs={'origin_type': 'foo', + 'origin_url': 'bar'}) resp = self.client.get(url) self.assertEquals(resp.status_code, 404) self.assertTemplateUsed('error.html') self.assertRegex(resp.content.decode('utf-8'), 'Origin.*is empty') mock_get_origin_visit_branches.return_value = stub_origin_branches mock_utils_service.lookup_directory.side_effect = \ NotFoundExc('Directory not found') url = reverse('browse-origin-directory', - kwargs={'origin_id': '1'}) + kwargs={'origin_type': 'foo', + 'origin_url': 'bar'}) resp = self.client.get(url) self.assertEquals(resp.status_code, 404) self.assertTemplateUsed('error.html') self.assertContains(resp, 'Directory not found', status_code=404) mock_origin_service.lookup_origin.side_effect = None mock_origin_service.lookup_origin.return_value = origin_info_test_data mock_get_origin_visits.return_value = [] url = reverse('browse-origin-content', - kwargs={'origin_id': '1', + kwargs={'origin_type': 'foo', + 'origin_url': 'bar', 'path': 'foo'}) resp = self.client.get(url) self.assertEquals(resp.status_code, 404) self.assertTemplateUsed('error.html') self.assertContains(resp, "No SWH visit", status_code=404) mock_get_origin_visits.return_value = stub_origin_visits mock_get_origin_visit_branches.side_effect = \ NotFoundExc('visit not found') url = reverse('browse-origin-content', - kwargs={'origin_id': '1', - 'visit_id': len(stub_origin_visits)+1, - 'path': 'foo'}) + kwargs={'origin_type': 'foo', + 'origin_url': 'bar', + 'path': 'foo'}, + query_params={'visit_id': len(stub_origin_visits)+1}) resp = self.client.get(url) self.assertEquals(resp.status_code, 404) self.assertTemplateUsed('error.html') - self.assertContains(resp, 'visit not found', status_code=404) + self.assertRegex(resp.content.decode('utf-8'), 'Visit.*not found') mock_get_origin_visits.return_value = stub_origin_visits mock_get_origin_visit_branches.side_effect = None mock_get_origin_visit_branches.return_value = [] url = reverse('browse-origin-content', - kwargs={'origin_id': '1', - 'path': 'foo'}) + kwargs={'origin_type': 'foo', + 'origin_url': 'bar', + 'path': 'baz'}) resp = self.client.get(url) self.assertEquals(resp.status_code, 404) self.assertTemplateUsed('error.html') self.assertRegex(resp.content.decode('utf-8'), 'Origin.*is empty') mock_get_origin_visit_branches.return_value = stub_origin_branches mock_origin_service.lookup_directory_with_path.return_value = \ {'target': stub_content_text_data['checksums']['sha1']} mock_request_content.side_effect = \ NotFoundExc('Content not found') url = reverse('browse-origin-content', - kwargs={'origin_id': '1', - 'path': 'foo'}) + kwargs={'origin_type': 'foo', + 'origin_url': 'bar', + 'path': 'baz'}) resp = self.client.get(url) self.assertEquals(resp.status_code, 404) self.assertTemplateUsed('error.html') self.assertContains(resp, 'Content not found', status_code=404) diff --git a/swh/web/tests/browse/views/test_revision.py b/swh/web/tests/browse/views/test_revision.py index 8cdaa6af..aed0ca8d 100644 --- a/swh/web/tests/browse/views/test_revision.py +++ b/swh/web/tests/browse/views/test_revision.py @@ -1,251 +1,258 @@ # Copyright (C) 2017 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information +# flake8: noqa + from unittest.mock import patch from nose.tools import istest from django.test import TestCase from django.utils.html import escape from swh.web.common.exc import NotFoundExc from swh.web.common.utils import reverse, format_utc_iso_date from swh.web.tests.testbase import SWHWebTestBase from .data.revision_test_data import ( revision_id_test, revision_metadata_test, revision_history_log_test ) class SwhBrowseRevisionTest(SWHWebTestBase, TestCase): @patch('swh.web.browse.views.revision.service') @istest def revision_browse(self, mock_service): mock_service.lookup_revision.return_value = revision_metadata_test url = reverse('browse-revision', kwargs={'sha1_git': revision_id_test}) author_id = revision_metadata_test['author']['id'] author_name = revision_metadata_test['author']['name'] committer_id = revision_metadata_test['committer']['id'] committer_name = revision_metadata_test['committer']['name'] dir_id = revision_metadata_test['directory'] author_url = reverse('browse-person', kwargs={'person_id': author_id}) committer_url = reverse('browse-person', kwargs={'person_id': committer_id}) directory_url = reverse('browse-directory', kwargs={'sha1_git': dir_id}) history_url = reverse('browse-revision-log', kwargs={'sha1_git': revision_id_test}) resp = self.client.get(url) self.assertEquals(resp.status_code, 200) self.assertTemplateUsed('revision.html') self.assertContains(resp, '%s' % (author_url, author_name)) self.assertContains(resp, '%s' % (committer_url, committer_name)) self.assertContains(resp, '%s' % (directory_url, directory_url)) self.assertContains(resp, '%s' % (history_url, history_url)) for parent in revision_metadata_test['parents']: parent_url = reverse('browse-revision', kwargs={'sha1_git': parent}) self.assertContains(resp, '%s' % (parent_url, parent)) author_date = revision_metadata_test['date'] committer_date = revision_metadata_test['committer_date'] message = revision_metadata_test['message'] self.assertContains(resp, format_utc_iso_date(author_date)) self.assertContains(resp, format_utc_iso_date(committer_date)) self.assertContains(resp, message) origin_info = { 'id': '7416001', 'type': 'git', 'url': 'https://github.com/webpack/webpack' } mock_service.lookup_origin.return_value = origin_info origin_directory_url = reverse('browse-origin-directory', - kwargs={'origin_id': origin_info['id']}, - query_params={'revision': revision_id_test}) # noqa + kwargs={'origin_type': origin_info['type'], + 'origin_url': origin_info['url']}, + query_params={'revision': revision_id_test}) origin_revision_log_url = reverse('browse-origin-log', - kwargs={'origin_id': origin_info['id']}, # noqa - query_params={'revision': revision_id_test}) # noqa + kwargs={'origin_type': origin_info['type'], + 'origin_url': origin_info['url']}, + query_params={'revision': revision_id_test}) url = reverse('browse-revision', kwargs={'sha1_git': revision_id_test}, - query_params={'origin_id': origin_info['id']}) # noqa + query_params={'origin_type': origin_info['type'], + 'origin_url': origin_info['url']}) resp = self.client.get(url) self.assertContains(resp, '%s' % (origin_directory_url, origin_directory_url)) self.assertContains(resp, '%s' % - (origin_revision_log_url, origin_revision_log_url)) # noqa + (origin_revision_log_url, origin_revision_log_url)) self.assertContains(resp, '%s' % (origin_info['url'], origin_info['url'])) for parent in revision_metadata_test['parents']: parent_url = reverse('browse-revision', kwargs={'sha1_git': parent}, - query_params={'origin_id': origin_info['id']}) + query_params={'origin_type': origin_info['type'], + 'origin_url': origin_info['url']}) self.assertContains(resp, '%s' % (parent_url, parent)) @patch('swh.web.browse.views.revision.service') @istest def revision_log_browse(self, mock_service): per_page = 10 mock_service.lookup_revision_log.return_value = \ revision_history_log_test[:per_page+1] url = reverse('browse-revision-log', kwargs={'sha1_git': revision_id_test}, query_params={'per_page': per_page}) resp = self.client.get(url) prev_rev = revision_history_log_test[per_page]['id'] next_page_url = reverse('browse-revision-log', kwargs={'sha1_git': prev_rev}, - query_params={'revs_breadcrumb': revision_id_test, # noqa + query_params={'revs_breadcrumb': revision_id_test, 'per_page': per_page}) self.assertEquals(resp.status_code, 200) self.assertTemplateUsed('revision-log.html') self.assertContains(resp, '', count=per_page) self.assertContains(resp, '
  • Newer
  • ') self.assertContains(resp, '
  • Older
  • ' % escape(next_page_url)) for log in revision_history_log_test[:per_page]: author_url = reverse('browse-person', kwargs={'person_id': log['author']['id']}) revision_url = reverse('browse-revision', kwargs={'sha1_git': log['id']}) directory_url = reverse('browse-directory', kwargs={'sha1_git': log['directory']}) self.assertContains(resp, '%s' % (author_url, log['author']['name'])) self.assertContains(resp, '%s' % (revision_url, log['id'][:7])) self.assertContains(resp, '%s' % (directory_url, 'Tree')) mock_service.lookup_revision_log.return_value = \ revision_history_log_test[per_page:2*per_page+1] resp = self.client.get(next_page_url) prev_prev_rev = revision_history_log_test[2*per_page]['id'] prev_page_url = reverse('browse-revision-log', kwargs={'sha1_git': revision_id_test}, query_params={'per_page': per_page}) next_page_url = reverse('browse-revision-log', kwargs={'sha1_git': prev_prev_rev}, - query_params={'revs_breadcrumb': revision_id_test + '/' + prev_rev, # noqa + query_params={'revs_breadcrumb': revision_id_test + '/' + prev_rev, 'per_page': per_page}) self.assertEquals(resp.status_code, 200) self.assertTemplateUsed('revision-log.html') self.assertContains(resp, '', count=per_page) self.assertContains(resp, '
  • Newer
  • ' % escape(prev_page_url)) self.assertContains(resp, '
  • Older
  • ' % escape(next_page_url)) mock_service.lookup_revision_log.return_value = \ revision_history_log_test[2*per_page:3*per_page+1] resp = self.client.get(next_page_url) prev_prev_prev_rev = revision_history_log_test[3*per_page]['id'] prev_page_url = reverse('browse-revision-log', kwargs={'sha1_git': prev_rev}, - query_params={'revs_breadcrumb': revision_id_test, # noqa + query_params={'revs_breadcrumb': revision_id_test, 'per_page': per_page}) next_page_url = reverse('browse-revision-log', kwargs={'sha1_git': prev_prev_prev_rev}, - query_params={'revs_breadcrumb': revision_id_test + '/' + prev_rev + '/' + prev_prev_rev, # noqa + query_params={'revs_breadcrumb': revision_id_test + '/' + prev_rev + '/' + prev_prev_rev, 'per_page': per_page}) self.assertEquals(resp.status_code, 200) self.assertTemplateUsed('revision-log.html') self.assertContains(resp, '', count=per_page) self.assertContains(resp, '
  • Newer
  • ' % escape(prev_page_url)) self.assertContains(resp, '
  • Older
  • ' % escape(next_page_url)) mock_service.lookup_revision_log.return_value = \ revision_history_log_test[3*per_page:3*per_page+per_page//2] resp = self.client.get(next_page_url) prev_page_url = reverse('browse-revision-log', kwargs={'sha1_git': prev_prev_rev}, - query_params={'revs_breadcrumb': revision_id_test + '/' + prev_rev, # noqa + query_params={'revs_breadcrumb': revision_id_test + '/' + prev_rev, 'per_page': per_page}) self.assertEquals(resp.status_code, 200) self.assertTemplateUsed('revision-log.html') self.assertContains(resp, '', count=per_page//2) self.assertContains(resp, '
  • Older
  • ') self.assertContains(resp, '
  • Newer
  • ' % escape(prev_page_url)) @patch('swh.web.browse.views.revision.service') @istest def revision_request_errors(self, mock_service): mock_service.lookup_revision.side_effect = \ NotFoundExc('Revision not found') url = reverse('browse-revision', kwargs={'sha1_git': revision_id_test}) resp = self.client.get(url) self.assertEquals(resp.status_code, 404) self.assertTemplateUsed('error.html') self.assertContains(resp, 'Revision not found', status_code=404) mock_service.lookup_revision_log.side_effect = \ NotFoundExc('Revision not found') url = reverse('browse-revision-log', kwargs={'sha1_git': revision_id_test}) resp = self.client.get(url) self.assertEquals(resp.status_code, 404) self.assertTemplateUsed('error.html') self.assertContains(resp, 'Revision not found', status_code=404) url = reverse('browse-revision', kwargs={'sha1_git': revision_id_test}, - query_params={'origin_id': '54'}) + query_params={'origin_type': 'git', + 'origin_url': 'https://github.com/foo/bar'}) mock_service.lookup_revision.side_effect = None mock_service.lookup_origin.side_effect = \ NotFoundExc('Origin not found') resp = self.client.get(url) self.assertEquals(resp.status_code, 404) self.assertTemplateUsed('error.html') self.assertContains(resp, 'Origin not found', status_code=404)