Port to Python 3, use pipenv, add defaults to get_env_variable
This commit is contained in:
		
							parent
							
								
									321edba5f7
								
							
						
					
					
						commit
						8ba50c4fef
					
				
					 13 changed files with 130 additions and 31 deletions
				
			
		
							
								
								
									
										13
									
								
								Pipfile
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								Pipfile
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,13 @@ | ||||||
|  | [[source]] | ||||||
|  | url = "https://pypi.org/simple" | ||||||
|  | verify_ssl = true | ||||||
|  | name = "pypi" | ||||||
|  | 
 | ||||||
|  | [packages] | ||||||
|  | django = "*" | ||||||
|  | 
 | ||||||
|  | [dev-packages] | ||||||
|  | coverage = "*" | ||||||
|  | 
 | ||||||
|  | [requires] | ||||||
|  | python_version = "3.6" | ||||||
							
								
								
									
										74
									
								
								Pipfile.lock
									
										
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								Pipfile.lock
									
										
									
										generated
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,74 @@ | ||||||
|  | { | ||||||
|  |     "_meta": { | ||||||
|  |         "hash": { | ||||||
|  |             "sha256": "4f2c26123afdb8df49819165b8514b1bc786124c6079304035cf1171d5da9c22" | ||||||
|  |         }, | ||||||
|  |         "pipfile-spec": 6, | ||||||
|  |         "requires": { | ||||||
|  |             "python_version": "3.6" | ||||||
|  |         }, | ||||||
|  |         "sources": [ | ||||||
|  |             { | ||||||
|  |                 "name": "pypi", | ||||||
|  |                 "url": "https://pypi.org/simple", | ||||||
|  |                 "verify_ssl": true | ||||||
|  |             } | ||||||
|  |         ] | ||||||
|  |     }, | ||||||
|  |     "default": { | ||||||
|  |         "django": { | ||||||
|  |             "hashes": [ | ||||||
|  |                 "sha256:1ffab268ada3d5684c05ba7ce776eaeedef360712358d6a6b340ae9f16486916", | ||||||
|  |                 "sha256:dd46d87af4c1bf54f4c926c3cfa41dc2b5c15782f15e4329752ce65f5dad1c37" | ||||||
|  |             ], | ||||||
|  |             "index": "pypi", | ||||||
|  |             "version": "==2.1.3" | ||||||
|  |         }, | ||||||
|  |         "pytz": { | ||||||
|  |             "hashes": [ | ||||||
|  |                 "sha256:31cb35c89bd7d333cd32c5f278fca91b523b0834369e757f4c5641ea252236ca", | ||||||
|  |                 "sha256:8e0f8568c118d3077b46be7d654cc8167fa916092e28320cde048e54bfc9f1e6" | ||||||
|  |             ], | ||||||
|  |             "version": "==2018.7" | ||||||
|  |         } | ||||||
|  |     }, | ||||||
|  |     "develop": { | ||||||
|  |         "coverage": { | ||||||
|  |             "hashes": [ | ||||||
|  |                 "sha256:09e47c529ff77bf042ecfe858fb55c3e3eb97aac2c87f0349ab5a7efd6b3939f", | ||||||
|  |                 "sha256:0a1f9b0eb3aa15c990c328535655847b3420231af299386cfe5efc98f9c250fe", | ||||||
|  |                 "sha256:0cc941b37b8c2ececfed341444a456912e740ecf515d560de58b9a76562d966d", | ||||||
|  |                 "sha256:10e8af18d1315de936d67775d3a814cc81d0747a1a0312d84e27ae5610e313b0", | ||||||
|  |                 "sha256:1b4276550b86caa60606bd3572b52769860a81a70754a54acc8ba789ce74d607", | ||||||
|  |                 "sha256:1e8a2627c48266c7b813975335cfdea58c706fe36f607c97d9392e61502dc79d", | ||||||
|  |                 "sha256:2b224052bfd801beb7478b03e8a66f3f25ea56ea488922e98903914ac9ac930b", | ||||||
|  |                 "sha256:447c450a093766744ab53bf1e7063ec82866f27bcb4f4c907da25ad293bba7e3", | ||||||
|  |                 "sha256:46101fc20c6f6568561cdd15a54018bb42980954b79aa46da8ae6f008066a30e", | ||||||
|  |                 "sha256:4710dc676bb4b779c4361b54eb308bc84d64a2fa3d78e5f7228921eccce5d815", | ||||||
|  |                 "sha256:510986f9a280cd05189b42eee2b69fecdf5bf9651d4cd315ea21d24a964a3c36", | ||||||
|  |                 "sha256:5535dda5739257effef56e49a1c51c71f1d37a6e5607bb25a5eee507c59580d1", | ||||||
|  |                 "sha256:5a7524042014642b39b1fcae85fb37556c200e64ec90824ae9ecf7b667ccfc14", | ||||||
|  |                 "sha256:5f55028169ef85e1fa8e4b8b1b91c0b3b0fa3297c4fb22990d46ff01d22c2d6c", | ||||||
|  |                 "sha256:6694d5573e7790a0e8d3d177d7a416ca5f5c150742ee703f3c18df76260de794", | ||||||
|  |                 "sha256:6831e1ac20ac52634da606b658b0b2712d26984999c9d93f0c6e59fe62ca741b", | ||||||
|  |                 "sha256:77f0d9fa5e10d03aa4528436e33423bfa3718b86c646615f04616294c935f840", | ||||||
|  |                 "sha256:828ad813c7cdc2e71dcf141912c685bfe4b548c0e6d9540db6418b807c345ddd", | ||||||
|  |                 "sha256:85a06c61598b14b015d4df233d249cd5abfa61084ef5b9f64a48e997fd829a82", | ||||||
|  |                 "sha256:8cb4febad0f0b26c6f62e1628f2053954ad2c555d67660f28dfb1b0496711952", | ||||||
|  |                 "sha256:a5c58664b23b248b16b96253880b2868fb34358911400a7ba39d7f6399935389", | ||||||
|  |                 "sha256:aaa0f296e503cda4bc07566f592cd7a28779d433f3a23c48082af425d6d5a78f", | ||||||
|  |                 "sha256:ab235d9fe64833f12d1334d29b558aacedfbca2356dfb9691f2d0d38a8a7bfb4", | ||||||
|  |                 "sha256:b3b0c8f660fae65eac74fbf003f3103769b90012ae7a460863010539bb7a80da", | ||||||
|  |                 "sha256:bab8e6d510d2ea0f1d14f12642e3f35cefa47a9b2e4c7cea1852b52bc9c49647", | ||||||
|  |                 "sha256:c45297bbdbc8bb79b02cf41417d63352b70bcb76f1bbb1ee7d47b3e89e42f95d", | ||||||
|  |                 "sha256:d19bca47c8a01b92640c614a9147b081a1974f69168ecd494687c827109e8f42", | ||||||
|  |                 "sha256:d64b4340a0c488a9e79b66ec9f9d77d02b99b772c8b8afd46c1294c1d39ca478", | ||||||
|  |                 "sha256:da969da069a82bbb5300b59161d8d7c8d423bc4ccd3b410a9b4d8932aeefc14b", | ||||||
|  |                 "sha256:ed02c7539705696ecb7dc9d476d861f3904a8d2b7e894bd418994920935d36bb", | ||||||
|  |                 "sha256:ee5b8abc35b549012e03a7b1e86c09491457dba6c94112a2482b18589cc2bdb9" | ||||||
|  |             ], | ||||||
|  |             "index": "pypi", | ||||||
|  |             "version": "==4.5.2" | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										15
									
								
								README.rst
									
										
									
									
									
								
							
							
						
						
									
										15
									
								
								README.rst
									
										
									
									
									
								
							|  | @ -1,5 +1,20 @@ | ||||||
|  | ========= | ||||||
| gvacommon | gvacommon | ||||||
| ========= | ========= | ||||||
| 
 | 
 | ||||||
| This module contains code that is intended to be shared between gnuviechadmin | This module contains code that is intended to be shared between gnuviechadmin | ||||||
| components. | components. | ||||||
|  | 
 | ||||||
|  | Install dependencies | ||||||
|  | ==================== | ||||||
|  | 
 | ||||||
|  | .. code-block:: | ||||||
|  | 
 | ||||||
|  |    pipenv install --dev | ||||||
|  | 
 | ||||||
|  | Run tests | ||||||
|  | ========= | ||||||
|  | 
 | ||||||
|  | .. code-block:: | ||||||
|  | 
 | ||||||
|  |    pipenv run coverage run --branch setup.py test | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| # | # | ||||||
| # gvacommon - common parts of gnuviechadmin | # gvacommon - common parts of gnuviechadmin | ||||||
| # Copyright (C) 2015-2016  Jan Dittberner | # Copyright (C) 2015-2018  Jan Dittberner | ||||||
| # | # | ||||||
| # This program is free software: you can redistribute it and/or modify | # This program is free software: you can redistribute it and/or modify | ||||||
| # it under the terms of the GNU Affero General Public License as published by | # it under the terms of the GNU Affero General Public License as published by | ||||||
|  | @ -15,4 +15,4 @@ | ||||||
| # You should have received a copy of the GNU Affero General Public License | # You should have received a copy of the GNU Affero General Public License | ||||||
| # along with this program.  If not, see <http://www.gnu.org/licenses/>. | # along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||||
| # | # | ||||||
| __version__ = '0.3.1' | __version__ = '0.4.0' | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| # | # | ||||||
| # gvacommon - common parts of gnuviechadmin | # gvacommon - common parts of gnuviechadmin | ||||||
| # Copyright (C) 2016  Jan Dittberner | # Copyright (C) 2016-2018  Jan Dittberner | ||||||
| # | # | ||||||
| # This program is free software: you can redistribute it and/or modify | # This program is free software: you can redistribute it and/or modify | ||||||
| # it under the terms of the GNU Affero General Public License as published by | # it under the terms of the GNU Affero General Public License as published by | ||||||
|  | @ -20,7 +20,7 @@ from django.core.exceptions import ImproperlyConfigured | ||||||
| from os import environ | from os import environ | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def get_env_variable(var_name): | def get_env_variable(var_name, type=str, default=None): | ||||||
|     """ |     """ | ||||||
|     Get a setting from an environment variable. |     Get a setting from an environment variable. | ||||||
| 
 | 
 | ||||||
|  | @ -30,7 +30,9 @@ def get_env_variable(var_name): | ||||||
|     :rtype: str |     :rtype: str | ||||||
|     """ |     """ | ||||||
|     try: |     try: | ||||||
|         return environ[var_name] |         return type(environ[var_name]) | ||||||
|     except KeyError: |     except KeyError: | ||||||
|  |         if default is not None: | ||||||
|  |             return default | ||||||
|         error_msg = "Set the %s environment variable" % var_name |         error_msg = "Set the %s environment variable" % var_name | ||||||
|         raise ImproperlyConfigured(error_msg) |         raise ImproperlyConfigured(error_msg) | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| # | # | ||||||
| # gvacommon - common parts of gnuviechadmin | # gvacommon - common parts of gnuviechadmin | ||||||
| # Copyright (C) 2014-2016  Jan Dittberner | # Copyright (C) 2014-2018  Jan Dittberner | ||||||
| # | # | ||||||
| # This program is free software: you can redistribute it and/or modify | # This program is free software: you can redistribute it and/or modify | ||||||
| # it under the terms of the GNU Affero General Public License as published by | # it under the terms of the GNU Affero General Public License as published by | ||||||
|  | @ -19,8 +19,6 @@ | ||||||
| Tests for gvacommon celery router code. | Tests for gvacommon celery router code. | ||||||
| 
 | 
 | ||||||
| """ | """ | ||||||
| from __future__ import absolute_import, unicode_literals |  | ||||||
| 
 |  | ||||||
| import unittest | import unittest | ||||||
| 
 | 
 | ||||||
| from gvacommon.celeryrouters import GvaRouter | from gvacommon.celeryrouters import GvaRouter | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| # -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||||||
| # | # | ||||||
| # gvacommon - common parts of gnuviechadmin | # gvacommon - common parts of gnuviechadmin | ||||||
| # Copyright (C) 2016  Jan Dittberner | # Copyright (C) 2016-2018  Jan Dittberner | ||||||
| # | # | ||||||
| # This program is free software: you can redistribute it and/or modify | # This program is free software: you can redistribute it and/or modify | ||||||
| # it under the terms of the GNU Affero General Public License as published by | # it under the terms of the GNU Affero General Public License as published by | ||||||
|  | @ -38,3 +38,15 @@ class GetEnvVariableTest(TestCase): | ||||||
|             get_env_variable('missingvariable') |             get_env_variable('missingvariable') | ||||||
|         self.assertEqual( |         self.assertEqual( | ||||||
|             str(e.exception), 'Set the missingvariable environment variable') |             str(e.exception), 'Set the missingvariable environment variable') | ||||||
|  | 
 | ||||||
|  |     def test_typed_variable(self): | ||||||
|  |         os.environ['testvariable'] = '42' | ||||||
|  |         self.assertEqual(get_env_variable('testvariable'), '42') | ||||||
|  |         self.assertEqual(get_env_variable('testvariable', int), 42) | ||||||
|  |         self.assertIsInstance(get_env_variable('testvariable', int), int) | ||||||
|  | 
 | ||||||
|  |     def test_get_default_for_missing_variable(self): | ||||||
|  |         if 'missingvariable' in os.environ: | ||||||
|  |             del os.environ['missingvariable'] | ||||||
|  |         self.assertEqual(get_env_variable( | ||||||
|  |             'missingvariable', default='test'), 'test') | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| # | # | ||||||
| # gvacommon - common parts of gnuviechadmin | # gvacommon - common parts of gnuviechadmin | ||||||
| # Copyright (C) 2014-2016  Jan Dittberner | # Copyright (C) 2014-2018  Jan Dittberner | ||||||
| # | # | ||||||
| # This program is free software: you can redistribute it and/or modify | # This program is free software: you can redistribute it and/or modify | ||||||
| # it under the terms of the GNU Affero General Public License as published by | # it under the terms of the GNU Affero General Public License as published by | ||||||
|  | @ -19,23 +19,16 @@ | ||||||
| Tests for gvacommon code. | Tests for gvacommon code. | ||||||
| 
 | 
 | ||||||
| """ | """ | ||||||
| from __future__ import absolute_import, unicode_literals |  | ||||||
| 
 |  | ||||||
| import unittest | import unittest | ||||||
| 
 | from unittest.mock import MagicMock | ||||||
| try: |  | ||||||
|     from unittest.Mock import MagicMock |  | ||||||
| except ImportError: |  | ||||||
|     from mock import MagicMock |  | ||||||
| 
 | 
 | ||||||
| import django | import django | ||||||
|  | from django.conf import settings | ||||||
|  | from django.contrib.auth import get_user_model | ||||||
| from django.db import connection | from django.db import connection | ||||||
| from django.http import HttpResponseForbidden | from django.http import HttpResponseForbidden | ||||||
| from django.conf import settings |  | ||||||
| from django.views.generic import View | from django.views.generic import View | ||||||
| 
 | 
 | ||||||
| from django.contrib.auth import get_user_model |  | ||||||
| 
 |  | ||||||
| if not settings.configured: | if not settings.configured: | ||||||
|     settings.configure( |     settings.configure( | ||||||
|         DEBUG=True, |         DEBUG=True, | ||||||
|  |  | ||||||
|  | @ -35,8 +35,8 @@ class StaffOrSelfLoginRequiredMixin(LoginRequiredMixin): | ||||||
| 
 | 
 | ||||||
|     def dispatch(self, request, *args, **kwargs): |     def dispatch(self, request, *args, **kwargs): | ||||||
|         if ( |         if ( | ||||||
|                     request.user.is_staff or |                 request.user.is_staff or | ||||||
|                         request.user == self.get_customer_object() |                 request.user == self.get_customer_object() | ||||||
|         ): |         ): | ||||||
|             return super(StaffOrSelfLoginRequiredMixin, self).dispatch( |             return super(StaffOrSelfLoginRequiredMixin, self).dispatch( | ||||||
|                 request, *args, **kwargs |                 request, *args, **kwargs | ||||||
|  |  | ||||||
|  | @ -1,3 +0,0 @@ | ||||||
| # This file is here because many Platforms as a Service look for |  | ||||||
| #	requirements.txt in the root directory of a project. |  | ||||||
| -r requirements/base.txt |  | ||||||
|  | @ -1 +0,0 @@ | ||||||
| Django>=1.9.2,<2 |  | ||||||
|  | @ -1,4 +0,0 @@ | ||||||
| # Test dependencies go here. |  | ||||||
| -r base.txt |  | ||||||
| coverage==4.0.3 |  | ||||||
| mock==1.3.0 |  | ||||||
							
								
								
									
										2
									
								
								setup.py
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								setup.py
									
										
									
									
									
								
							|  | @ -1,6 +1,6 @@ | ||||||
| # | # | ||||||
| # gvacommon - common parts of gnuviechadmin | # gvacommon - common parts of gnuviechadmin | ||||||
| # Copyright (C) 2016  Jan Dittberner | # Copyright (C) 2016-2018  Jan Dittberner | ||||||
| # | # | ||||||
| # This program is free software: you can redistribute it and/or modify | # This program is free software: you can redistribute it and/or modify | ||||||
| # it under the terms of the GNU Affero General Public License as published by | # it under the terms of the GNU Affero General Public License as published by | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue