|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +""" |
| 3 | +Test pip_helpers. |
| 4 | +""" |
| 5 | + |
| 6 | +from __future__ import absolute_import, unicode_literals |
| 7 | + |
| 8 | +import unittest |
| 9 | + |
| 10 | +import django |
| 11 | +import pytest |
| 12 | + |
| 13 | +from ..pip_helpers import check_if_installed, get_installed_packages |
| 14 | + |
| 15 | +__title__ = 'django_elasticsearch_dsl_drf.tests.test_pip_helpers' |
| 16 | +__author__ = 'Artur Barseghyan <[email protected]>' |
| 17 | +__copyright__ = '2017-2018 Artur Barseghyan' |
| 18 | +__license__ = 'GPL 2.0/LGPL 2.1' |
| 19 | +__all__ = ( |
| 20 | + 'TestPipHelpers', |
| 21 | +) |
| 22 | + |
| 23 | + |
| 24 | +@pytest.mark.django_db |
| 25 | +class TestPipHelpers(unittest.TestCase): |
| 26 | + """Test pip_helpers.""" |
| 27 | + |
| 28 | + @classmethod |
| 29 | + def setUpClass(cls): |
| 30 | + cls.mapping = { |
| 31 | + 'country': { |
| 32 | + 'name': 'Netherlands', |
| 33 | + 'province': { |
| 34 | + 'name': 'North Holland', |
| 35 | + 'city': { |
| 36 | + 'name': 'Amsterdam', |
| 37 | + } |
| 38 | + } |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + def test_get_installed_packages(self): |
| 43 | + """Test `get_installed_packages`. |
| 44 | +
|
| 45 | + :return: |
| 46 | + """ |
| 47 | + installed_packages = get_installed_packages() |
| 48 | + self.assertIn('Django', installed_packages) |
| 49 | + self.assertIn('elasticsearch', installed_packages) |
| 50 | + self.assertIn('elasticsearch-dsl', installed_packages) |
| 51 | + |
| 52 | + def test_get_installed_packages_with_versions(self): |
| 53 | + """Test `get_installed_packages`. |
| 54 | +
|
| 55 | + :return: |
| 56 | + """ |
| 57 | + installed_packages = get_installed_packages(with_versions=True) |
| 58 | + django_version = '{}.{}.{}'.format(*django.VERSION[:3]) |
| 59 | + self.assertIn(('Django', django_version), installed_packages) |
| 60 | + |
| 61 | + def test_check_if_installed(self): |
| 62 | + """Test `check_if_installed`. |
| 63 | +
|
| 64 | + :return: |
| 65 | + """ |
| 66 | + self.assertTrue(check_if_installed('Django')) |
| 67 | + self.assertTrue(check_if_installed('elasticsearch')) |
| 68 | + self.assertTrue(check_if_installed('elasticsearch-dsl')) |
| 69 | + self.assertFalse(check_if_installed('django-fobi')) |
0 commit comments