From ca4a86e20296b75ea4ee170c7935e65b33f5cc78 Mon Sep 17 00:00:00 2001 From: Nathan Workman Date: Thu, 5 Apr 2018 23:18:05 -0400 Subject: [PATCH 01/15] Setup, tox, pytest --- .gitignore | 30 ++++++++++++++++++++++++++---- requirements.in | 4 +++- requirements.txt | 11 ++++++++--- setup.py | 26 ++++++++++++++++++++++++++ tests/settings.py | 9 +++++++++ tox.ini | 16 ++++++++++++++++ 6 files changed, 88 insertions(+), 8 deletions(-) create mode 100644 setup.py create mode 100644 tests/settings.py create mode 100644 tox.ini diff --git a/.gitignore b/.gitignore index 3d1244d..9d97716 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,34 @@ + +# general things to ignore +build/ +dist/ +*.egg-info/ +*.egg +*.py[cod] +__pycache__/ +*.so +*~ /venv __pycache__ *.pyc *.sqlite3 +.DS_Store + +# due to using tox and pytest +.tox +.cache +.pytest_cache + +# node modules +/node_modules + +# project dist static files seeker/static seeker/media -/node_modules + +# project secrets +.env + +# due to ansible logs *.log *.retry -.env -.DS_Store -htmlcov diff --git a/requirements.in b/requirements.in index f094cb7..be08c6f 100644 --- a/requirements.in +++ b/requirements.in @@ -9,4 +9,6 @@ pip-tools==1.11.0 psycopg2==2.7.4 redis==2.10.6 Scrapy==1.5.0 -scrapy-djangoitem==1.1.1 \ No newline at end of file +scrapy-djangoitem==1.1.1 +pytest==3.5.0 +pytest-django==3.1.2 diff --git a/requirements.txt b/requirements.txt index dfad2c7..fa9b7f5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,7 +6,7 @@ # amqp==2.2.2 # via kombu asn1crypto==0.24.0 # via cryptography -attrs==17.4.0 # via automat, service-identity +attrs==17.4.0 # via automat, pytest, service-identity automat==0.6.0 # via twisted billiard==3.5.0.3 # via celery celery==4.1.0 @@ -15,7 +15,7 @@ cffi==1.11.5 # via cryptography chardet==3.0.4 # via requests click==6.7 # via pip-tools constantly==15.1.0 # via twisted -cryptography==2.2.1 # via pyopenssl +cryptography==2.2.2 # via pyopenssl cssselect==1.0.3 # via parsel, scrapy django-anymail==2.0 django-debug-toolbar==1.9.1 @@ -29,14 +29,19 @@ idna==2.6 # via cryptography, hyperlink, requests incremental==17.5.0 # via twisted kombu==4.1.0 # via celery lxml==4.2.1 # via parsel, scrapy +more-itertools==4.1.0 # via pytest parsel==1.4.0 # via scrapy pip-tools==1.11.0 +pluggy==0.6.0 # via pytest psycopg2==2.7.4 +py==1.5.3 # via pytest pyasn1-modules==0.2.1 # via service-identity pyasn1==0.4.2 # via pyasn1-modules, service-identity pycparser==2.18 # via cffi pydispatcher==2.0.5 # via scrapy pyopenssl==17.5.0 # via scrapy, service-identity +pytest-django==3.1.2 +pytest==3.5.0 pytz==2018.3 # via celery, django queuelib==1.5.0 # via scrapy redis==2.10.6 @@ -44,7 +49,7 @@ requests==2.18.4 # via django-anymail scrapy-djangoitem==1.1.1 scrapy==1.5.0 service-identity==17.0.0 # via scrapy -six==1.11.0 # via automat, cryptography, django-anymail, parsel, pip-tools, pyopenssl, scrapy, scrapy-djangoitem, w3lib +six==1.11.0 # via automat, cryptography, django-anymail, more-itertools, parsel, pip-tools, pyopenssl, pytest, scrapy, scrapy-djangoitem, w3lib sqlparse==0.2.4 # via django-debug-toolbar twisted==17.9.0 # via scrapy urllib3==1.22 # via requests diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..b15f356 --- /dev/null +++ b/setup.py @@ -0,0 +1,26 @@ +from setuptools import setup, find_packages + +setup( + name='seeker', + version='0.2.0', + author=u'Nathan Workman', + author_email='nathancworkman@gmail.com', + url='https://github.com/NathanWorkman/seeker.git', + packages=find_packages(), + requires=['scrapy (>=1.5.0)', 'django(>=2.0.0)'], + classifiers=[ + 'Development Status :: 2 - Pre-Alpha', + 'Environment :: Console', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: BSD License', + 'Operating System :: OS Independent', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Topic :: Utilities', + 'Framework :: Django', + 'Framework :: Scrapy', + ], + zip_safe=False, +) diff --git a/tests/settings.py b/tests/settings.py new file mode 100644 index 0000000..a9f4919 --- /dev/null +++ b/tests/settings.py @@ -0,0 +1,9 @@ + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': ':memory:', + } +} + +SECRET_KEY = 'super-secret-key' diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..a29f7b2 --- /dev/null +++ b/tox.ini @@ -0,0 +1,16 @@ +# Tox (http://tox.testrun.org/) is a tool for running tests +# in multiple virtualenvs. This configuration file will run the +# test suite on all supported python versions. To use it, "pip install tox" +# and then run "tox" from this directory. + +[tox] +envlist = + py3 + flake8 + +[testenv:py3] +basepython = python3.6 +deps = + -r requirements.txt +commands = + py.test {posargs:tests} From faee13e0a0f7b19d221752eebd03aee5ed8d888f Mon Sep 17 00:00:00 2001 From: Nathan Workman Date: Thu, 5 Apr 2018 23:51:06 -0400 Subject: [PATCH 02/15] Flake8 --- requirements.in | 1 + requirements.txt | 4 +++ seeker/companies/tests.py | 3 --- seeker/jobs/admin.py | 11 +++----- seeker/jobs/models.py | 10 +++---- seeker/jobs/tests.py | 3 --- seeker/scraper/pipelines.py | 6 +---- seeker/scraper/settings.py | 52 ++++++++++++++++++------------------- seeker/seeker/settings.py | 1 - tox.ini | 21 +++++++++++++++ 10 files changed, 61 insertions(+), 51 deletions(-) delete mode 100644 seeker/companies/tests.py delete mode 100644 seeker/jobs/tests.py diff --git a/requirements.in b/requirements.in index be08c6f..4354d0b 100644 --- a/requirements.in +++ b/requirements.in @@ -12,3 +12,4 @@ Scrapy==1.5.0 scrapy-djangoitem==1.1.1 pytest==3.5.0 pytest-django==3.1.2 +flake8==3.5.0 diff --git a/requirements.txt b/requirements.txt index fa9b7f5..6b593a9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,12 +23,14 @@ django-dotenv==1.4.2 django-widget-tweaks==1.4.1 django==2.0.3 first==2.0.1 # via pip-tools +flake8==3.5.0 gunicorn==19.7.1 hyperlink==18.0.0 # via twisted idna==2.6 # via cryptography, hyperlink, requests incremental==17.5.0 # via twisted kombu==4.1.0 # via celery lxml==4.2.1 # via parsel, scrapy +mccabe==0.6.1 # via flake8 more-itertools==4.1.0 # via pytest parsel==1.4.0 # via scrapy pip-tools==1.11.0 @@ -37,8 +39,10 @@ psycopg2==2.7.4 py==1.5.3 # via pytest pyasn1-modules==0.2.1 # via service-identity pyasn1==0.4.2 # via pyasn1-modules, service-identity +pycodestyle==2.3.1 # via flake8 pycparser==2.18 # via cffi pydispatcher==2.0.5 # via scrapy +pyflakes==1.6.0 # via flake8 pyopenssl==17.5.0 # via scrapy, service-identity pytest-django==3.1.2 pytest==3.5.0 diff --git a/seeker/companies/tests.py b/seeker/companies/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/seeker/companies/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/seeker/jobs/admin.py b/seeker/jobs/admin.py index 4f29d12..9683ded 100644 --- a/seeker/jobs/admin.py +++ b/seeker/jobs/admin.py @@ -3,14 +3,9 @@ from .models import Job, Board -# class BoardAdmin(admin.ModelAdmin): -# list_display = ('title',) +class BoardAdmin(admin.ModelAdmin): + list_display = ('scrape_date',) -# class JobAdmin(admin.ModelAdmin): - # list_display = ('scrape_date',) - - -# admin.site.register(Board, BoardAdmin) +admin.site.register(Board, BoardAdmin) admin.site.register(Job) -admin.site.register(Board) diff --git a/seeker/jobs/models.py b/seeker/jobs/models.py index a629851..d71a2d4 100644 --- a/seeker/jobs/models.py +++ b/seeker/jobs/models.py @@ -27,11 +27,11 @@ class Job(models.Model): on_delete=models.CASCADE ) company = models.ForeignKey( - Company, - blank=True, - null=True, - on_delete=models.SET_NULL - ) + Company, + blank=True, + null=True, + on_delete=models.SET_NULL + ) body = models.TextField() url = models.URLField("URL") pub_date = models.TextField() diff --git a/seeker/jobs/tests.py b/seeker/jobs/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/seeker/jobs/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/seeker/scraper/pipelines.py b/seeker/scraper/pipelines.py index e86d4d4..b33ff89 100644 --- a/seeker/scraper/pipelines.py +++ b/seeker/scraper/pipelines.py @@ -5,10 +5,6 @@ # Don't forget to add your pipeline to the ITEM_PIPELINES setting # See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html -import re -from datetime import datetime - -import pytz from django.utils.text import slugify from scrapy.exceptions import DropItem @@ -40,7 +36,7 @@ def process_item(self, item, spider): """ For every job that we create, delete the oldest job """ - # TODO: possibly remove this and just keep a large index of + # TODO: possibly remove this and just keep a large index of # job = Job.objects.all().last() # job.delete() diff --git a/seeker/scraper/settings.py b/seeker/scraper/settings.py index 583eafe..45a69d3 100644 --- a/seeker/scraper/settings.py +++ b/seeker/scraper/settings.py @@ -18,78 +18,78 @@ # Crawl responsibly by identifying yourself (and your website) on the user-agent -#USER_AGENT = 'scraper (+http://www.yourdomain.com)' +# USER_AGENT = 'scraper (+http://www.yourdomain.com)' # Obey robots.txt rules ROBOTSTXT_OBEY = False # Configure maximum concurrent requests performed by Scrapy (default: 16) -#CONCURRENT_REQUESTS = 32 +# CONCURRENT_REQUESTS = 32 # Configure a delay for requests for the same website (default: 0) # See https://doc.scrapy.org/en/latest/topics/settings.html#download-delay # See also autothrottle settings and docs -#DOWNLOAD_DELAY = 3 +# DOWNLOAD_DELAY = 3 # The download delay setting will honor only one of: -#CONCURRENT_REQUESTS_PER_DOMAIN = 16 -#CONCURRENT_REQUESTS_PER_IP = 16 +# CONCURRENT_REQUESTS_PER_DOMAIN = 16 +# CONCURRENT_REQUESTS_PER_IP = 16 # Disable cookies (enabled by default) -#COOKIES_ENABLED = False +# COOKIES_ENABLED = False # Disable Telnet Console (enabled by default) -#TELNETCONSOLE_ENABLED = False +# TELNETCONSOLE_ENABLED = False # Override the default request headers: -#DEFAULT_REQUEST_HEADERS = { +# DEFAULT_REQUEST_HEADERS = { # 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', # 'Accept-Language': 'en', -#} +# } # Enable or disable spider middlewares # See https://doc.scrapy.org/en/latest/topics/spider-middleware.html -#SPIDER_MIDDLEWARES = { +# SPIDER_MIDDLEWARES = { # 'scraper.middlewares.ScraperSpiderMiddleware': 543, -#} +# } # Enable or disable downloader middlewares # See https://doc.scrapy.org/en/latest/topics/downloader-middleware.html -#DOWNLOADER_MIDDLEWARES = { +# DOWNLOADER_MIDDLEWARES = { # 'scraper.middlewares.ScraperDownloaderMiddleware': 543, -#} +# } # Enable or disable extensions # See https://doc.scrapy.org/en/latest/topics/extensions.html -#EXTENSIONS = { +# EXTENSIONS = { # 'scrapy.extensions.telnet.TelnetConsole': None, -#} +# } # Configure item pipelines # See https://doc.scrapy.org/en/latest/topics/item-pipeline.html ITEM_PIPELINES = { - 'scraper.pipelines.JobsPipeline': 300, + 'scraper.pipelines.JobsPipeline': 300, } # Enable and configure the AutoThrottle extension (disabled by default) # See https://doc.scrapy.org/en/latest/topics/autothrottle.html -#AUTOTHROTTLE_ENABLED = True +# AUTOTHROTTLE_ENABLED = True # The initial download delay -#AUTOTHROTTLE_START_DELAY = 5 +# AUTOTHROTTLE_START_DELAY = 5 # The maximum download delay to be set in case of high latencies -#AUTOTHROTTLE_MAX_DELAY = 60 +# AUTOTHROTTLE_MAX_DELAY = 60 # The average number of requests Scrapy should be sending in parallel to # each remote server -#AUTOTHROTTLE_TARGET_CONCURRENCY = 1.0 +# AUTOTHROTTLE_TARGET_CONCURRENCY = 1.0 # Enable showing throttling stats for every response received: -#AUTOTHROTTLE_DEBUG = False +# AUTOTHROTTLE_DEBUG = False # Enable and configure HTTP caching (disabled by default) # See https://doc.scrapy.org/en/latest/topics/downloader-middleware.html#httpcache-middleware-settings -#HTTPCACHE_ENABLED = True -#HTTPCACHE_EXPIRATION_SECS = 0 -#HTTPCACHE_DIR = 'httpcache' -#HTTPCACHE_IGNORE_HTTP_CODES = [] -#HTTPCACHE_STORAGE = 'scrapy.extensions.httpcache.FilesystemCacheStorage' +# HTTPCACHE_ENABLED = True +# HTTPCACHE_EXPIRATION_SECS = 0 +# HTTPCACHE_DIR = 'httpcache' +# HTTPCACHE_IGNORE_HTTP_CODES = [] +# HTTPCACHE_STORAGE = 'scrapy.extensions.httpcache.FilesystemCacheStorage' # http://doc.scrapy.org/en/latest/topics/djangoitem.html#django-settings-set-up diff --git a/seeker/seeker/settings.py b/seeker/seeker/settings.py index 81dfc2b..5d81f30 100644 --- a/seeker/seeker/settings.py +++ b/seeker/seeker/settings.py @@ -143,4 +143,3 @@ MEDIAFILES_LOCATION = 'media' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_URL = '/media/' - diff --git a/tox.ini b/tox.ini index a29f7b2..8c7343f 100644 --- a/tox.ini +++ b/tox.ini @@ -8,9 +8,30 @@ envlist = py3 flake8 +[flake8] +# D100: Missing docstring in public module +# D101: Missing docstring in public class +# D102: Missing docstring in public method +# D103: Missing docstring in public function +# D105: Missing docstring in magic method +# D200: One-line docstring should fit on one line with quotes +# D202: No blank lines allowed after function docstring +# D400: First line should end with a period +# D401: First line should be in imperative mood +# E501: Line too long +# N805: First argument of a method should be named 'self' +# N806: Variable in function should be lowercase +ignore = D100,D101,D102,D103,D105,D200,D202,D400,D401,E501,N805,N806 + [testenv:py3] basepython = python3.6 deps = -r requirements.txt commands = py.test {posargs:tests} + + +[testenv:flake8] +basepython=python3.6 +deps=flake8>=2.2.0 +commands=flake8 From fb35895714df857f9c649490d74a7e0bf36674d9 Mon Sep 17 00:00:00 2001 From: Nathan Workman Date: Fri, 6 Apr 2018 00:01:09 -0400 Subject: [PATCH 03/15] Update flake8 version --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 8c7343f..3e21f29 100644 --- a/tox.ini +++ b/tox.ini @@ -33,5 +33,5 @@ commands = [testenv:flake8] basepython=python3.6 -deps=flake8>=2.2.0 +deps=flake8>=3.5.0 commands=flake8 From d5a42d4acfbd8290ab2ca46a1c4cfeebc395e938 Mon Sep 17 00:00:00 2001 From: Nathan Workman Date: Fri, 6 Apr 2018 00:20:22 -0400 Subject: [PATCH 04/15] travis --- .travis.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..c81bece --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ +language: python +python: + - "3.3" + - "3.4" + - "3.5" + - "3.6" +# command to install dependencies +install: + - pip install -r requirements.txt +# command to run tests +script: + - tox # or py.test for Python versions 3.5 and below From 7303501939529354494dc865ae12c6dcb94c73c9 Mon Sep 17 00:00:00 2001 From: Nathan Workman Date: Fri, 6 Apr 2018 00:26:08 -0400 Subject: [PATCH 05/15] Only test on 3.5 for now --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index c81bece..e95402c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,6 @@ language: python python: - - "3.3" - - "3.4" - "3.5" - - "3.6" # command to install dependencies install: - pip install -r requirements.txt From c8b31f2b178edc956904b54e00282961792b9c7f Mon Sep 17 00:00:00 2001 From: Nathan Workman Date: Fri, 6 Apr 2018 00:42:21 -0400 Subject: [PATCH 06/15] singular --- seeker/companies/apps.py | 5 ----- seeker/{companies => company}/__init__.py | 0 seeker/{companies => company}/admin.py | 0 seeker/company/apps.py | 5 +++++ .../{companies => company}/migrations/0001_initial.py | 2 +- seeker/{companies => company}/migrations/__init__.py | 0 seeker/{companies => company}/models.py | 0 seeker/{companies => company}/urls.py | 0 seeker/{companies => company}/views.py | 0 seeker/{jobs => job}/__init__.py | 0 seeker/job/admin.py | 6 ++++++ seeker/job/apps.py | 5 +++++ seeker/{jobs => job}/migrations/0001_initial.py | 10 +++++----- seeker/{jobs => job}/migrations/__init__.py | 0 seeker/{jobs => job}/models.py | 2 +- seeker/{jobs => job}/urls.py | 0 seeker/{jobs => job}/views.py | 0 seeker/jobs/admin.py | 11 ----------- seeker/jobs/apps.py | 5 ----- seeker/seeker/settings.py | 4 ++-- .../{companies => company}/company_detail.html | 0 .../{companies => company}/company_list.html | 0 seeker/seeker/templates/{jobs => job}/job_detail.html | 0 seeker/seeker/templates/{jobs => job}/job_list.html | 0 seeker/seeker/urls.py | 4 ++-- tests/__init__.py | 0 tests/test_jobs.py | 1 + tox.ini | 1 + 28 files changed, 29 insertions(+), 32 deletions(-) delete mode 100644 seeker/companies/apps.py rename seeker/{companies => company}/__init__.py (100%) rename seeker/{companies => company}/admin.py (100%) create mode 100644 seeker/company/apps.py rename seeker/{companies => company}/migrations/0001_initial.py (93%) rename seeker/{companies => company}/migrations/__init__.py (100%) rename seeker/{companies => company}/models.py (100%) rename seeker/{companies => company}/urls.py (100%) rename seeker/{companies => company}/views.py (100%) rename seeker/{jobs => job}/__init__.py (100%) create mode 100644 seeker/job/admin.py create mode 100644 seeker/job/apps.py rename seeker/{jobs => job}/migrations/0001_initial.py (85%) rename seeker/{jobs => job}/migrations/__init__.py (100%) rename seeker/{jobs => job}/models.py (97%) rename seeker/{jobs => job}/urls.py (100%) rename seeker/{jobs => job}/views.py (100%) delete mode 100644 seeker/jobs/admin.py delete mode 100644 seeker/jobs/apps.py rename seeker/seeker/templates/{companies => company}/company_detail.html (100%) rename seeker/seeker/templates/{companies => company}/company_list.html (100%) rename seeker/seeker/templates/{jobs => job}/job_detail.html (100%) rename seeker/seeker/templates/{jobs => job}/job_list.html (100%) create mode 100644 tests/__init__.py create mode 100644 tests/test_jobs.py diff --git a/seeker/companies/apps.py b/seeker/companies/apps.py deleted file mode 100644 index 0acc248..0000000 --- a/seeker/companies/apps.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.apps import AppConfig - - -class CompaniesConfig(AppConfig): - name = 'companies' diff --git a/seeker/companies/__init__.py b/seeker/company/__init__.py similarity index 100% rename from seeker/companies/__init__.py rename to seeker/company/__init__.py diff --git a/seeker/companies/admin.py b/seeker/company/admin.py similarity index 100% rename from seeker/companies/admin.py rename to seeker/company/admin.py diff --git a/seeker/company/apps.py b/seeker/company/apps.py new file mode 100644 index 0000000..3d1e229 --- /dev/null +++ b/seeker/company/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class CompanyConfig(AppConfig): + name = 'company' diff --git a/seeker/companies/migrations/0001_initial.py b/seeker/company/migrations/0001_initial.py similarity index 93% rename from seeker/companies/migrations/0001_initial.py rename to seeker/company/migrations/0001_initial.py index 9669925..260cb55 100644 --- a/seeker/companies/migrations/0001_initial.py +++ b/seeker/company/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 2.0.3 on 2018-03-27 00:40 +# Generated by Django 2.0.3 on 2018-04-06 04:39 from django.db import migrations, models diff --git a/seeker/companies/migrations/__init__.py b/seeker/company/migrations/__init__.py similarity index 100% rename from seeker/companies/migrations/__init__.py rename to seeker/company/migrations/__init__.py diff --git a/seeker/companies/models.py b/seeker/company/models.py similarity index 100% rename from seeker/companies/models.py rename to seeker/company/models.py diff --git a/seeker/companies/urls.py b/seeker/company/urls.py similarity index 100% rename from seeker/companies/urls.py rename to seeker/company/urls.py diff --git a/seeker/companies/views.py b/seeker/company/views.py similarity index 100% rename from seeker/companies/views.py rename to seeker/company/views.py diff --git a/seeker/jobs/__init__.py b/seeker/job/__init__.py similarity index 100% rename from seeker/jobs/__init__.py rename to seeker/job/__init__.py diff --git a/seeker/job/admin.py b/seeker/job/admin.py new file mode 100644 index 0000000..c3cd9e5 --- /dev/null +++ b/seeker/job/admin.py @@ -0,0 +1,6 @@ +from django.contrib import admin + +from .models import Job, Board + +admin.site.register(Board) +admin.site.register(Job) diff --git a/seeker/job/apps.py b/seeker/job/apps.py new file mode 100644 index 0000000..0d8f10f --- /dev/null +++ b/seeker/job/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class JobConfig(AppConfig): + name = 'job' diff --git a/seeker/jobs/migrations/0001_initial.py b/seeker/job/migrations/0001_initial.py similarity index 85% rename from seeker/jobs/migrations/0001_initial.py rename to seeker/job/migrations/0001_initial.py index 0055391..4dedbc3 100644 --- a/seeker/jobs/migrations/0001_initial.py +++ b/seeker/job/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 2.0.3 on 2018-03-27 00:40 +# Generated by Django 2.0.3 on 2018-04-06 04:39 from django.db import migrations, models import django.db.models.deletion @@ -9,7 +9,7 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ('companies', '0001_initial'), + ('company', '0001_initial'), ] operations = [ @@ -36,11 +36,11 @@ class Migration(migrations.Migration): ('scrape_date', models.DateTimeField()), ('salary', models.TextField()), ('location', models.TextField()), - ('board', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='jobs.Board')), - ('company', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='companies.Company')), + ('board', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='job.Board')), + ('company', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='company.Company')), ], options={ - 'ordering': ['-pub_date'], + 'ordering': ['-scrape_date'], }, ), ] diff --git a/seeker/jobs/migrations/__init__.py b/seeker/job/migrations/__init__.py similarity index 100% rename from seeker/jobs/migrations/__init__.py rename to seeker/job/migrations/__init__.py diff --git a/seeker/jobs/models.py b/seeker/job/models.py similarity index 97% rename from seeker/jobs/models.py rename to seeker/job/models.py index d71a2d4..b9b91d4 100644 --- a/seeker/jobs/models.py +++ b/seeker/job/models.py @@ -2,7 +2,7 @@ from django.urls import reverse from django.db import models -from companies.models import Company +from company.models import Company class Board(models.Model): diff --git a/seeker/jobs/urls.py b/seeker/job/urls.py similarity index 100% rename from seeker/jobs/urls.py rename to seeker/job/urls.py diff --git a/seeker/jobs/views.py b/seeker/job/views.py similarity index 100% rename from seeker/jobs/views.py rename to seeker/job/views.py diff --git a/seeker/jobs/admin.py b/seeker/jobs/admin.py deleted file mode 100644 index 9683ded..0000000 --- a/seeker/jobs/admin.py +++ /dev/null @@ -1,11 +0,0 @@ -from django.contrib import admin - -from .models import Job, Board - - -class BoardAdmin(admin.ModelAdmin): - list_display = ('scrape_date',) - - -admin.site.register(Board, BoardAdmin) -admin.site.register(Job) diff --git a/seeker/jobs/apps.py b/seeker/jobs/apps.py deleted file mode 100644 index 14c323a..0000000 --- a/seeker/jobs/apps.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.apps import AppConfig - - -class JobsConfig(AppConfig): - name = 'jobs' diff --git a/seeker/seeker/settings.py b/seeker/seeker/settings.py index 5d81f30..dbcc246 100644 --- a/seeker/seeker/settings.py +++ b/seeker/seeker/settings.py @@ -42,8 +42,8 @@ 'debug_toolbar', 'widget_tweaks', - 'jobs', - 'companies', + 'job', + 'company', ] MIDDLEWARE = [ diff --git a/seeker/seeker/templates/companies/company_detail.html b/seeker/seeker/templates/company/company_detail.html similarity index 100% rename from seeker/seeker/templates/companies/company_detail.html rename to seeker/seeker/templates/company/company_detail.html diff --git a/seeker/seeker/templates/companies/company_list.html b/seeker/seeker/templates/company/company_list.html similarity index 100% rename from seeker/seeker/templates/companies/company_list.html rename to seeker/seeker/templates/company/company_list.html diff --git a/seeker/seeker/templates/jobs/job_detail.html b/seeker/seeker/templates/job/job_detail.html similarity index 100% rename from seeker/seeker/templates/jobs/job_detail.html rename to seeker/seeker/templates/job/job_detail.html diff --git a/seeker/seeker/templates/jobs/job_list.html b/seeker/seeker/templates/job/job_list.html similarity index 100% rename from seeker/seeker/templates/jobs/job_list.html rename to seeker/seeker/templates/job/job_list.html diff --git a/seeker/seeker/urls.py b/seeker/seeker/urls.py index 21dbd52..c4ff73e 100644 --- a/seeker/seeker/urls.py +++ b/seeker/seeker/urls.py @@ -23,6 +23,6 @@ path('admin/', admin.site.urls), path('', HomeView.as_view(), name='home'), path('about/', AboutView.as_view(), name='about'), - path('jobs/', include('jobs.urls')), - path('companies/', include('companies.urls')) + path('jobs/', include('job.urls')), + path('companies/', include('company.urls')) ] diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_jobs.py b/tests/test_jobs.py new file mode 100644 index 0000000..46f21db --- /dev/null +++ b/tests/test_jobs.py @@ -0,0 +1 @@ +from seeker.jobs import models diff --git a/tox.ini b/tox.ini index 3e21f29..2cd05b1 100644 --- a/tox.ini +++ b/tox.ini @@ -25,6 +25,7 @@ ignore = D100,D101,D102,D103,D105,D200,D202,D400,D401,E501,N805,N806 [testenv:py3] basepython = python3.6 +passenv = DISPLAY XAUTHORITY deps = -r requirements.txt commands = From 584828b4592bac7ce71a4d86947ceae59c87bca6 Mon Sep 17 00:00:00 2001 From: Nathan Workman Date: Fri, 6 Apr 2018 00:45:52 -0400 Subject: [PATCH 07/15] add tox to requirements --- requirements.in | 1 + requirements.txt | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/requirements.in b/requirements.in index 4354d0b..fc63526 100644 --- a/requirements.in +++ b/requirements.in @@ -13,3 +13,4 @@ scrapy-djangoitem==1.1.1 pytest==3.5.0 pytest-django==3.1.2 flake8==3.5.0 +tox==3.0.0 diff --git a/requirements.txt b/requirements.txt index 6b593a9..13f5a66 100644 --- a/requirements.txt +++ b/requirements.txt @@ -34,9 +34,9 @@ mccabe==0.6.1 # via flake8 more-itertools==4.1.0 # via pytest parsel==1.4.0 # via scrapy pip-tools==1.11.0 -pluggy==0.6.0 # via pytest +pluggy==0.6.0 # via pytest, tox psycopg2==2.7.4 -py==1.5.3 # via pytest +py==1.5.3 # via pytest, tox pyasn1-modules==0.2.1 # via service-identity pyasn1==0.4.2 # via pyasn1-modules, service-identity pycodestyle==2.3.1 # via flake8 @@ -53,10 +53,12 @@ requests==2.18.4 # via django-anymail scrapy-djangoitem==1.1.1 scrapy==1.5.0 service-identity==17.0.0 # via scrapy -six==1.11.0 # via automat, cryptography, django-anymail, more-itertools, parsel, pip-tools, pyopenssl, pytest, scrapy, scrapy-djangoitem, w3lib +six==1.11.0 # via automat, cryptography, django-anymail, more-itertools, parsel, pip-tools, pyopenssl, pytest, scrapy, scrapy-djangoitem, tox, w3lib sqlparse==0.2.4 # via django-debug-toolbar +tox==3.0.0 twisted==17.9.0 # via scrapy urllib3==1.22 # via requests vine==1.1.4 # via amqp +virtualenv==15.2.0 # via tox w3lib==1.19.0 # via parsel, scrapy zope.interface==4.4.3 # via twisted From ac8fb193568bd78a31c43e36f17cc9fb663de5eb Mon Sep 17 00:00:00 2001 From: Nathan Workman Date: Fri, 6 Apr 2018 10:37:15 -0400 Subject: [PATCH 08/15] pytest python path --- requirements.in | 1 + requirements.txt | 1 + seeker/scraper/items.py | 2 +- seeker/scraper/pipelines.py | 4 ++-- tests/factories.py | 19 +++++++++++++++++++ tests/test_jobs.py | 10 +++++++++- tests/{settings.py => test_settings.py} | 3 +++ tox.ini | 12 +++++++----- 8 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 tests/factories.py rename tests/{settings.py => test_settings.py} (68%) diff --git a/requirements.in b/requirements.in index fc63526..6e4a024 100644 --- a/requirements.in +++ b/requirements.in @@ -12,5 +12,6 @@ Scrapy==1.5.0 scrapy-djangoitem==1.1.1 pytest==3.5.0 pytest-django==3.1.2 +pytest-pythonpath==0.7.2 flake8==3.5.0 tox==3.0.0 diff --git a/requirements.txt b/requirements.txt index 13f5a66..42475cf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -45,6 +45,7 @@ pydispatcher==2.0.5 # via scrapy pyflakes==1.6.0 # via flake8 pyopenssl==17.5.0 # via scrapy, service-identity pytest-django==3.1.2 +pytest-pythonpath==0.7.2 pytest==3.5.0 pytz==2018.3 # via celery, django queuelib==1.5.0 # via scrapy diff --git a/seeker/scraper/items.py b/seeker/scraper/items.py index 74efe4f..46ac4d5 100644 --- a/seeker/scraper/items.py +++ b/seeker/scraper/items.py @@ -8,7 +8,7 @@ import scrapy from scrapy_djangoitem import DjangoItem -from jobs.models import Job +from job.models import Job class JobItem(DjangoItem): diff --git a/seeker/scraper/pipelines.py b/seeker/scraper/pipelines.py index b33ff89..8cf902b 100644 --- a/seeker/scraper/pipelines.py +++ b/seeker/scraper/pipelines.py @@ -8,8 +8,8 @@ from django.utils.text import slugify from scrapy.exceptions import DropItem -from jobs.models import Job, Board -from companies.models import Company +from job.models import Job, Board +from company.models import Company class JobsPipeline(object): diff --git a/tests/factories.py b/tests/factories.py new file mode 100644 index 0000000..56f1254 --- /dev/null +++ b/tests/factories.py @@ -0,0 +1,19 @@ +import factory +from seeker.job.models import Board, Job + + +class BoardFactory(factory.DjangoModelFactory): + """ + Define Board Factory + """ + class Meta: + model = Board + + +class JobFactory(factory.DjangoModelFactory): + """ + Define Job Factory + """ + class Meta: + model = Job + customer = factory.SubFactory(BoardFactory) diff --git a/tests/test_jobs.py b/tests/test_jobs.py index 46f21db..89f92f5 100644 --- a/tests/test_jobs.py +++ b/tests/test_jobs.py @@ -1 +1,9 @@ -from seeker.jobs import models +# import pytest +from seeker.job import models + + +def test_django(): + # from base.settings import settings as base_settings + from django.conf import settings as django_settings + print(django_settings.xxx) + assert 3 == 5 diff --git a/tests/settings.py b/tests/test_settings.py similarity index 68% rename from tests/settings.py rename to tests/test_settings.py index a9f4919..6794987 100644 --- a/tests/settings.py +++ b/tests/test_settings.py @@ -1,3 +1,6 @@ +import os + +os.environ['DJANGO_SETTINGS_MODULE'] = 'seeker.settings' DATABASES = { 'default': { diff --git a/tox.ini b/tox.ini index 2cd05b1..fd6e39e 100644 --- a/tox.ini +++ b/tox.ini @@ -8,6 +8,11 @@ envlist = py3 flake8 +[pytest] +DJANGO_SETTINGS_MODULE = seeker.seeker.settings +# -- recommended but optional: +python_files = tests.py test_*.py *_tests.py + [flake8] # D100: Missing docstring in public module # D101: Missing docstring in public class @@ -25,11 +30,8 @@ ignore = D100,D101,D102,D103,D105,D200,D202,D400,D401,E501,N805,N806 [testenv:py3] basepython = python3.6 -passenv = DISPLAY XAUTHORITY -deps = - -r requirements.txt -commands = - py.test {posargs:tests} +deps = -r requirements.txt +commands = pytest [testenv:flake8] From 5fad4b65d07e0565adf8990805512accf19fa80e Mon Sep 17 00:00:00 2001 From: Nathan Workman Date: Fri, 6 Apr 2018 10:41:23 -0400 Subject: [PATCH 09/15] generic --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e95402c..272469d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -language: python +language: generic python: - "3.5" # command to install dependencies From e01a4cf7a75258f98b1d09eac17217a80c0ac44e Mon Sep 17 00:00:00 2001 From: Nathan Workman Date: Fri, 6 Apr 2018 10:43:00 -0400 Subject: [PATCH 10/15] matrix --- .travis.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 272469d..bdce3a7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,11 @@ language: generic -python: - - "3.5" + +matrix: + include: + - python: 3.6 + env: TOXENV=flake8 + - python: 3.6 + env: TOXENV=py3 # command to install dependencies install: - pip install -r requirements.txt From 47e0a503266e67446a9643ad564e361ccf72dbb7 Mon Sep 17 00:00:00 2001 From: Nathan Workman Date: Fri, 6 Apr 2018 13:36:15 -0400 Subject: [PATCH 11/15] tox amnd travis --- .travis.yml | 17 +++++++---------- requirements.in | 1 - tests/conftest.py | 0 tests/factories.py | 30 +++++++++++++++--------------- tests/test_jobs.py | 2 +- tox.ini | 38 +++++++++++++++++++++----------------- 6 files changed, 44 insertions(+), 44 deletions(-) create mode 100644 tests/conftest.py diff --git a/.travis.yml b/.travis.yml index bdce3a7..87af8ec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,11 @@ -language: generic +language: python + +python: + - "3.6" -matrix: - include: - - python: 3.6 - env: TOXENV=flake8 - - python: 3.6 - env: TOXENV=py3 -# command to install dependencies install: - pip install -r requirements.txt -# command to run tests + - pip install tox-travis + script: - - tox # or py.test for Python versions 3.5 and below + - tox diff --git a/requirements.in b/requirements.in index 6e4a024..fc63526 100644 --- a/requirements.in +++ b/requirements.in @@ -12,6 +12,5 @@ Scrapy==1.5.0 scrapy-djangoitem==1.1.1 pytest==3.5.0 pytest-django==3.1.2 -pytest-pythonpath==0.7.2 flake8==3.5.0 tox==3.0.0 diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/factories.py b/tests/factories.py index 56f1254..98b4d2d 100644 --- a/tests/factories.py +++ b/tests/factories.py @@ -1,19 +1,19 @@ -import factory -from seeker.job.models import Board, Job +# import factory +# from seeker.job.models import Board, Job -class BoardFactory(factory.DjangoModelFactory): - """ - Define Board Factory - """ - class Meta: - model = Board +# class BoardFactory(factory.DjangoModelFactory): +# """ +# Define Board Factory +# """ +# class Meta: +# model = Board -class JobFactory(factory.DjangoModelFactory): - """ - Define Job Factory - """ - class Meta: - model = Job - customer = factory.SubFactory(BoardFactory) +# class JobFactory(factory.DjangoModelFactory): +# """ +# Define Job Factory +# """ +# class Meta: +# model = Job +# customer = factory.SubFactory(BoardFactory) diff --git a/tests/test_jobs.py b/tests/test_jobs.py index 89f92f5..47451bd 100644 --- a/tests/test_jobs.py +++ b/tests/test_jobs.py @@ -1,5 +1,5 @@ # import pytest -from seeker.job import models +# from seeker.job import models def test_django(): diff --git a/tox.ini b/tox.ini index fd6e39e..400fea6 100644 --- a/tox.ini +++ b/tox.ini @@ -4,14 +4,28 @@ # and then run "tox" from this directory. [tox] -envlist = - py3 - flake8 +envlist = py36,flake8 + +[testenv] +commands = py.test -v +deps = -r{toxinidir}/requirements.txt +passenv = + TRAVIS + TRAVIS_BRANCH + TRAVIS_JOB_ID + +[testenv:flake8] +commands = flake8 . +deps = flake8>=3.5.0 + +[travis] +python = + 3.6: py36, flake8 [pytest] -DJANGO_SETTINGS_MODULE = seeker.seeker.settings -# -- recommended but optional: -python_files = tests.py test_*.py *_tests.py +addopts = --ignore=setup.py +python_files = *.py +python_functions = test_ [flake8] # D100: Missing docstring in public module @@ -27,14 +41,4 @@ python_files = tests.py test_*.py *_tests.py # N805: First argument of a method should be named 'self' # N806: Variable in function should be lowercase ignore = D100,D101,D102,D103,D105,D200,D202,D400,D401,E501,N805,N806 - -[testenv:py3] -basepython = python3.6 -deps = -r requirements.txt -commands = pytest - - -[testenv:flake8] -basepython=python3.6 -deps=flake8>=3.5.0 -commands=flake8 +exclude = .git, .tox, build, dist From 795555419a924b02a2cde07bb056ce5fa234d416 Mon Sep 17 00:00:00 2001 From: Nathan Workman Date: Fri, 6 Apr 2018 15:01:14 -0400 Subject: [PATCH 12/15] tox config example test --- seeker/manage.py | 2 +- tests/conftest.py | 2 ++ tests/test_jobs.py | 11 ++++++----- tests/test_settings.py | 2 +- tox.ini | 12 +++++------- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/seeker/manage.py b/seeker/manage.py index 5d63641..d6f27d2 100755 --- a/seeker/manage.py +++ b/seeker/manage.py @@ -11,5 +11,5 @@ "Couldn't import Django. Are you sure it's installed and " "available on your PYTHONPATH environment variable? Did you " "forget to activate a virtual environment?" - ) from exc + ) execute_from_command_line(sys.argv) diff --git a/tests/conftest.py b/tests/conftest.py index e69de29..b08124a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -0,0 +1,2 @@ +# import django +# django.setup() diff --git a/tests/test_jobs.py b/tests/test_jobs.py index 47451bd..9db1f55 100644 --- a/tests/test_jobs.py +++ b/tests/test_jobs.py @@ -2,8 +2,9 @@ # from seeker.job import models -def test_django(): - # from base.settings import settings as base_settings - from django.conf import settings as django_settings - print(django_settings.xxx) - assert 3 == 5 +def func(x): + return x + 1 + + +def test_answer(): + assert func(3) == 4 diff --git a/tests/test_settings.py b/tests/test_settings.py index 6794987..e7fb456 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -1,6 +1,6 @@ import os -os.environ['DJANGO_SETTINGS_MODULE'] = 'seeker.settings' +os.environ['DJANGO_SETTINGS_MODULE'] = 'seeker.seeker.settings' DATABASES = { 'default': { diff --git a/tox.ini b/tox.ini index 400fea6..dca70af 100644 --- a/tox.ini +++ b/tox.ini @@ -9,13 +9,10 @@ envlist = py36,flake8 [testenv] commands = py.test -v deps = -r{toxinidir}/requirements.txt -passenv = - TRAVIS - TRAVIS_BRANCH - TRAVIS_JOB_ID + [testenv:flake8] -commands = flake8 . +commands = flake8 deps = flake8>=3.5.0 [travis] @@ -24,8 +21,9 @@ python = [pytest] addopts = --ignore=setup.py -python_files = *.py -python_functions = test_ +python_files = test_*.py +python_functions = test_* +norecursedirs = scraper [flake8] # D100: Missing docstring in public module From 333c3c9e71bc58285db198ee106e5fa36f9464ae Mon Sep 17 00:00:00 2001 From: Nathan Workman Date: Fri, 6 Apr 2018 15:19:17 -0400 Subject: [PATCH 13/15] Add FactoryBoy --- requirements.in | 2 ++ requirements.txt | 9 +++++++-- tox.ini | 1 - 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/requirements.in b/requirements.in index fc63526..11c60bb 100644 --- a/requirements.in +++ b/requirements.in @@ -14,3 +14,5 @@ pytest==3.5.0 pytest-django==3.1.2 flake8==3.5.0 tox==3.0.0 +pytest-factoryboy==2.0.1 + diff --git a/requirements.txt b/requirements.txt index 42475cf..5f781b3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,12 +22,15 @@ django-debug-toolbar==1.9.1 django-dotenv==1.4.2 django-widget-tweaks==1.4.1 django==2.0.3 +factory-boy==2.10.0 # via pytest-factoryboy +faker==0.8.12 # via factory-boy first==2.0.1 # via pip-tools flake8==3.5.0 gunicorn==19.7.1 hyperlink==18.0.0 # via twisted idna==2.6 # via cryptography, hyperlink, requests incremental==17.5.0 # via twisted +inflection==0.3.1 # via pytest-factoryboy kombu==4.1.0 # via celery lxml==4.2.1 # via parsel, scrapy mccabe==0.6.1 # via flake8 @@ -45,8 +48,9 @@ pydispatcher==2.0.5 # via scrapy pyflakes==1.6.0 # via flake8 pyopenssl==17.5.0 # via scrapy, service-identity pytest-django==3.1.2 -pytest-pythonpath==0.7.2 +pytest-factoryboy==2.0.1 pytest==3.5.0 +python-dateutil==2.7.2 # via faker pytz==2018.3 # via celery, django queuelib==1.5.0 # via scrapy redis==2.10.6 @@ -54,8 +58,9 @@ requests==2.18.4 # via django-anymail scrapy-djangoitem==1.1.1 scrapy==1.5.0 service-identity==17.0.0 # via scrapy -six==1.11.0 # via automat, cryptography, django-anymail, more-itertools, parsel, pip-tools, pyopenssl, pytest, scrapy, scrapy-djangoitem, tox, w3lib +six==1.11.0 # via automat, cryptography, django-anymail, faker, more-itertools, parsel, pip-tools, pyopenssl, pytest, python-dateutil, scrapy, scrapy-djangoitem, tox, w3lib sqlparse==0.2.4 # via django-debug-toolbar +text-unidecode==1.2 # via faker tox==3.0.0 twisted==17.9.0 # via scrapy urllib3==1.22 # via requests diff --git a/tox.ini b/tox.ini index dca70af..d151da0 100644 --- a/tox.ini +++ b/tox.ini @@ -23,7 +23,6 @@ python = addopts = --ignore=setup.py python_files = test_*.py python_functions = test_* -norecursedirs = scraper [flake8] # D100: Missing docstring in public module From 73f07928adf39a9e83d98a97b73f78c5f8a06121 Mon Sep 17 00:00:00 2001 From: Nathan Workman Date: Fri, 6 Apr 2018 22:49:28 -0400 Subject: [PATCH 14/15] Remove __init__.py recommended by pytest docs fixes relative import issue --- .travis.yml | 1 + tests/__init__.py | 0 tests/factories.py | 38 +++++++++++++++++++++++--------------- tests/test_jobs.py | 24 ++++++++++++++++++------ 4 files changed, 42 insertions(+), 21 deletions(-) delete mode 100644 tests/__init__.py diff --git a/.travis.yml b/.travis.yml index 87af8ec..a42b3a5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ python: - "3.6" install: + - pip install setuptools --upgrade - pip install -r requirements.txt - pip install tox-travis diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/factories.py b/tests/factories.py index 98b4d2d..7774eea 100644 --- a/tests/factories.py +++ b/tests/factories.py @@ -1,19 +1,27 @@ -# import factory -# from seeker.job.models import Board, Job +import factory +from seeker.job.models import Board, Job +from seeker.company.models import Company -# class BoardFactory(factory.DjangoModelFactory): -# """ -# Define Board Factory -# """ -# class Meta: -# model = Board +class CompanyFactory(factory.DjangoModelFactory): + """Define Company Factory.""" + class Meta: + model = Company -# class JobFactory(factory.DjangoModelFactory): -# """ -# Define Job Factory -# """ -# class Meta: -# model = Job -# customer = factory.SubFactory(BoardFactory) + +class BoardFactory(factory.DjangoModelFactory): + """Define Board Factory""" + + class Meta: + model = Board + + +class JobFactory(factory.DjangoModelFactory): + """ Define Job Factory""" + + class Meta: + model = Job + + board = factory.SubFactory(BoardFactory) + company = factory.SubFactory(CompanyFactory) diff --git a/tests/test_jobs.py b/tests/test_jobs.py index 9db1f55..20729bc 100644 --- a/tests/test_jobs.py +++ b/tests/test_jobs.py @@ -1,10 +1,22 @@ -# import pytest -# from seeker.job import models +import pytest +from factories import BoardFactory, JobFactory, CompanyFactory -def func(x): - return x + 1 +@pytest.mark.django_db +def test_board_model(): + """ Test customer model """ + # create customer model instance + board = BoardFactory(title="Job Board Title") + assert board.title == "Job Board Title" -def test_answer(): - assert func(3) == 4 +# @pytest.mark.django_db +# def test_job_creation(): +# """ Test quote model """ +# # create customer and quote model instances +# customer = CustomerFactory(name="Test Customer Name") +# quote = QuoteFactory(customer=customer, price=100.00) + +# assert quote.customer == customer +# asset quote.customer.name == "Test Customer Name" +# assert quote.price == 100.00 From e4837c261cf584d4cedc2afcd7cb3c401a0b3434 Mon Sep 17 00:00:00 2001 From: Nathan Workman Date: Sat, 7 Apr 2018 01:35:39 -0400 Subject: [PATCH 15/15] arbitary test to validate python paths are set correctly --- .travis.yml | 2 +- tests/conftest.py | 2 -- tests/test_jobs.py | 15 ++++++++++----- tests/test_settings.py | 2 ++ tox.ini | 8 +++++--- 5 files changed, 18 insertions(+), 11 deletions(-) delete mode 100644 tests/conftest.py diff --git a/.travis.yml b/.travis.yml index a42b3a5..7d368fd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,8 @@ python: install: - pip install setuptools --upgrade - - pip install -r requirements.txt - pip install tox-travis + - pip install -r requirements.txt script: - tox diff --git a/tests/conftest.py b/tests/conftest.py deleted file mode 100644 index b08124a..0000000 --- a/tests/conftest.py +++ /dev/null @@ -1,2 +0,0 @@ -# import django -# django.setup() diff --git a/tests/test_jobs.py b/tests/test_jobs.py index 20729bc..3228d91 100644 --- a/tests/test_jobs.py +++ b/tests/test_jobs.py @@ -1,13 +1,18 @@ -import pytest -from factories import BoardFactory, JobFactory, CompanyFactory +import pytest # noqa +# from seeker.job.models import Board -@pytest.mark.django_db +# @pytest.fixture +# def board(): +# (board) = + + +# @pytest.mark.django_db def test_board_model(): """ Test customer model """ # create customer model instance - board = BoardFactory(title="Job Board Title") - assert board.title == "Job Board Title" + title = "Job Board Title" + assert title == "Job Board Title" # @pytest.mark.django_db diff --git a/tests/test_settings.py b/tests/test_settings.py index e7fb456..8928bd3 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -1,6 +1,8 @@ import os os.environ['DJANGO_SETTINGS_MODULE'] = 'seeker.seeker.settings' +# from seeker.seeker.settings import * # noqa + DATABASES = { 'default': { diff --git a/tox.ini b/tox.ini index d151da0..d8df6c3 100644 --- a/tox.ini +++ b/tox.ini @@ -6,10 +6,12 @@ [tox] envlist = py36,flake8 -[testenv] -commands = py.test -v +[testenv:py36] +testpaths = tests seeker deps = -r{toxinidir}/requirements.txt - +commands = pytest {posargs} +setenv = + PYTHONPATH = {toxinidir} [testenv:flake8] commands = flake8