Completed
Pull Request — master (#29)
by Gonzalo
57s
created

test_invalid_user_password()   A

Complexity

Conditions 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
c 2
b 0
f 0
dl 0
loc 4
rs 10
1
# -*- coding: utf-8 -*-
2
# -----------------------------------------------------------------------------
3
# Copyright (c) The Spyder Development Team
4
#
5
# Licensed under the terms of the MIT License
6
# (See LICENSE.txt for details)
7
# -----------------------------------------------------------------------------
8
"""Tests github repo."""
9
10
# Standard library imports
11
import os
12
13
# Third party imports
14
import pytest
15
16
# Local imports
17
from loghub.external.github import ApiError
18
from loghub.main import GitHubRepo
19
20
REPO = 'spyder-ide/loghub'
21
TEST_TOKEN = os.environ.get('TEST_TOKEN', '').replace('x', '')
22
TEST_USER = os.environ.get('TEST_USER', '').replace('x', '')
23
TEST_PASS = os.environ.get('TEST_CODE', '').replace('x', '')
24
TEST_MILESTONE = 'test-milestone'
25
TEST_TAG = 'v0.1.2'
26
NOT_ON_CI = not os.environ.get('CIRCLECI')
27
28
29
# --- Fixtures
30
# -----------------------------------------------------------------------------
31
@pytest.fixture
32
def gh_repo():
33
    return GitHubRepo(token=TEST_TOKEN, repo=REPO)
34
35
36
# --- Tests
37
# -----------------------------------------------------------------------------
38
@pytest.mark.skipif(NOT_ON_CI, reason='test on ci server only')
39
def test_valid_user_password():
40
    gh = GitHubRepo(username=TEST_USER, password='invalid-password', repo=REPO)
41
    with pytest.raises(ApiError):
42
        gh.milestone(TEST_MILESTONE)
43
44
45
def test_invalid_user_password():
46
    gh = GitHubRepo(username=TEST_USER, password='invalid-password', repo=REPO)
47
    with pytest.raises(ApiError):
48
        gh.milestone(TEST_MILESTONE)
49
50
51
@pytest.mark.skipif(NOT_ON_CI, reason='test on ci server only')
52
def test_valid_token():
53
    gh = GitHubRepo(token=TEST_TOKEN, repo=REPO)
54
    gh.milestone(TEST_MILESTONE)
55
56
57
def test_invalid_token():
58
    gh = GitHubRepo(token='this-is-an-invalid-token', repo=REPO)
59
    with pytest.raises(ApiError):
60
        gh.milestone(TEST_MILESTONE)
61
62
63
@pytest.mark.skipif(NOT_ON_CI, reason='test on ci server only')
64
def test_tags(gh_repo):
65
    tags = gh_repo.tags()
66
    titles = [tag['ref'].replace('refs/tags/', '') for tag in tags]
67
    assert TEST_TAG in titles
68
69
70
@pytest.mark.skipif(NOT_ON_CI, reason='test on ci server only')
71
def test_valid_tag(gh_repo):
72
    tag = gh_repo.tag(TEST_TAG)
73
    assert bool(tag)
74
75
76
@pytest.mark.skipif(NOT_ON_CI, reason='test on ci server only')
77
def test_invalid_tag(gh_repo):
78
    with pytest.raises(SystemExit):
79
        gh_repo.tag('invalid-tag')
80
81
82
@pytest.mark.skipif(NOT_ON_CI, reason='test on ci server only')
83
def test_milestones(gh_repo):
84
    milestones = gh_repo.milestones()
85
    titles = [milestone['title'] for milestone in milestones]
86
    assert TEST_MILESTONE in titles
87
88
89
@pytest.mark.skipif(NOT_ON_CI, reason='test on ci server only')
90
def test_valid_milestone(gh_repo):
91
    assert bool(gh_repo.milestone(TEST_MILESTONE))
92
93
94
@pytest.mark.skipif(NOT_ON_CI, reason='test on ci server only')
95
def test_invalid_milestone(gh_repo):
96
    with pytest.raises(SystemExit):
97
        gh_repo.milestone('invalid-milestone')
98
99
100
@pytest.mark.skipif(NOT_ON_CI, reason='test on ci server only')
101
def test_issues(gh_repo):
102
    milestone_data = gh_repo.milestone(TEST_MILESTONE)
103
    print(milestone_data)
104
    milestone_number = milestone_data['number']
105
    issues = gh_repo.issues(milestone=milestone_number, state='closed')
106
    assert len(issues) == 3
107
108
109
@pytest.mark.skipif(NOT_ON_CI, reason='test on ci server only')
110
def test_pr_merged(gh_repo):
111
    assert gh_repo.is_merged(25)
112
113
114
@pytest.mark.skipif(NOT_ON_CI, reason='test on ci server only')
115
def test_pr_closed(gh_repo):
116
    assert not gh_repo.is_merged(22)
117
118
119
def test_dates():
120
    date = GitHubRepo.str_to_date('2016-10-10T08:08:08Z')
121
    assert date.year == 2016
122
    assert date.month == 10
123
    assert date.day == 10
124
    assert date.hour == 8
125
    assert date.minute == 8
126
    assert date.second == 8
127