This repository has been archived by the owner on Aug 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from ncrmro/dev
Auth and Browser testing
- Loading branch information
Showing
37 changed files
with
653 additions
and
1,650 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,3 +142,5 @@ fabric.properties | |
/src/staticfiles/ | ||
node_modules | ||
/bend/static/ | ||
/fend/src/server/data/schema.json | ||
screenshots |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
prospector==0.12.4 | ||
coverage==4.2 | ||
coverage==4.2 | ||
selenium==3.0.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from django.test import LiveServerTestCase | ||
from selenium import webdriver | ||
import os | ||
|
||
|
||
if not os.path.exists('./screenshots'): | ||
os.makedirs('./screenshots') | ||
|
||
|
||
class HomePageTest(LiveServerTestCase): | ||
def setUp(self): | ||
self.selenium = webdriver.Firefox() | ||
super(HomePageTest, self).setUp() | ||
|
||
def tearDown(self): | ||
self.selenium.quit() | ||
super(HomePageTest, self).tearDown() | ||
|
||
def test_home_page(self): | ||
selenium = self.selenium | ||
selenium.implicitly_wait(10) # seconds | ||
# Opening the link we want to test | ||
selenium.get(self.live_server_url) | ||
selenium.save_screenshot('./screenshots/ff_landing.png') | ||
assert 'Relay Fullstack' in selenium.page_source |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,89 @@ | ||
from graphene import AbstractType, Node, Field, String, relay, ObjectType, Int, Boolean, ID | ||
from graphene import AbstractType, Node, Field, String, relay, ObjectType, Int, Boolean, ID, InputObjectType | ||
from django.contrib.auth.models import AnonymousUser, User | ||
from graphene import AbstractType, Node, relay | ||
from graphene_django.filter import DjangoFilterConnectionField | ||
from graphene_django.types import DjangoObjectType | ||
from .jwt_util import loginUser | ||
from .jwt_util import loginUser, authenticate | ||
from jwt_auth import settings, exceptions | ||
import jwt | ||
|
||
jwt_decode_handler = settings.JWT_DECODE_HANDLER | ||
|
||
|
||
class UserNode(DjangoObjectType): | ||
class Meta: | ||
model = User | ||
only_fields = ( | ||
'id', | ||
'last_login', | ||
'is_superuser', | ||
'username', | ||
'first_name', | ||
'last_name', | ||
'email', | ||
'is_staff', | ||
'is_active', | ||
'date_joined', | ||
'todomodel' | ||
) | ||
interfaces = (Node,) | ||
|
||
|
||
class CurrentUser(ObjectType): | ||
id = ID() | ||
username = String() | ||
password = String() | ||
is_anonymous = Boolean() | ||
is_authenticated = Boolean() | ||
is_staff = Boolean() | ||
is_active = Boolean() | ||
|
||
|
||
class UserQueries(AbstractType): | ||
user = Node.Field(UserNode) | ||
user = Field(UserNode) | ||
all_users = DjangoFilterConnectionField(UserNode) | ||
viewer = Field(UserNode) | ||
|
||
current_user = Field(CurrentUser) | ||
|
||
def resolve_current_user(self, args, context, info): | ||
anon = AnonymousUser | ||
return CurrentUser( | ||
id=anon.id, | ||
username=anon.username, | ||
is_anonymous=anon.is_anonymous, | ||
is_authenticated=anon.is_authenticated, | ||
is_staff=anon.is_staff, | ||
is_active=anon.is_active, | ||
) | ||
def resolve_viewer(self, args, context, info): | ||
try: | ||
check_token = authenticate(context) | ||
print('Found Token in Auth Header', check_token) | ||
token_user = check_token[0] | ||
user = User.objects.get(id=token_user.id, username=token_user.username) | ||
return user | ||
except: | ||
return User( | ||
id=0, | ||
username="" | ||
) | ||
|
||
|
||
class LogInUser(relay.ClientIDMutation): | ||
class Input: | ||
username = String(required=True) | ||
password = String(required=True) | ||
|
||
user = Field(UserNode) | ||
token = String() | ||
viewer = Field(UserNode) | ||
jwt_token = String() | ||
|
||
@classmethod | ||
def mutate_and_get_payload(cls, input, context, info): | ||
print("Logging user in", input, context, info) | ||
username = input.get('username') | ||
password = input.get('password') | ||
jwt_token = loginUser(username, password) | ||
viewer = User.objects.get(username=username) | ||
return LogInUser(viewer, jwt_token) | ||
|
||
|
||
class CreateUser(relay.ClientIDMutation): | ||
class Input: | ||
username = String(required=True) | ||
password = String(required=True) | ||
|
||
viewer = Field(UserNode) | ||
jwt_token = String() | ||
|
||
@classmethod | ||
def mutate_and_get_payload(cls, input, context, info): | ||
print("Logging user in", input, context, info) | ||
username = input.get('username') | ||
password = input.get('password') | ||
token = loginUser(username, password) | ||
return LogInUser(token=token) | ||
viewer = User.objects.create_user(username=username, password=password) | ||
jwt_token = loginUser(username, password) | ||
return CreateUser(viewer, jwt_token) | ||
|
||
|
||
class UserMutations(AbstractType): | ||
login_user = LogInUser.Field() | ||
create_user = CreateUser.Field() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.