mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 05:22:16 +00:00
Compare commits
11 Commits
aa51ce7861
...
046ad92132
| Author | SHA1 | Date | |
|---|---|---|---|
| 046ad92132 | |||
| d19fcc9bb5 | |||
| afc345e17c | |||
| 34ade5f7e5 | |||
| 3f95f8189c | |||
| 2258cdac12 | |||
| 31152cd684 | |||
| 1274140c39 | |||
| 9b341ea583 | |||
| 401629c433 | |||
| df94b93f55 |
@@ -1,16 +0,0 @@
|
||||
version: 2
|
||||
plugins:
|
||||
csslint:
|
||||
enabled: true
|
||||
duplication:
|
||||
enabled: true
|
||||
config:
|
||||
languages:
|
||||
- javascript
|
||||
- python
|
||||
eslint:
|
||||
enabled: true
|
||||
fixme:
|
||||
enabled: true
|
||||
radon:
|
||||
enabled: true
|
||||
@@ -1,3 +1,3 @@
|
||||
[run]
|
||||
plugins = django_coverage_plugin
|
||||
omit = *migrations*, *tests*
|
||||
omit = */migrations/*, */tests/*
|
||||
|
||||
23
.github/workflows/django.yml
vendored
23
.github/workflows/django.yml
vendored
@@ -10,12 +10,12 @@ jobs:
|
||||
build:
|
||||
if: "!contains(github.event.head_commit.message, '[ci skip]')"
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
browser: ['chrome', 'firefox']
|
||||
# strategy:
|
||||
# matrix:
|
||||
# browser: ['chrome']
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
BROWSER: ${{ matrix.browser }}
|
||||
# BROWSER: ${{ matrix.browser }}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: bahmutov/npm-install@v1
|
||||
@@ -32,27 +32,16 @@ jobs:
|
||||
- name: Install Dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install pycodestyle coverage coveralls django_coverage_plugin pytest-cov
|
||||
pip install pycodestyle coveralls django_coverage_plugin pytest-cov
|
||||
pip install --upgrade --upgrade-strategy eager -r requirements.txt
|
||||
python manage.py collectstatic --noinput
|
||||
- name: Cache gulp output
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: static/
|
||||
key: static-${{ hashFiles('package-lock.json') }}-${{ hashFiles('pipeline/source_assets') }}
|
||||
- name: Basic Checks
|
||||
run: |
|
||||
pycodestyle . --exclude=migrations,node_modules
|
||||
python manage.py check
|
||||
python manage.py makemigrations --check --dry-run
|
||||
- name: Run Tests
|
||||
uses: paambaati/codeclimate-action@v2.7.5
|
||||
env:
|
||||
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
||||
with:
|
||||
coverageCommand: coverage run -m pytest -n 8
|
||||
coverageLocations: |
|
||||
${{github.workspace}}/.coverage:coverage.py
|
||||
run: pytest --cov -n 8
|
||||
- uses: actions/upload-artifact@v2
|
||||
if: failure()
|
||||
with:
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
*.sqlite3
|
||||
*.md
|
||||
**/tests
|
||||
conftest.py
|
||||
pytest.ini
|
||||
Dockerfile
|
||||
|
||||
@@ -78,6 +78,7 @@ INSTALLED_APPS = (
|
||||
MIDDLEWARE = (
|
||||
'raven.contrib.django.raven_compat.middleware.SentryResponseErrorIdMiddleware',
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'whitenoise.middleware.WhiteNoiseMiddleware',
|
||||
'debug_toolbar.middleware.DebugToolbarMiddleware',
|
||||
'reversion.middleware.RevisionMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
@@ -91,6 +92,7 @@ MIDDLEWARE = (
|
||||
ROOT_URLCONF = 'PyRIGS.urls'
|
||||
|
||||
WSGI_APPLICATION = 'PyRIGS.wsgi.application'
|
||||
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
|
||||
|
||||
@@ -19,11 +19,15 @@ def create_datetime(year, month, day, hour, min):
|
||||
return tz.localize(datetime(year, month, day, hour, min)).astimezone(pytz.utc)
|
||||
|
||||
|
||||
def create_browser(browser):
|
||||
def create_browser():
|
||||
browser = env('BROWSER', default="chrome")
|
||||
if browser == "firefox":
|
||||
options = webdriver.FirefoxOptions()
|
||||
options.headless = True
|
||||
driver = webdriver.Firefox(options=options)
|
||||
driver.set_window_position(0, 0)
|
||||
# Firefox is pissy about out of bounds otherwise
|
||||
driver.set_window_size(3840, 2160)
|
||||
else:
|
||||
options = webdriver.ChromeOptions()
|
||||
options.add_argument("--window-size=1920,1080")
|
||||
@@ -37,7 +41,7 @@ def create_browser(browser):
|
||||
class BaseTest(LiveServerTestCase):
|
||||
def setUp(self):
|
||||
super().setUpClass()
|
||||
self.driver = create_browser(env('BROWSER', default="chrome"))
|
||||
self.driver = create_browser()
|
||||
self.wait = WebDriverWait(self.driver, 15)
|
||||
|
||||
def tearDown(self):
|
||||
@@ -80,4 +84,4 @@ def screenshot_failure_cls(cls):
|
||||
|
||||
|
||||
def assert_times_equal(first_time, second_time):
|
||||
assert first_time.replace(microsecond=0) == second_time.replace(microsecond=0)
|
||||
assert first_time.replace(microsecond=0, second=0) == second_time.replace(microsecond=0, second=0)
|
||||
|
||||
@@ -75,7 +75,7 @@ class BootstrapSelectElement(Region):
|
||||
self.open()
|
||||
search_box.clear()
|
||||
search_box.send_keys(query)
|
||||
self.wait.until(expected_conditions.invisibility_of_element_located(*self._status_locator))
|
||||
self.wait.until(expected_conditions.invisibility_of_element_located(self._status_locator))
|
||||
|
||||
@property
|
||||
def options(self):
|
||||
|
||||
3
app.json
3
app.json
@@ -2,8 +2,7 @@
|
||||
"name": "PyRIGS",
|
||||
"description": "",
|
||||
"scripts": {
|
||||
"postdeploy": "python manage.py migrate && python manage.py generateSampleData",
|
||||
"heroku-cleanup": "rm -rf node_modules pipeline"
|
||||
"postdeploy": "python manage.py migrate && python manage.py generateSampleData"
|
||||
},
|
||||
"stack": "heroku-20",
|
||||
"env": {
|
||||
|
||||
@@ -287,14 +287,14 @@ class TestAssetAudit(AutoLoginTest):
|
||||
category=self.category, date_acquired=datetime.date(2020, 2, 1))
|
||||
models.Asset.objects.create(asset_id="111", description="Erms", status=self.status, category=self.category,
|
||||
date_acquired=datetime.date(2020, 2, 1))
|
||||
models.Asset.objects.create(asset_id="1111", description="A hammer", status=self.status, category=self.category,
|
||||
date_acquired=datetime.date(2020, 2, 1))
|
||||
self.asset = models.Asset.objects.create(asset_id="1111", description="A hammer", status=self.status,
|
||||
category=self.category,
|
||||
date_acquired=datetime.date(2020, 2, 1))
|
||||
self.page = pages.AssetAuditList(self.driver, self.live_server_url).open()
|
||||
self.wait = WebDriverWait(self.driver, 20)
|
||||
|
||||
def test_audit_process(self):
|
||||
asset_id = "1111"
|
||||
self.page.set_query(asset_id)
|
||||
def test_audit_fail(self):
|
||||
self.page.set_query(self.asset.asset_id)
|
||||
self.page.search()
|
||||
self.wait.until(ec.visibility_of_element_located((By.ID, 'modal')))
|
||||
# Do it wrong on purpose to check error display
|
||||
@@ -302,20 +302,26 @@ class TestAssetAudit(AutoLoginTest):
|
||||
self.page.modal.description = ""
|
||||
self.page.modal.submit()
|
||||
self.wait.until(animation_is_finished())
|
||||
self.driver.implicitly_wait(4)
|
||||
self.assertIn("This field is required.", self.page.modal.errors["Description"])
|
||||
|
||||
def test_audit_success(self):
|
||||
self.page.set_query(self.asset.asset_id)
|
||||
self.page.search()
|
||||
self.wait.until(ec.visibility_of_element_located((By.ID, 'modal')))
|
||||
# Now do it properly
|
||||
self.page.modal.description = new_desc = "A BIG hammer"
|
||||
self.page.modal.submit()
|
||||
self.wait.until(animation_is_finished())
|
||||
submit_time = timezone.now()
|
||||
# Check data is correct
|
||||
audited = models.Asset.objects.get(asset_id=asset_id)
|
||||
self.assertEqual(audited.description, new_desc)
|
||||
self.asset.refresh_from_db()
|
||||
self.assertEqual(self.asset.description, new_desc)
|
||||
# Make sure audit 'log' was filled out
|
||||
self.assertEqual(self.profile.initials, audited.last_audited_by.initials)
|
||||
assert_times_equal(submit_time, audited.last_audited_at)
|
||||
self.assertEqual(self.profile.initials, self.asset.last_audited_by.initials)
|
||||
assert_times_equal(submit_time, self.asset.last_audited_at)
|
||||
# Check we've removed it from the 'needing audit' list
|
||||
self.assertNotIn(asset_id, self.page.assets)
|
||||
self.assertNotIn(self.asset.asset_id, self.page.assets)
|
||||
|
||||
def test_audit_list(self):
|
||||
self.assertEqual(len(models.Asset.objects.filter(last_audited_at=None)), len(self.page.assets))
|
||||
|
||||
@@ -213,18 +213,17 @@ def create_asset_one():
|
||||
status = models.AssetStatus.objects.create(name="Probably Fine", should_show=True)
|
||||
return models.Asset.objects.create(asset_id="1", description="Half Price Fish", status=status, category=category, date_acquired=datetime.date(2020, 2, 1))
|
||||
|
||||
# Nothing should be available to the unauthenticated
|
||||
|
||||
|
||||
def test_unauthenticated(client):
|
||||
def test_unauthenticated(client): # Nothing should be available to the unauthenticated
|
||||
create_asset_one()
|
||||
for url in filter(lambda url: url.name is not None and "json" not in str(url), urls.urlpatterns):
|
||||
pattern = str(url.pattern)
|
||||
request_url = ""
|
||||
if ":pk>" in pattern:
|
||||
request_url = reverse(url.name, kwargs={'pk': 1})
|
||||
else:
|
||||
request_url = reverse(url.name)
|
||||
if request_url:
|
||||
print(request_url)
|
||||
response = client.get(request_url, follow=True, HTTP_HOST='example.com')
|
||||
# TODO Check the URL here
|
||||
assertContains(response, 'Login')
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"gulp": "gulp",
|
||||
"build": "node node_modules/gulp/bin/gulp build"
|
||||
"build": "node node_modules/gulp/bin/gulp build",
|
||||
"heroku-cleanup": "rm -rf node_modules/ pipeline/source_assets gulpfile.js"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user