From c6467896dec0c9aaa428f5f2ea1a5d2ef3bef482 Mon Sep 17 00:00:00 2001 From: Stephen G Tuggy Date: Fri, 7 Aug 2020 16:12:32 -0700 Subject: [PATCH 01/14] Add CODE_OF_CONDUCT.md --- CODE_OF_CONDUCT.md | 129 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 CODE_OF_CONDUCT.md diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..a0f1b56 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,129 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +job_history_code_of_conduct@eml.cc. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct +enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at +https://www.contributor-covenant.org/translations. + From 31ea44bf80dfb5b1d6643108b842a7e3ff422f37 Mon Sep 17 00:00:00 2001 From: Stephen G Tuggy Date: Sun, 16 Aug 2020 07:36:12 -0700 Subject: [PATCH 02/14] chore: Check in .env.example sample .env file --- .env.example | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..7bd192b --- /dev/null +++ b/.env.example @@ -0,0 +1,13 @@ +JOB_HISTORY_ALLOWED_HOSTS=0.0.0.0,my-desktop +JOB_HISTORY_DB_HOST=job_history_db +JOB_HISTORY_DB_NAME=job_history +JOB_HISTORY_DB_PASSWORD=8KkMs8a2SdxUw25CAwmuyantK5dbK1xT +JOB_HISTORY_DB_PORT=5432 +JOB_HISTORY_DB_USERNAME=postgres +JOB_HISTORY_DEBUG=FALSE +JOB_HISTORY_SECRET_KEY=4VGVMQDKbpMsAostzHCtlfOUTHFAMx03zeXza96WGiPxt3qTtkQcTyr +JOB_HISTORY_STATIC_ROOT=/usr/src/app/static/ +JOB_HISTORY_STATIC_URL=/app/static/ +POSTGRES_DB=job_history +POSTGRES_PASSWORD=8KkMs8a2SdxUw25CAwmuyantK5dbK1xT +POSTGRES_USER=postgres From 5732cd681f6970693b405a11c29c30e0f9ec16e6 Mon Sep 17 00:00:00 2001 From: Stephen G Tuggy Date: Sun, 16 Aug 2020 07:36:32 -0700 Subject: [PATCH 03/14] chore(.gitignore): Add a few items --- .gitignore | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 236aa2e..d210020 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,8 @@ parts/ sdist/ var/ wheels/ +pip-wheel-metadata/ +share/python-wheels/ *.egg-info/ .installed.cfg *.egg @@ -40,12 +42,14 @@ pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ +.nox/ .coverage .coverage.* .cache nosetests.xml coverage.xml *.cover +*.py,cover .hypothesis/ .pytest_cache/ @@ -57,6 +61,7 @@ coverage.xml *.log local_settings.py db.sqlite3 +db.sqlite3-journal # Flask stuff: instance/ @@ -74,11 +79,26 @@ target/ # Jupyter Notebook .ipynb_checkpoints +# IPython +profile_default/ +ipython_config.py + # pyenv .python-version -# celery beat schedule file +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff celerybeat-schedule +celerybeat.pid # SageMath parsed files *.sage.py @@ -104,6 +124,11 @@ venv.bak/ # mypy .mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ .DS_Store .vscode/ From 26557b8b1587e81f0b7c48082b2f92d4b3593cb8 Mon Sep 17 00:00:00 2001 From: Stephen G Tuggy Date: Sun, 16 Aug 2020 07:39:20 -0700 Subject: [PATCH 04/14] docs(README.md): Update README with new .env instructions --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4788d55..b6a44d9 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ This is a web app that lets you enter info about your current and past jobs into This app runs in `Docker`. You will need both Docker and Docker Compose to build and run it. On macOS and Windows, the easiest way to get these products is to download and install Docker Desktop Community Edition. -Also, you will need a copy of a file called `.env`. Ask me for this file, and I can send you one, via a more secure channel than GitHub. Place this file in the root folder of your local working copy of this repo. +Also, you will need a copy of a file called `.env`. Place this file in the root folder of your local working copy of this repo. You can use `.env.example` as a reference/template. Be sure to change the values for `JOB_HISTORY_SECRET_KEY`, `JOB_HISTORY_DB_PASSWORD`, and `POSTGRES_PASSWORD`. (The last two values should match.) Once you have these items in place, run the command `docker-compose up --build`, either in PowerShell on Windows, or in Terminal on macOS or Linux. You should see Docker Compose pulling the latest copy of each source docker image, then building the main image for this app, and finally, spinning up both containers. From a6379c2fcf8a4a2c5b3988e4c251f423e03f9c1d Mon Sep 17 00:00:00 2001 From: Stephen G Tuggy Date: Thu, 20 Aug 2020 08:59:47 -0700 Subject: [PATCH 05/14] deps: Remove unnecessary dependency GDAL --- app/requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/requirements.txt b/app/requirements.txt index b570bd5..9455d77 100644 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -2,7 +2,6 @@ astroid==2.4.2 colorama==0.4.3 Django==2.2.15 django-environ==0.4.5 -GDAL==2.4.0 isort==4.3.21 lazy-object-proxy==1.4.3 mccabe==0.6.1 From b0ffab995a7f09892da22e4b3d8860da24a53e85 Mon Sep 17 00:00:00 2001 From: Stephen G Tuggy Date: Thu, 20 Aug 2020 09:21:13 -0700 Subject: [PATCH 06/14] models: Add UniqueConstraints on Employer and Position --- .../migrations/0008_auto_20200820_1614.py | 21 +++++++++++++++++++ app/jobHistory/models.py | 6 ++++++ 2 files changed, 27 insertions(+) create mode 100644 app/jobHistory/migrations/0008_auto_20200820_1614.py diff --git a/app/jobHistory/migrations/0008_auto_20200820_1614.py b/app/jobHistory/migrations/0008_auto_20200820_1614.py new file mode 100644 index 0000000..09b677a --- /dev/null +++ b/app/jobHistory/migrations/0008_auto_20200820_1614.py @@ -0,0 +1,21 @@ +# Generated by Django 2.2.15 on 2020-08-20 16:14 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('jobHistory', '0007_auto_20200813_1931'), + ] + + operations = [ + migrations.AddConstraint( + model_name='employer', + constraint=models.UniqueConstraint(fields=('short_name',), name='employer_must_be_unique'), + ), + migrations.AddConstraint( + model_name='position', + constraint=models.UniqueConstraint(fields=('employer', 'title'), name='position_must_be_unique'), + ), + ] diff --git a/app/jobHistory/models.py b/app/jobHistory/models.py index aff0539..ca02d82 100644 --- a/app/jobHistory/models.py +++ b/app/jobHistory/models.py @@ -9,6 +9,9 @@ class Employer(models.Model): class Meta: verbose_name = _('Employer') + constraints = [ + models.UniqueConstraint(fields=['short_name', ], name='employer_must_be_unique'), + ] short_name = models.CharField(max_length=50, unique=True, blank=False, null=False, verbose_name=_('Short Name')) long_name = models.CharField(max_length=254, unique=True, blank=False, null=True, verbose_name=_('Long Name')) @@ -31,6 +34,9 @@ def __str__(self): class Position(models.Model): class Meta: verbose_name = _('Position') + constraints = [ + models.UniqueConstraint(fields=['employer', 'title', ], name='position_must_be_unique'), + ] employer = models.ForeignKey(Employer, on_delete=models.CASCADE, verbose_name=_('Employer')) title = models.CharField(max_length=200, blank=False, null=False, verbose_name=_('Title')) From 052a161448115a04eb98664ce12c4104aa4d6e0e Mon Sep 17 00:00:00 2001 From: Stephen G Tuggy Date: Thu, 20 Aug 2020 09:42:53 -0700 Subject: [PATCH 07/14] Create CONTRIBUTING.md --- CONTRIBUTING.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..e589837 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,17 @@ +# Contributing + +Thank you for taking the time to contribute to job-history! There are just a few things to be aware of when contributing to this project. + +## Code of Conduct +First, please follow the [Code of Conduct](CODE_OF_CONDUCT.md). + +## Filing Issues +Second, when filing issues or bugs, please try to fill out the complete template as much as possible. This will help save time in the long run. + +## Pull Requests +When submitting a Pull Request, try to fill that template out thoroughly, as well. Link any related issues, with [closing keywords](https://docs.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), if appropriate. + +## Code Conventions +In general, please follow general Python/Django style guidelines, as well as the conventions you see used in the project already. + +Thanks once again! From 1b78cb9361ddc75c2fe94bdcdc40f1d0707f176a Mon Sep 17 00:00:00 2001 From: Stephen G Tuggy Date: Fri, 21 Aug 2020 14:46:36 -0700 Subject: [PATCH 08/14] feat(tests): First test --- app/jobHistory/tests.py | 22 ++++++++++++++++++++++ docker-compose.circleci.yml | 5 ++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/jobHistory/tests.py b/app/jobHistory/tests.py index 7ce503c..a1ded5e 100644 --- a/app/jobHistory/tests.py +++ b/app/jobHistory/tests.py @@ -1,3 +1,25 @@ from django.test import TestCase +from .models import Employer, Position, JobTimePeriod # Create your tests here. +class EmployerTestCase(TestCase): + def setUp(self): + pass + + def test_creating_an_employer(self): + Employer.objects.create(short_name="Employer1", long_name="Employer 1") + + # def test_creating_positions(self): + # Employer.objects.create(short_name="Employer2", long_name="Employer 2") + # empID = Employer.objects.get(short_name="Employer2").pk + # Position.objects.create(employer=empID, title="Position 1", supervisor_given_name="John", supervisor_surname="Doe", can_contact=True) + # Position.objects.create(employer=empID, title="Position 2", supervisor_given_name="Jane", supervisor_surname="Doe", can_contact=False) + + # def test_creating_job_time_periods(self): + # Employer.objects.create(short_name="Employer3", long_name="Employer 3") + # empID = Employer.objects.get(short_name="Employer3").pk + # Position.objects.create(employer=empID, title="Position 3", supervisor_given_name="John", supervisor_surname="Doe", can_contact=True) + # Position.objects.create(employer=empID, title="Position 4", supervisor_given_name="Jane", supervisor_surname="Doe", can_contact=False) + # position3ID = Position.objects.get() + + diff --git a/docker-compose.circleci.yml b/docker-compose.circleci.yml index b780b76..dd99e71 100644 --- a/docker-compose.circleci.yml +++ b/docker-compose.circleci.yml @@ -23,6 +23,7 @@ services: - "8000:8000" networks: - job_history_net_1 + - job_history_internal_net restart: "no" db: @@ -39,12 +40,14 @@ services: ports: - "5432:5432" networks: - - job_history_net_1 + - job_history_internal_net restart: "no" networks: job_history_net_1: + job_history_internal_net: + internal: true volumes: pg_data: From 5def7699dd73d32d92dd5b4dde5e84ef8b4af1c3 Mon Sep 17 00:00:00 2001 From: Stephen G Tuggy Date: Fri, 21 Aug 2020 14:54:15 -0700 Subject: [PATCH 09/14] feat(tests): Test creating positions and creating job time periods --- app/jobHistory/tests.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/app/jobHistory/tests.py b/app/jobHistory/tests.py index a1ded5e..3dc7130 100644 --- a/app/jobHistory/tests.py +++ b/app/jobHistory/tests.py @@ -9,17 +9,22 @@ def setUp(self): def test_creating_an_employer(self): Employer.objects.create(short_name="Employer1", long_name="Employer 1") - # def test_creating_positions(self): - # Employer.objects.create(short_name="Employer2", long_name="Employer 2") - # empID = Employer.objects.get(short_name="Employer2").pk - # Position.objects.create(employer=empID, title="Position 1", supervisor_given_name="John", supervisor_surname="Doe", can_contact=True) - # Position.objects.create(employer=empID, title="Position 2", supervisor_given_name="Jane", supervisor_surname="Doe", can_contact=False) + def test_creating_positions(self): + Employer.objects.create(short_name="Employer2", long_name="Employer 2") + emp = Employer.objects.get(short_name="Employer2") + Position.objects.create(employer=emp, title="Position 1", supervisor_given_name="John", supervisor_surname="Doe", can_contact=True) + Position.objects.create(employer=emp, title="Position 2", supervisor_given_name="Jane", supervisor_surname="Doe", can_contact=False) - # def test_creating_job_time_periods(self): - # Employer.objects.create(short_name="Employer3", long_name="Employer 3") - # empID = Employer.objects.get(short_name="Employer3").pk - # Position.objects.create(employer=empID, title="Position 3", supervisor_given_name="John", supervisor_surname="Doe", can_contact=True) - # Position.objects.create(employer=empID, title="Position 4", supervisor_given_name="Jane", supervisor_surname="Doe", can_contact=False) - # position3ID = Position.objects.get() + def test_creating_job_time_periods(self): + Employer.objects.create(short_name="Employer3", long_name="Employer 3") + emp = Employer.objects.get(short_name="Employer3") + Position.objects.create(employer=emp, title="Position 3", supervisor_given_name="John", supervisor_surname="Doe", can_contact=True) + Position.objects.create(employer=emp, title="Position 4", supervisor_given_name="Jane", supervisor_surname="Doe", can_contact=False) + position3 = Position.objects.get(employer=emp, title="Position 3") + position4 = Position.objects.get(employer=emp, title="Position 4") + JobTimePeriod.objects.create(position=position3, start_year=2000, is_current_position=False, end_year=2005, starting_pay="$10.00/hour", ending_pay="$11.00/hour") + JobTimePeriod.objects.create(position=position3, start_year=2005, is_current_position=False, end_year=2010, starting_pay="$12.00/hour", ending_pay="$13.00/hour") + JobTimePeriod.objects.create(position=position3, start_year=2010, is_current_position=False, end_year=2015, starting_pay="$14.00/hour", ending_pay="$15.00/hour") + JobTimePeriod.objects.create(position=position3, start_year=2015, is_current_position=True, starting_pay="$16.00/hour", ending_pay="$17.00/hour") From 330cc22a5a9cfd5db6cf3382a40dd2e52809979f Mon Sep 17 00:00:00 2001 From: Stephen G Tuggy Date: Fri, 21 Aug 2020 15:29:55 -0700 Subject: [PATCH 10/14] feat: More tests; 2 add'l UniqueConstraints on JobTimePeriod --- .../migrations/0009_auto_20200821_2214.py | 17 +++++++++++++ .../migrations/0010_auto_20200821_2227.py | 25 +++++++++++++++++++ app/jobHistory/models.py | 12 +++++---- app/jobHistory/tests.py | 22 ++++++++++++++++ 4 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 app/jobHistory/migrations/0009_auto_20200821_2214.py create mode 100644 app/jobHistory/migrations/0010_auto_20200821_2227.py diff --git a/app/jobHistory/migrations/0009_auto_20200821_2214.py b/app/jobHistory/migrations/0009_auto_20200821_2214.py new file mode 100644 index 0000000..f38d67b --- /dev/null +++ b/app/jobHistory/migrations/0009_auto_20200821_2214.py @@ -0,0 +1,17 @@ +# Generated by Django 2.2.15 on 2020-08-21 22:14 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('jobHistory', '0008_auto_20200820_1614'), + ] + + operations = [ + migrations.AddConstraint( + model_name='jobtimeperiod', + constraint=models.UniqueConstraint(fields=('position', 'start_year', 'is_current_position', 'end_year'), name='job_time_period_must_be_unique'), + ), + ] diff --git a/app/jobHistory/migrations/0010_auto_20200821_2227.py b/app/jobHistory/migrations/0010_auto_20200821_2227.py new file mode 100644 index 0000000..cd05a48 --- /dev/null +++ b/app/jobHistory/migrations/0010_auto_20200821_2227.py @@ -0,0 +1,25 @@ +# Generated by Django 2.2.15 on 2020-08-21 22:27 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('jobHistory', '0009_auto_20200821_2214'), + ] + + operations = [ + migrations.RemoveConstraint( + model_name='jobtimeperiod', + name='job_time_period_must_be_unique', + ), + migrations.AddConstraint( + model_name='jobtimeperiod', + constraint=models.UniqueConstraint(fields=('position', 'start_year', 'is_current_position'), name='job_time_period_must_be_unique_1'), + ), + migrations.AddConstraint( + model_name='jobtimeperiod', + constraint=models.UniqueConstraint(condition=models.Q(is_current_position__exact=False), fields=('position', 'start_year', 'end_year'), name='job_time_period_start_and_end_year_must_be_unique_if_not_current_position'), + ), + ] diff --git a/app/jobHistory/models.py b/app/jobHistory/models.py index ca02d82..64bffc7 100644 --- a/app/jobHistory/models.py +++ b/app/jobHistory/models.py @@ -9,9 +9,9 @@ class Employer(models.Model): class Meta: verbose_name = _('Employer') - constraints = [ + constraints = [ models.UniqueConstraint(fields=['short_name', ], name='employer_must_be_unique'), - ] + ] short_name = models.CharField(max_length=50, unique=True, blank=False, null=False, verbose_name=_('Short Name')) long_name = models.CharField(max_length=254, unique=True, blank=False, null=True, verbose_name=_('Long Name')) @@ -34,9 +34,9 @@ def __str__(self): class Position(models.Model): class Meta: verbose_name = _('Position') - constraints = [ + constraints = [ models.UniqueConstraint(fields=['employer', 'title', ], name='position_must_be_unique'), - ] + ] employer = models.ForeignKey(Employer, on_delete=models.CASCADE, verbose_name=_('Employer')) title = models.CharField(max_length=200, blank=False, null=False, verbose_name=_('Title')) @@ -71,7 +71,9 @@ class Meta: models.CheckConstraint(check=(models.Q(is_current_position__exact=False) | (models.Q(end_year__isnull=True) & models.Q(end_month__isnull=True) & models.Q(end_day__isnull=True))), name='leave_end_date_blank_if_current_position'), models.CheckConstraint(check=(models.Q(start_month__isnull=False) | models.Q(start_day__isnull=True)), name='require_start_month_if_start_day_specified'), models.CheckConstraint(check=(models.Q(end_year__isnull=False) | (models.Q(end_month__isnull=True) & models.Q(end_day__isnull=True))), name='require_end_year_if_end_month_specified'), - models.CheckConstraint(check=(models.Q(end_month__isnull=False) | models.Q(end_day__isnull=True)), name='require_end_month_if_end_day_specified') + models.CheckConstraint(check=(models.Q(end_month__isnull=False) | models.Q(end_day__isnull=True)), name='require_end_month_if_end_day_specified'), + models.UniqueConstraint(fields=['position', 'start_year', 'is_current_position'], name='job_time_period_must_be_unique_1'), + models.UniqueConstraint(fields=['position', 'start_year', 'end_year'], condition=models.Q(is_current_position__exact=False), name='job_time_period_start_and_end_year_must_be_unique_if_not_current_position'), ] position = models.ForeignKey(Position, on_delete=models.CASCADE, verbose_name=_('Position')) diff --git a/app/jobHistory/tests.py b/app/jobHistory/tests.py index 3dc7130..52c4dcf 100644 --- a/app/jobHistory/tests.py +++ b/app/jobHistory/tests.py @@ -1,4 +1,5 @@ from django.test import TestCase +from django.db import IntegrityError from .models import Employer, Position, JobTimePeriod # Create your tests here. @@ -27,4 +28,25 @@ def test_creating_job_time_periods(self): JobTimePeriod.objects.create(position=position3, start_year=2010, is_current_position=False, end_year=2015, starting_pay="$14.00/hour", ending_pay="$15.00/hour") JobTimePeriod.objects.create(position=position3, start_year=2015, is_current_position=True, starting_pay="$16.00/hour", ending_pay="$17.00/hour") + def test_creating_duplicate_employers(self): + Employer.objects.create(short_name="Employer4", long_name="Employer 4") + with self.assertRaises(IntegrityError): + Employer.objects.create(short_name="Employer4", long_name="Employer 4") + + def test_creating_duplicate_positions(self): + Employer.objects.create(short_name="Employer5", long_name="Employer 5") + emp = Employer.objects.get(short_name="Employer5") + Position.objects.create(employer=emp, title="Position 5", supervisor_given_name="John", supervisor_surname="Doe", can_contact=True) + with self.assertRaises(IntegrityError): + Position.objects.create(employer=emp, title="Position 5", supervisor_given_name="Jane", supervisor_surname="Doe", can_contact=False) + + def test_creating_duplicate_job_time_periods(self): + Employer.objects.create(short_name="Employer6", long_name="Employer 6") + emp = Employer.objects.get(short_name="Employer6") + Position.objects.create(employer=emp, title="Position 6", supervisor_given_name="Billy Joe", supervisor_surname="Jim Bob", can_contact=True) + position = Position.objects.get(employer=emp, title="Position 6") + JobTimePeriod.objects.create(position=position, start_year=2000, is_current_position=True, starting_pay="$10.00/hour", ending_pay="$17.00/hour") + with self.assertRaises(IntegrityError): + JobTimePeriod.objects.create(position=position, start_year=2000, is_current_position=True, starting_pay="$10.00/hour", ending_pay="$17.00/hour") + From 84deedbd1691e5069f1e45af257d372a3a9ba236 Mon Sep 17 00:00:00 2001 From: Stephen G Tuggy Date: Fri, 21 Aug 2020 15:49:22 -0700 Subject: [PATCH 11/14] fix: Fix the new JobTimePeriod uniqueness constraints -- not just year --- .../migrations/0011_auto_20200821_2244.py | 29 +++++++++++++++++++ app/jobHistory/models.py | 4 +-- app/jobHistory/tests.py | 15 ++++++++-- 3 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 app/jobHistory/migrations/0011_auto_20200821_2244.py diff --git a/app/jobHistory/migrations/0011_auto_20200821_2244.py b/app/jobHistory/migrations/0011_auto_20200821_2244.py new file mode 100644 index 0000000..31f0164 --- /dev/null +++ b/app/jobHistory/migrations/0011_auto_20200821_2244.py @@ -0,0 +1,29 @@ +# Generated by Django 2.2.15 on 2020-08-21 22:44 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('jobHistory', '0010_auto_20200821_2227'), + ] + + operations = [ + migrations.RemoveConstraint( + model_name='jobtimeperiod', + name='job_time_period_must_be_unique_1', + ), + migrations.RemoveConstraint( + model_name='jobtimeperiod', + name='job_time_period_start_and_end_year_must_be_unique_if_not_current_position', + ), + migrations.AddConstraint( + model_name='jobtimeperiod', + constraint=models.UniqueConstraint(fields=('position', 'start_year', 'start_month', 'start_day', 'is_current_position'), name='job_time_period_must_be_unique_A'), + ), + migrations.AddConstraint( + model_name='jobtimeperiod', + constraint=models.UniqueConstraint(condition=models.Q(is_current_position__exact=False), fields=('position', 'start_year', 'start_month', 'start_day', 'end_year', 'end_month', 'end_day'), name='job_time_period_start_and_end_date_must_be_unique_if_not_current_position'), + ), + ] diff --git a/app/jobHistory/models.py b/app/jobHistory/models.py index 64bffc7..9273498 100644 --- a/app/jobHistory/models.py +++ b/app/jobHistory/models.py @@ -72,8 +72,8 @@ class Meta: models.CheckConstraint(check=(models.Q(start_month__isnull=False) | models.Q(start_day__isnull=True)), name='require_start_month_if_start_day_specified'), models.CheckConstraint(check=(models.Q(end_year__isnull=False) | (models.Q(end_month__isnull=True) & models.Q(end_day__isnull=True))), name='require_end_year_if_end_month_specified'), models.CheckConstraint(check=(models.Q(end_month__isnull=False) | models.Q(end_day__isnull=True)), name='require_end_month_if_end_day_specified'), - models.UniqueConstraint(fields=['position', 'start_year', 'is_current_position'], name='job_time_period_must_be_unique_1'), - models.UniqueConstraint(fields=['position', 'start_year', 'end_year'], condition=models.Q(is_current_position__exact=False), name='job_time_period_start_and_end_year_must_be_unique_if_not_current_position'), + models.UniqueConstraint(fields=['position', 'start_year', 'start_month', 'start_day', 'is_current_position'], name='job_time_period_must_be_unique_A'), + models.UniqueConstraint(fields=['position', 'start_year', 'start_month', 'start_day', 'end_year', 'end_month', 'end_day'], condition=models.Q(is_current_position__exact=False), name='job_time_period_start_and_end_date_must_be_unique_if_not_current_position'), ] position = models.ForeignKey(Position, on_delete=models.CASCADE, verbose_name=_('Position')) diff --git a/app/jobHistory/tests.py b/app/jobHistory/tests.py index 52c4dcf..7dd6598 100644 --- a/app/jobHistory/tests.py +++ b/app/jobHistory/tests.py @@ -40,13 +40,22 @@ def test_creating_duplicate_positions(self): with self.assertRaises(IntegrityError): Position.objects.create(employer=emp, title="Position 5", supervisor_given_name="Jane", supervisor_surname="Doe", can_contact=False) - def test_creating_duplicate_job_time_periods(self): + def test_creating_duplicate_job_time_periods_A(self): Employer.objects.create(short_name="Employer6", long_name="Employer 6") emp = Employer.objects.get(short_name="Employer6") Position.objects.create(employer=emp, title="Position 6", supervisor_given_name="Billy Joe", supervisor_surname="Jim Bob", can_contact=True) position = Position.objects.get(employer=emp, title="Position 6") - JobTimePeriod.objects.create(position=position, start_year=2000, is_current_position=True, starting_pay="$10.00/hour", ending_pay="$17.00/hour") + JobTimePeriod.objects.create(position=position, start_year=2000, start_month=1, start_day=1, is_current_position=True, starting_pay="$10.00/hour", ending_pay="$17.00/hour") with self.assertRaises(IntegrityError): - JobTimePeriod.objects.create(position=position, start_year=2000, is_current_position=True, starting_pay="$10.00/hour", ending_pay="$17.00/hour") + JobTimePeriod.objects.create(position=position, start_year=2000, start_month=1, start_day=1, is_current_position=True, starting_pay="$10.00/hour", ending_pay="$17.00/hour") + + def test_creating_duplicate_job_time_periods_B(self): + Employer.objects.create(short_name="Employer7", long_name="Employer 7") + emp = Employer.objects.get(short_name="Employer7") + Position.objects.create(employer=emp, title="Position 7", supervisor_given_name="Billy Joe", supervisor_surname="Jim Bob", can_contact=True) + position = Position.objects.get(employer=emp, title="Position 7") + JobTimePeriod.objects.create(position=position, start_year=2000, start_month=1, start_day=1, is_current_position=False, end_year=2019, end_month=12, end_day=31, starting_pay="$10.00/hour", ending_pay="$17.00/hour") + with self.assertRaises(IntegrityError): + JobTimePeriod.objects.create(position=position, start_year=2000, start_month=1, start_day=1, is_current_position=False, end_year=2019, end_month=12, end_day=31, starting_pay="$10.00/hour", ending_pay="$17.00/hour") From dfc4bd1f7943061543823d5f0733a02af43aa1fa Mon Sep 17 00:00:00 2001 From: Stephen G Tuggy Date: Sat, 3 Oct 2020 10:59:31 -0700 Subject: [PATCH 12/14] Create shiftleft-analysis.yml --- .github/workflows/shiftleft-analysis.yml | 47 ++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .github/workflows/shiftleft-analysis.yml diff --git a/.github/workflows/shiftleft-analysis.yml b/.github/workflows/shiftleft-analysis.yml new file mode 100644 index 0000000..fe84925 --- /dev/null +++ b/.github/workflows/shiftleft-analysis.yml @@ -0,0 +1,47 @@ +# This workflow integrates Scan with GitHub's code scanning feature +# Scan is a free open-source security tool for modern DevOps teams from ShiftLeft +# Visit https://slscan.io/en/latest/integrations/code-scan for help +name: SL Scan + +# This section configures the trigger for the workflow. Feel free to customize depending on your convention +on: push + +jobs: + Scan-Build: + # Scan runs on ubuntu, mac and windows + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + # Instructions + # 1. Setup JDK, Node.js, Python etc depending on your project type + # 2. Compile or build the project before invoking scan + # Example: mvn compile, or npm install or pip install goes here + # 3. Invoke Scan with the github token. Leave the workspace empty to use relative url + + - name: Set up Python 3.7 + uses: actions/setup-python@v2 + with: + python-version: '3.7' # Version range or exact version of a Python version to use, using SemVer's version range syntax + architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified + + - name: Install Dependencies + run: | + python -m pip install --upgrade-strategy eager --upgrade pip + python -m pip install --upgrade-strategy eager --upgrade --use-feature=2020-resolver -r app/requirements.txt + + - name: Perform Scan + uses: ShiftLeftSecurity/scan-action@master + env: + WORKSPACE: "" + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SCAN_AUTO_BUILD: true + with: + output: reports + # Scan auto-detects the languages in your project. To override uncomment the below variable and set the type + # type: credscan,java + # type: python + + - name: Upload report + uses: github/codeql-action/upload-sarif@v1 + with: + sarif_file: reports From 1997ef0661ca7ad9f087249084f6f28d77967d7f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 19 Mar 2021 00:26:47 +0000 Subject: [PATCH 13/14] chore(deps): bump django from 2.2.15 to 2.2.18 in /app Bumps [django](https://github.com/django/django) from 2.2.15 to 2.2.18. - [Release notes](https://github.com/django/django/releases) - [Commits](https://github.com/django/django/compare/2.2.15...2.2.18) Signed-off-by: dependabot[bot] --- app/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/requirements.txt b/app/requirements.txt index 9455d77..3711c98 100644 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -1,6 +1,6 @@ astroid==2.4.2 colorama==0.4.3 -Django==2.2.15 +Django==2.2.18 django-environ==0.4.5 isort==4.3.21 lazy-object-proxy==1.4.3 From 8f522b5da5100bbe9c98c7ab86c955766c4b78bd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 8 Apr 2021 19:45:07 +0000 Subject: [PATCH 14/14] chore(deps): bump django from 2.2.18 to 2.2.20 in /app Bumps [django](https://github.com/django/django) from 2.2.18 to 2.2.20. - [Release notes](https://github.com/django/django/releases) - [Commits](https://github.com/django/django/compare/2.2.18...2.2.20) Signed-off-by: dependabot[bot] --- app/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/requirements.txt b/app/requirements.txt index 3711c98..7bb604a 100644 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -1,6 +1,6 @@ astroid==2.4.2 colorama==0.4.3 -Django==2.2.18 +Django==2.2.20 django-environ==0.4.5 isort==4.3.21 lazy-object-proxy==1.4.3