Repository navigation
Expand file tree
/
Copy pathtest_commits.py
More file actions
75 lines (59 loc) · 2.62 KB
/
Copy pathtest_commits.py
File metadata and controls
75 lines (59 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from datetime import datetime, timedelta
import shutil
import subprocess
import tempfile
import os
import unittest
from django.test import TestCase
from django.urls import reverse
from codespeed.models import (Project, Benchmark, Revision, Branch, Executable,
Environment)
hgdir = ''
# hg aborts on commit when ui.username is unset, which is the case on a CI
# runner with no ~/.hgrc, so supply one explicitly.
HG_USER = ['-u', 'Codespeed Tests <tests@example.com>']
def setUpModule():
global hgdir
if not shutil.which('hg'):
raise unittest.SkipTest('Mercurial is not installed')
hgdir = tempfile.TemporaryDirectory()
subprocess.check_call(['hg', 'init'], cwd=hgdir.name)
# Add some commits
readme = os.path.join(hgdir.name, 'README.md')
file1 = os.path.join(hgdir.name, 'file1.py')
with open(readme, 'w') as hg_file:
hg_file.write('readme')
subprocess.check_call(['hg', 'add', readme], cwd=hgdir.name)
subprocess.check_call(['hg', 'commit', '-m', "first commit"] + HG_USER,
cwd=hgdir.name)
with open(file1, 'w') as hg_file:
hg_file.write('value = 10')
subprocess.check_call(['hg', 'add', file1], cwd=hgdir.name)
subprocess.check_call(['hg', 'commit', '-m', "second commit"] + HG_USER,
cwd=hgdir.name)
def tearDownModule():
hgdir.cleanup()
class TestMercurial(TestCase):
def setUp(self):
self.days = 0
self.hgdir = hgdir.name
self.starttime = datetime.now() + timedelta(days=-100)
Project(repo_type='M', name='pro',
repo_path=str(self.hgdir)).save()
self.pro = Project.objects.get(name='pro')
Branch(project=self.pro, name='default').save()
self.b = Branch.objects.get(name='default')
Environment(name='Walden Pond').save()
Executable(name='walden', project=self.pro).save()
Benchmark(name='TestBench').save()
self.env = Environment.objects.get(name='Walden Pond')
self.exe = Executable.objects.get(name='walden')
self.bench = Benchmark.objects.get(name='TestBench')
cmd = ['hg', '-R', self.hgdir, 'id', '-r', '1']
self.cid = subprocess.check_output(cmd).split()[0]
Revision(commitid=self.cid.decode('utf-8'), date=self.starttime, branch=self.b,
project=self.pro).save()
def test_hg(self):
with self.settings(REPOSITORY_BASE_PATH=os.path.dirname(self.hgdir)):
response = self.client.get(reverse('displaylogs'), {'revisionid': 1})
assert response.status_code == 200, 'expected 200 got %d' % response.status_code