tests for project detection
This commit is contained in:
parent
6ec2bc69a1
commit
b223138ab2
8 changed files with 95 additions and 0 deletions
0
tests/samples/projects/git/emptyfile.txt
Normal file
0
tests/samples/projects/git/emptyfile.txt
Normal file
0
tests/samples/projects/hg/emptyfile.txt
Normal file
0
tests/samples/projects/hg/emptyfile.txt
Normal file
0
tests/samples/projects/project_map/emptyfile.txt
Normal file
0
tests/samples/projects/project_map/emptyfile.txt
Normal file
0
tests/samples/projects/svn/emptyfile.txt
Normal file
0
tests/samples/projects/svn/emptyfile.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
waka-project-file
|
5
tests/samples/svn_output
Normal file
5
tests/samples/svn_output
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
Path: .
|
||||||
|
Working Copy Root Path: /Users/user/projects/svn
|
||||||
|
URL: http://code.googlecode.com/svn
|
||||||
|
Relative URL: ^/
|
||||||
|
Repository Root: http://code.googlecode.com/svn
|
89
tests/test_wakatime_project.py
Normal file
89
tests/test_wakatime_project.py
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
|
||||||
|
from wakatime.main import execute
|
||||||
|
from wakatime.packages import requests
|
||||||
|
from wakatime.packages.requests.models import Response
|
||||||
|
|
||||||
|
import time
|
||||||
|
from wakatime.compat import u
|
||||||
|
from . import utils
|
||||||
|
|
||||||
|
|
||||||
|
class LanguagesTestCase(utils.TestCase):
|
||||||
|
patch_these = [
|
||||||
|
'wakatime.packages.requests.adapters.HTTPAdapter.send',
|
||||||
|
'wakatime.offlinequeue.Queue.push',
|
||||||
|
['wakatime.offlinequeue.Queue.pop', None],
|
||||||
|
'wakatime.session_cache.SessionCache.save',
|
||||||
|
'wakatime.session_cache.SessionCache.delete',
|
||||||
|
['wakatime.session_cache.SessionCache.get', requests.session],
|
||||||
|
]
|
||||||
|
|
||||||
|
def test_project_argument_overrides_detected_project(self):
|
||||||
|
response = Response()
|
||||||
|
response.status_code = 0
|
||||||
|
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
||||||
|
|
||||||
|
now = u(int(time.time()))
|
||||||
|
entity = 'tests/samples/projects/git/emptyfile.txt'
|
||||||
|
config = 'tests/samples/sample.cfg'
|
||||||
|
|
||||||
|
args = ['--project', 'forced-project', '--file', entity, '--config', config, '--time', now]
|
||||||
|
|
||||||
|
execute(args)
|
||||||
|
|
||||||
|
self.assertEquals('forced-project', self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['project'])
|
||||||
|
|
||||||
|
def test_wakatime_project_file(self):
|
||||||
|
response = Response()
|
||||||
|
response.status_code = 0
|
||||||
|
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
||||||
|
|
||||||
|
now = u(int(time.time()))
|
||||||
|
entity = 'tests/samples/projects/wakatime_project_file/emptyfile.txt'
|
||||||
|
config = 'tests/samples/sample.cfg'
|
||||||
|
|
||||||
|
args = ['--file', entity, '--config', config, '--time', now]
|
||||||
|
|
||||||
|
execute(args)
|
||||||
|
|
||||||
|
self.assertEquals('waka-project-file', self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['project'])
|
||||||
|
|
||||||
|
def test_git_project_detected(self):
|
||||||
|
response = Response()
|
||||||
|
response.status_code = 0
|
||||||
|
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
||||||
|
|
||||||
|
now = u(int(time.time()))
|
||||||
|
entity = 'tests/samples/projects/git/emptyfile.txt'
|
||||||
|
config = 'tests/samples/sample.cfg'
|
||||||
|
|
||||||
|
args = ['--file', entity, '--config', config, '--time', now]
|
||||||
|
|
||||||
|
execute(args)
|
||||||
|
|
||||||
|
self.assertEquals('git', self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['project'])
|
||||||
|
|
||||||
|
def test_svn_project_detected(self):
|
||||||
|
response = Response()
|
||||||
|
response.status_code = 0
|
||||||
|
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
|
||||||
|
|
||||||
|
with utils.mock.patch('wakatime.projects.git.Git.process') as mock_git:
|
||||||
|
mock_git.return_value = False
|
||||||
|
|
||||||
|
with utils.mock.patch('wakatime.projects.subversion.Popen.communicate') as mock_popen:
|
||||||
|
stdout = open('tests/samples/svn_output').read()
|
||||||
|
stderr = ''
|
||||||
|
mock_popen.return_value = (stdout, stderr)
|
||||||
|
|
||||||
|
now = u(int(time.time()))
|
||||||
|
entity = 'tests/samples/projects/svn/emptyfile.txt'
|
||||||
|
config = 'tests/samples/sample.cfg'
|
||||||
|
|
||||||
|
args = ['--file', entity, '--config', config, '--time', now]
|
||||||
|
|
||||||
|
execute(args)
|
||||||
|
|
||||||
|
self.assertEquals('svn', self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['project'])
|
Loading…
Reference in a new issue