test for forking repo and cloning it to local repo

This commit is contained in:
Churikova Tetiana 2018-01-26 20:12:58 +02:00
parent 8f6dfe7b2f
commit 417317f9b5
6 changed files with 127 additions and 8 deletions

View File

@ -15,3 +15,7 @@ class BasePageObject(object):
@property
def time_now(self):
return datetime.now().strftime('%-m%-d%-H%-M%-S')
@property
def current_url(self):
return self.driver.current_url

View File

@ -2,6 +2,10 @@ import time, pytest
from pages.base_element import *
from pages.base_page import BasePageObject
from tests import test_data
from git import Repo
import os
import shutil
import logging
class EmailEditbox(BaseEditBox):
@ -106,6 +110,32 @@ class ContractBody(BaseText):
super(ContractBody, self).__init__(driver)
self.locator = self.Locator.xpath_selector("//tbody//p[contains(text(), "
"'Current balance: 0.000000 ETH')]")
class IssueId(BaseText):
def __init__(self, driver):
super(IssueId, self).__init__(driver)
self.locator = self.Locator.css_selector(".gh-header-number")
class ForkButton(BaseButton):
def __init__(self, driver):
super(ForkButton, self).__init__(driver)
self.locator = self.Locator.css_selector("[href='#fork-destination-box']")
class HeaderInForkPopup(BaseText):
def __init__(self, driver):
super(HeaderInForkPopup, self).__init__(driver)
self.locator = self.Locator.css_selector("#facebox-header")
class UserAccountInForkPopup(BaseButton):
def __init__(self, driver):
super(UserAccountInForkPopup, self).__init__(driver)
self.locator = self.Locator.css_selector("[value=%s]"%test_data.config['DEV']['gh_username'])
class ForkedRepoText(BaseText):
def __init__(self, driver):
super(ForkedRepoText, self).__init__(driver)
self.locator = self.Locator.css_selector(".commit-tease")
class GithubPage(BasePageObject):
@ -133,18 +163,28 @@ class GithubPage(BasePageObject):
self.cross_button = LabelsButton.CrossButton(self.driver)
self.submit_new_issue_button = SubmitNewIssueButton(self.driver)
self.contract_body = ContractBody(self.driver)
self.issue_id = IssueId(self.driver)
self.fork_button = ForkButton(self.driver)
self.header_in_fork_popup = HeaderInForkPopup(self.driver)
self.user_account_in_fork_popup = UserAccountInForkPopup(self.driver)
self.forked_repo_text = ForkedRepoText(self.driver)
def get_issues_page(self):
self.driver.get('https://github.com/Org4/nov13/issues')
self.driver.get(test_data.config['ORG']['gh_repo'] + 'issues')
def get_issue_page(self, issue_id):
self.driver.get(test_data.config['ORG']['gh_repo'] + 'issues/' + issue_id)
def get_sob_plugin_page(self):
self.driver.get('http://github.com/apps/status-open-bounty-app-test')
self.driver.get(test_data.config['Common']['sob_test_app'])
def sign_in(self, email, password):
self.email_input.send_keys(email)
self.password_input.send_keys(password)
self.sign_in_button.click()
def install_sob_plugin(self):
initial_url = self.driver.current_url
self.get_sob_plugin_page()
@ -164,7 +204,19 @@ class GithubPage(BasePageObject):
self.bounty_label.click()
self.cross_button.click()
self.submit_new_issue_button.click()
return test_data.issue['title']
test_data.issue['id'] = self.issue_id.text[1:]
logging.info("Issue id is %s" % test_data.issue['id'])
logging.info("Issue title is %s" % test_data.issue['title'])
def fork_repo(self, initial_repo, wait=60):
self.driver.get(initial_repo)
self.fork_button.click()
if self.header_in_fork_popup.text == 'Where should we fork this repository?':
self.user_account_in_fork_popup.click()
self.forked_repo_text.wait_for_element(wait)
def get_login_page(self):
self.driver.get(test_data.config['Common']['gh_login'])
def get_deployed_contract(self, wait=120):
for i in range(wait):
@ -175,3 +227,26 @@ class GithubPage(BasePageObject):
time.sleep(10)
pass
pytest.fail('Contract is not deployed in %s minutes!' % str(wait/60))
#cloning via HTTPS
def clone_repo(self, initial_repo=None, username=None, repo_name=None, repo_path='git_repo'):
os.mkdir(repo_path)
os.chdir(repo_path)
test_data.local_repo_path = os.getcwd()
fork = 'https://github.com/%s/%s.git' % (username, repo_name)
logging.info(('Cloning from %s to %s' % (fork, repo_path)))
r = Repo.clone_from(fork, repo_path)
logging.info(('Successefully cloned to: %s' % test_data.local_repo_path))
logging.info('Set upstream to %s'% initial_repo)
upstream = r.create_remote('upstream', initial_repo)
upstream.fetch()
assert upstream.exists()
r.heads.master.checkout()
def clean_repo_local_folder(self):
logging.info('Removing %s' % test_data.local_repo_path)
if test_data.local_repo_path:
shutil.rmtree(test_data.local_repo_path)

View File

@ -16,3 +16,6 @@ selenium==2.53.6
six==1.10.0
urllib3==1.22
yarl==0.12.0
gitpython==2.1.8
gitdb2==2.0.3
smmap2==2.0.3

View File

@ -3,15 +3,17 @@ import configparser
class TestData(object):
def __init__(self):
self.test_name = None
self.config = configparser.ConfigParser()
# define here path to your config.ini file
#example - config_example.ini
# example - config_example.ini
self.config.read('config.ini')
self.base_case_issue = dict()
self.base_case_issue['title'] = 'Very first auto_test_bounty'
# self.issue['title'] is set in GithubPage::create_new_bounty
# self.issue['id'] is set in GithubPage::create_new_bounty
# self.local_repo_path is set in GithubPage::clone_repo
test_data = TestData()

View File

@ -1,13 +1,27 @@
[Common]
;app URL
url = https://openbounty.status.im:444/
;URL to GH openbounty app
sob_test_app = http://github.com/apps/status-open-bounty-app-test
gh_login = https://github.com/login
[Paths]
;AbsolutePath to 'tests' folder
tests_absolute = /usr/dir/open-bounty/test/end-to-end/tests/
[ORG]
;GitHub credentials for organization
;GitHub credentials for organization owner
gh_login = login
gh_password = password
;GitHub repo path
gh_repo = https://github.com/org_name/repo_name/
;GitHub repo name
gh_repo_name = repo_name
;MetaMask password for organization
mm_password = password
[DEV]
;GitHub credentials for developer
gh_login = login
gh_password = password
gh_username = username

View File

@ -2,6 +2,7 @@ import pytest
from os import environ
from pages.openbounty.landing import LandingPage
from pages.openbounty.bounties import BountiesPage
from pages.thirdparty.github import GithubPage
from tests.basetestcase import BaseTestCase
from tests import test_data
@ -37,6 +38,26 @@ class TestLogin(BaseTestCase):
assert titles[0].text == test_data.issue['title']
def test_forking_repo(self):
github = GithubPage(self.driver)
self.cleanup = True
# Sign In to GH as Developer
github.get_login_page()
github.sign_in(test_data.config['DEV']['gh_login'],
test_data.config['DEV']['gh_password'])
# Fork repo as Developer from Organization
github.fork_repo(test_data.config['ORG']['gh_repo'])
# Cloning repo to local git as Developer and set upstream to Organization (via HTTPS)
github.clone_repo(test_data.config['ORG']['gh_repo'],
test_data.config['DEV']['gh_username'],
test_data.config['ORG']['gh_repo_name'],
'git_repo')
github.clean_repo_local_folder()