Changeset View
Changeset View
Standalone View
Standalone View
swh/web/ui/tests/views/test_api.py
Show First 20 Lines • Show All 673 Lines • ▼ Show 20 Lines | def api_revision(self, mock_service): | ||||
'committer_email': 'robot@softwareheritage.org', | 'committer_email': 'robot@softwareheritage.org', | ||||
'message': 'synthetic revision message', | 'message': 'synthetic revision message', | ||||
'date_offset': 0, | 'date_offset': 0, | ||||
'committer_date_offset': 0, | 'committer_date_offset': 0, | ||||
'parents': [ | 'parents': [ | ||||
'8734ef7e7c357ce2af928115c6c6a42b7e2a44e7' | '8734ef7e7c357ce2af928115c6c6a42b7e2a44e7' | ||||
], | ], | ||||
'parent_urls': [ | 'parent_urls': [ | ||||
'/api/1/revision/18d8be353ed3480476f032475e7c233eff7371d5' | '/api/1/revision/8734ef7e7c357ce2af928115c6c6a42b7e2a44e7' | ||||
'/history/8734ef7e7c357ce2af928115c6c6a42b7e2a44e7/' | '/prev/18d8be353ed3480476f032475e7c233eff7371d5/' | ||||
], | ], | ||||
'type': 'tar', | 'type': 'tar', | ||||
'synthetic': True, | 'synthetic': True, | ||||
'metadata': { | 'metadata': { | ||||
'original_artifact': [{ | 'original_artifact': [{ | ||||
'archive_type': 'tar', | 'archive_type': 'tar', | ||||
'name': 'webbase-5.7.0.tar.gz', | 'name': 'webbase-5.7.0.tar.gz', | ||||
'sha1': '147f73f369733d088b7a6fa9c4e0273dcd3c7ccd', | 'sha1': '147f73f369733d088b7a6fa9c4e0273dcd3c7ccd', | ||||
▲ Show 20 Lines • Show All 719 Lines • ▼ Show 20 Lines | def api_revision_log(self, mock_service): | ||||
'committer_email': 'robot@softwareheritage.org', | 'committer_email': 'robot@softwareheritage.org', | ||||
'message': 'synthetic revision message', | 'message': 'synthetic revision message', | ||||
'date_offset': 0, | 'date_offset': 0, | ||||
'committer_date_offset': 0, | 'committer_date_offset': 0, | ||||
'parents': [ | 'parents': [ | ||||
'7834ef7e7c357ce2af928115c6c6a42b7e2a4345' | '7834ef7e7c357ce2af928115c6c6a42b7e2a4345' | ||||
], | ], | ||||
'parent_urls': [ | 'parent_urls': [ | ||||
'/api/1/revision/18d8be353ed3480476f032475e7c233eff7371d5' | '/api/1/revision/7834ef7e7c357ce2af928115c6c6a42b7e2a4345' | ||||
'/history/7834ef7e7c357ce2af928115c6c6a42b7e2a4345/' | '/prev/18d8be353ed3480476f032475e7c233eff7371d5/' | ||||
], | ], | ||||
'type': 'tar', | 'type': 'tar', | ||||
'synthetic': True, | 'synthetic': True, | ||||
}] | }] | ||||
# when | # when | ||||
rv = self.app.get('/api/1/revision/8834ef7e7c357ce2af928115c6c6a42' | rv = self.app.get('/api/1/revision/8834ef7e7c357ce2af928115c6c6a42' | ||||
'b7e2a44e6/log/') | 'b7e2a44e6/log/') | ||||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | def api_revision_log_context(self, mock_service): | ||||
'author_email': 'name@surname.com', | 'author_email': 'name@surname.com', | ||||
'committer_name': 'Name Surname', | 'committer_name': 'Name Surname', | ||||
'committer_email': 'name@surname.com', | 'committer_email': 'name@surname.com', | ||||
'message': 'amazing revision message', | 'message': 'amazing revision message', | ||||
'date_offset': 0, | 'date_offset': 0, | ||||
'committer_date_offset': 0, | 'committer_date_offset': 0, | ||||
'parents': ['adc83b19e793491b1c6ea0fd8b46cd9f32e592fc'], | 'parents': ['adc83b19e793491b1c6ea0fd8b46cd9f32e592fc'], | ||||
'parent_urls': [ | 'parent_urls': [ | ||||
'/api/1/revision/7834ef7e7c357ce2af928115c6c6a42b7e2a44e6' | '/api/1/revision/adc83b19e793491b1c6ea0fd8b46cd9f32e592fc' | ||||
'/history/adc83b19e793491b1c6ea0fd8b46cd9f32e592fc/' | '/prev/7834ef7e7c357ce2af928115c6c6a42b7e2a44e6/' | ||||
], | ], | ||||
'type': 'tar', | 'type': 'tar', | ||||
'synthetic': True, | 'synthetic': True, | ||||
}, | }, | ||||
{ | { | ||||
'url': '/api/1/revision/' | 'url': '/api/1/revision/' | ||||
'18d8be353ed3480476f032475e7c233eff7371d5/', | '18d8be353ed3480476f032475e7c233eff7371d5/', | ||||
'history_url': '/api/1/revision/' | 'history_url': '/api/1/revision/' | ||||
'18d8be353ed3480476f032475e7c233eff7371d5/log/', | '18d8be353ed3480476f032475e7c233eff7371d5/log/', | ||||
'id': '18d8be353ed3480476f032475e7c233eff7371d5', | 'id': '18d8be353ed3480476f032475e7c233eff7371d5', | ||||
'directory': '7834ef7e7c357ce2af928115c6c6a42b7e2a44e6', | 'directory': '7834ef7e7c357ce2af928115c6c6a42b7e2a44e6', | ||||
'directory_url': '/api/1/directory/' | 'directory_url': '/api/1/directory/' | ||||
'7834ef7e7c357ce2af928115c6c6a42b7e2a44e6/', | '7834ef7e7c357ce2af928115c6c6a42b7e2a44e6/', | ||||
'author_name': 'Software Heritage', | 'author_name': 'Software Heritage', | ||||
'author_email': 'robot@softwareheritage.org', | 'author_email': 'robot@softwareheritage.org', | ||||
'committer_name': 'Software Heritage', | 'committer_name': 'Software Heritage', | ||||
'committer_email': 'robot@softwareheritage.org', | 'committer_email': 'robot@softwareheritage.org', | ||||
'message': 'synthetic revision message', | 'message': 'synthetic revision message', | ||||
'date_offset': 0, | 'date_offset': 0, | ||||
'committer_date_offset': 0, | 'committer_date_offset': 0, | ||||
'parents': ['7834ef7e7c357ce2af928115c6c6a42b7e2a4345'], | 'parents': ['7834ef7e7c357ce2af928115c6c6a42b7e2a4345'], | ||||
'parent_urls': [ | 'parent_urls': [ | ||||
'/api/1/revision/18d8be353ed3480476f032475e7c233eff7371d5' | '/api/1/revision/7834ef7e7c357ce2af928115c6c6a42b7e2a4345' | ||||
'/history/7834ef7e7c357ce2af928115c6c6a42b7e2a4345/' | '/prev/18d8be353ed3480476f032475e7c233eff7371d5/' | ||||
], | ], | ||||
'type': 'tar', | 'type': 'tar', | ||||
'synthetic': True, | 'synthetic': True, | ||||
}]) | }]) | ||||
mock_service.lookup_revision_log.assert_called_once_with( | mock_service.lookup_revision_log.assert_called_once_with( | ||||
'18d8be353ed3480476f032475e7c233eff7371d5', 100) | '18d8be353ed3480476f032475e7c233eff7371d5', 100) | ||||
mock_service.lookup_revision_multiple.assert_called_once_with( | mock_service.lookup_revision_multiple.assert_called_once_with( | ||||
Show All 33 Lines | def api_revision_log_by(self, mock_service): | ||||
'committer_email': 'robot@softwareheritage.org', | 'committer_email': 'robot@softwareheritage.org', | ||||
'message': 'synthetic revision message', | 'message': 'synthetic revision message', | ||||
'date_offset': 0, | 'date_offset': 0, | ||||
'committer_date_offset': 0, | 'committer_date_offset': 0, | ||||
'parents': [ | 'parents': [ | ||||
'7834ef7e7c357ce2af928115c6c6a42b7e2a4345' | '7834ef7e7c357ce2af928115c6c6a42b7e2a4345' | ||||
], | ], | ||||
'parent_urls': [ | 'parent_urls': [ | ||||
'/api/1/revision/18d8be353ed3480476f032475e7c233eff7371d5' | '/api/1/revision/7834ef7e7c357ce2af928115c6c6a42b7e2a4345' | ||||
'/history/7834ef7e7c357ce2af928115c6c6a42b7e2a4345/' | '/prev/18d8be353ed3480476f032475e7c233eff7371d5/' | ||||
], | ], | ||||
'type': 'tar', | 'type': 'tar', | ||||
'synthetic': True, | 'synthetic': True, | ||||
}] | }] | ||||
# when | # when | ||||
rv = self.app.get('/api/1/revision/origin/1/log/') | rv = self.app.get('/api/1/revision/origin/1/log/') | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | def api_revision_history(self, mock_service): | ||||
# given | # given | ||||
stub_revision = { | stub_revision = { | ||||
'id': '883', | 'id': '883', | ||||
'children': ['777', '999'], | 'children': ['777', '999'], | ||||
'parents': [], | 'parents': [], | ||||
'directory': '272' | 'directory': '272' | ||||
} | } | ||||
mock_service.lookup_revision_with_context.return_value = stub_revision | mock_service.lookup_revision.return_value = stub_revision | ||||
# then | # then | ||||
rv = self.app.get('/api/1/revision/666/history/883/') | rv = self.app.get('/api/1/revision/883/prev/999/') | ||||
self.assertEquals(rv.status_code, 200) | self.assertEquals(rv.status_code, 200) | ||||
self.assertEquals(rv.mimetype, 'application/json') | self.assertEquals(rv.mimetype, 'application/json') | ||||
response_data = json.loads(rv.data.decode('utf-8')) | response_data = json.loads(rv.data.decode('utf-8')) | ||||
self.assertEquals(response_data, { | self.assertEquals(response_data, { | ||||
'id': '883', | 'id': '883', | ||||
'url': '/api/1/revision/883/', | 'url': '/api/1/revision/883/', | ||||
'history_url': '/api/1/revision/883/log/', | 'history_url': '/api/1/revision/883/log/', | ||||
'history_context_url': '/api/1/revision/883/prev/999/log/', | |||||
'children': ['777', '999'], | 'children': ['777', '999'], | ||||
'children_urls': ['/api/1/revision/666/history/777/', | 'children_urls': ['/api/1/revision/777/', | ||||
'/api/1/revision/666/history/999/'], | '/api/1/revision/999/'], | ||||
'parents': [], | 'parents': [], | ||||
'parent_urls': [], | 'parent_urls': [], | ||||
'directory': '272', | 'directory': '272', | ||||
'directory_url': '/api/1/directory/272/' | 'directory_url': '/api/1/directory/272/' | ||||
}) | }) | ||||
mock_service.lookup_revision_with_context.assert_called_once_with( | mock_service.lookup_revision.assert_called_once_with('883') | ||||
'666', '883', 100) | |||||
@patch('swh.web.ui.views.api._revision_directory_by') | @patch('swh.web.ui.views.api._revision_directory_by') | ||||
@istest | @istest | ||||
def api_revision_directory_ko_not_found(self, mock_rev_dir): | def api_revision_directory_ko_not_found(self, mock_rev_dir): | ||||
# given | # given | ||||
mock_rev_dir.side_effect = NotFoundExc('Not found') | mock_rev_dir.side_effect = NotFoundExc('Not found') | ||||
# then | # then | ||||
▲ Show 20 Lines • Show All 447 Lines • Show Last 20 Lines |