Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#200 - Fixing test_archive_license_requests_feature and test_unarchive_license_requests_feature #457

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 68 additions & 28 deletions src/app/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from django.test import TestCase
from unittest import skipIf
from unittest.mock import patch
from src.secret import getAccessToken, getGithubUserId, getGithubUserName
from django.contrib.auth.models import User
from django.conf import settings
Expand Down Expand Up @@ -31,6 +32,33 @@
def getExamplePath(filename):
return os.path.join(settings.EXAMPLES_DIR, filename)


class TestUtil(TestCase):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1% of developers fix this issue

E302: expected 2 blank lines, found 1


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


Help us improve LIFT! (Sonatype LiftBot external survey)

Was this a good recommendation for you? Answering this survey will not impact your Lift settings.

[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

def gitHubLogin(self):
TEST_LOGIN_INFO = {
"provider": "github",
"uid": str(getGithubUserId()),
"access_token": getAccessToken(),
"login": getGithubUserName(),
"id": getGithubUserId(),
"password": 'pass'
}
# login first
self.user = User.objects.create(username=TEST_LOGIN_INFO["login"],
is_active=True,
is_superuser=True)
self.user.set_password(TEST_LOGIN_INFO["password"])
self.user.save()
social_auth = UserSocialAuth.objects.create(provider=TEST_LOGIN_INFO["provider"],
uid=TEST_LOGIN_INFO["uid"],
extra_data=TEST_LOGIN_INFO,
user=self.user)
self.user = authenticate(username=TEST_LOGIN_INFO["login"],
password=TEST_LOGIN_INFO["password"])
login = self.client.login(username=TEST_LOGIN_INFO["login"],
password=TEST_LOGIN_INFO["password"])
return login

class IndexViewsTestCase(TestCase):

def test_index(self):
Expand Down Expand Up @@ -1106,40 +1134,52 @@ def test_error_archive_license_requests(self):
@skipIf(not getAccessToken() and not getGithubUserId() and not getGithubUserName(), "You need to set gihub parameters in the secret.py file for this test to be executed properly.")
def test_archive_license_requests_feature(self):
"""Check if the license is shifted to archive requests when archive button is pressed"""
login = TestUtil.gitHubLogin(self)
self.assertTrue(login)
cookie = self.client.cookies['sessionid']
driver = self.selenium
driver.get(self.live_server_url+'/app/license_requests/')
table_contents = driver.find_element_by_css_selector('tbody').text
self.assertEqual(table_contents, "No data available in table")
license_obj = LicenseRequest.objects.create(fullname="BSD Zero Clause License-00", shortIdentifier="0BSD")
driver.refresh()
license_name = driver.find_element_by_css_selector('td').text
self.assertEqual(license_name, "BSD Zero Clause License-00")
self.assertEqual(LicenseRequest.objects.get(id=license_obj.id).archive, False)
if driver.find_element_by_id('archive_button' + str(license_obj.id)):
driver.find_element_by_id('archive_button' + str(license_obj.id)).click()
driver.find_element_by_id('confirm_archive').click()
self.assertEqual(LicenseRequest.objects.get(id=license_obj.id).archive, True)
else:
pass
with patch('app.utils.checkPermission') as mock_checkPermission:
mock_checkPermission.return_value = True
driver.get(self.live_server_url+'/app/license_requests/')
driver.add_cookie({'name': 'sessionid', 'value': cookie.value, 'secure': False, 'path': '/'})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1% of developers fix this issue

E501: line too long (105 > 79 characters)

❗❗ 11 similar findings have been found in this PR

🔎 Expand here to view all instances of this finding
File Path Line Number
src/app/tests.py 1147
src/app/tests.py 1151
src/app/tests.py 1152
src/app/tests.py 1153
src/app/tests.py 1155
src/app/tests.py 1169
src/app/tests.py 1172
src/app/tests.py 1176
src/app/tests.py 1177
src/app/tests.py 1178

Showing 10 of 11 findings. Visit the Lift Web Console to see all.


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


Help us improve LIFT! (Sonatype LiftBot external survey)

Was this a good recommendation for you? Answering this survey will not impact your Lift settings.

[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sonatype-lift ignoreall

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ignoreall command is active on this PR, all the existing Lift issues are ignored.

table_contents = driver.find_element_by_css_selector('tbody').text
self.assertEqual(table_contents, "No data available in table")
license_obj = LicenseRequest.objects.create(fullname="BSD Zero Clause License-00", shortIdentifier="0BSD")
driver.refresh()
license_name = driver.find_element_by_css_selector('td').text
self.assertEqual(license_name, "BSD Zero Clause License-00")
self.assertEqual(LicenseRequest.objects.get(id=license_obj.id).archive, False)
if driver.find_element_by_id('archive_button' + str(license_obj.id)):
driver.find_element_by_id('archive_button' + str(license_obj.id)).click()
driver.find_element_by_id('confirm_archive').click()
self.assertEqual(LicenseRequest.objects.get(id=license_obj.id).archive, True)
else:
pass

@skipIf(not getAccessToken() and not getGithubUserId() and not getGithubUserName(), "You need to set gihub parameters in the secret.py file for this test to be executed properly.")
def test_unarchive_license_requests_feature(self):
"""Check if license is shifted back to license requests when unarchive button is pressed"""
login = TestUtil.gitHubLogin(self)
self.assertTrue(login)
cookie = self.client.cookies['sessionid']
driver = self.selenium
driver.get(self.live_server_url+'/app/archive_requests/')
table_contents = driver.find_element_by_css_selector('tbody').text
self.assertEqual(table_contents, "No data available in table")
archive_license_obj = LicenseRequest.objects.create(fullname="BSD Zero Clause License-00", shortIdentifier="0BSD", archive="True")
driver.refresh()
license_name = driver.find_element_by_css_selector('td').text
self.assertEqual(license_name, "BSD Zero Clause License-00")
self.assertEqual(LicenseRequest.objects.get(id=archive_license_obj.id).archive, True)
if driver.find_element_by_id('unarchive_button' + str(archive_license_obj.id)):
driver.find_element_by_id('unarchive_button' + str(archive_license_obj.id)).click()
driver.find_element_by_id('confirm_unarchive').click()
self.assertEqual(LicenseRequest.objects.get(id=archive_license_obj.id).archive, False)
else:
pass
with patch('app.utils.checkPermission') as mock_checkPermission:
mock_checkPermission.return_value = True
driver.get(self.live_server_url+'/app/archive_requests/')
driver.add_cookie({'name': 'sessionid', 'value': cookie.value, 'secure': False, 'path': '/'})
table_contents = driver.find_element_by_css_selector('tbody').text
self.assertEqual(table_contents, "No data available in table")
archive_license_obj = LicenseRequest.objects.create(fullname="BSD Zero Clause License-00", shortIdentifier="0BSD", archive="True")
driver.refresh()
license_name = driver.find_element_by_css_selector('td').text
self.assertEqual(license_name, "BSD Zero Clause License-00")
self.assertEqual(LicenseRequest.objects.get(id=archive_license_obj.id).archive, True)
if driver.find_element_by_id('unarchive_button' + str(archive_license_obj.id)):
driver.find_element_by_id('unarchive_button' + str(archive_license_obj.id)).click()
driver.find_element_by_id('confirm_unarchive').click()
self.assertEqual(LicenseRequest.objects.get(id=archive_license_obj.id).archive, False)
else:
pass

class SubmitNewLicenseViewsTestCase(TestCase):

Expand Down