Skip to content

Commit

Permalink
Added slugification for branch names (#28)
Browse files Browse the repository at this point in the history
Added slugification for branch names (Fixes #26 )
  • Loading branch information
PonteIneptique committed Jan 3, 2017
1 parent 5af6b39 commit 6a019ea
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 7 deletions.
11 changes: 10 additions & 1 deletion flask_github_proxy/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import base64
from slugify import slugify
from hashlib import sha256
from flask import jsonify

Expand Down Expand Up @@ -127,7 +128,15 @@ def __init__(self, path, content, author, date, logs):
self.__logs__ = logs
self.blob = None
self.posted = False
self.branch = None
self.__branch__ = None

@property
def branch(self):
return self.__branch__

@branch.setter
def branch(self, value):
self.__branch__ = slugify(value)

@property
def path(self):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ requests==2.10.0
six==1.10.0
Werkzeug==0.11.10
wheel==0.24.0
python-slugify==1.2.1
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"Flask==0.11.1",
"GitHub-Flask==3.1.2",
"requests==2.10.0",
"python-slugify==1.2.1"
],
include_package_data=True,
zip_safe=False,
Expand Down
59 changes: 53 additions & 6 deletions tests/test_integrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ def test_fail_pull_request(self):
self.assertEqual(http, 404, "Status code should be carried by ProxyError")

def test_default_branch(self):
self.proxy.__default_branch__ = "default_branch"
self.proxy.__default_branch__ = "default-branch"

result = self.makeRequest(
base64.encodebytes(b'Some content'),
Expand All @@ -477,15 +477,15 @@ def test_default_branch(self):
)
data, http = response_read(result)
self.assertIn(
"GET::/repos/ponteineptique/dummy/git/refs/heads/default_branch", self.calls.keys(),
"GET::/repos/ponteineptique/dummy/git/refs/heads/default-branch", self.calls.keys(),
"Assert we check for the default_branch"
)

# Second step : we check with creation
self.calls.clear()
self.proxy.__default_branch__ = "default_branch2"
self.proxy.__default_branch__ = "default-branch2"
self.github_api.route_fail[
"http://localhost/repos/ponteineptique/dummy/git/refs/heads/default_branch2"
"http://localhost/repos/ponteineptique/dummy/git/refs/heads/default-branch2"
] = True
result = self.makeRequest(
base64.encodebytes(b'Some content'),
Expand All @@ -499,11 +499,11 @@ def test_default_branch(self):
)
data, http = response_read(result)
self.assertIn(
"GET::/repos/ponteineptique/dummy/git/refs/heads/default_branch2", self.calls.keys(),
"GET::/repos/ponteineptique/dummy/git/refs/heads/default-branch2", self.calls.keys(),
"Assert we check for the default_branch"
)
self.assertEqual(
json.loads(self.calls["POST::/repos/ponteineptique/dummy/git/refs"]["data"]), {"ref": "refs/heads/default_branch2", "sha": "123456"},
json.loads(self.calls["POST::/repos/ponteineptique/dummy/git/refs"]["data"]), {"ref": "refs/heads/default-branch2", "sha": "123456"},
"Assert we create for the default_branch2"
)

Expand Down Expand Up @@ -551,3 +551,50 @@ def test_default_branch_filesha(self):
{"ref": "refs/heads/9c6609fc", "sha": "123456"},
"Assert we create for the default_branch2"
)

def test_unicode_branch(self):
branch = "LauriMarjamäki"

result = self.makeRequest(
base64.encodebytes(b'Some content'),
make_secret(base64.encodebytes(b'Some content').decode("utf-8"), self.secret),
{
"author_name": branch,
"date": "19/06/2016",
"logs": "Hard work of transcribing file",
"author_email": "leponteineptique@gmail.com",
"branch": "users/{}".format(branch)
}
)
data, http = response_read(result)
self.assertIn(
"GET::/repos/ponteineptique/dummy/git/refs/heads/users-laurimarjamaki", self.calls.keys(),
"Assert we check for the default_branch"
)

# Second step : we check with creation
self.calls.clear()
self.github_api.route_fail[
"http://localhost/repos/ponteineptique/dummy/git/refs/heads/users-laurimarjamaki"
] = True
result = self.makeRequest(
base64.encodebytes(b'Some content'),
make_secret(base64.encodebytes(b'Some content').decode("utf-8"), self.secret),
{
"author_name": branch,
"date": "19/06/2016",
"logs": "Hard work of transcribing file",
"author_email": "leponteineptique@gmail.com",
"branch": "users/{}".format(branch)
}
)
data, http = response_read(result)
self.assertIn(
"GET::/repos/ponteineptique/dummy/git/refs/heads/users-laurimarjamaki", self.calls.keys(),
"Assert we check for the default_branch"
)
self.assertEqual(
json.loads(self.calls["POST::/repos/ponteineptique/dummy/git/refs"]["data"]),
{"ref": "refs/heads/users-laurimarjamaki", "sha": "123456"},
"Assert we create for the branch users-laurimarjamaki"
)

0 comments on commit 6a019ea

Please sign in to comment.