Skip to content

Commit

Permalink
RANGER-2927: fix python unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mneethiraj committed Aug 18, 2020
1 parent b937ab4 commit 1066351
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 93 deletions.
1 change: 0 additions & 1 deletion intg/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/target/
/venv/
70 changes: 8 additions & 62 deletions intg/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,80 +53,26 @@
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.6.1</version>
<configuration>
<filesets>
<fileset>
<directory>venv</directory>
</fileset>
</filesets>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${maven.exec.plugin.version}</version>
<executions>
<execution>
<configuration>
<skip>${skipTests}</skip>
<executable>python3</executable>
<arguments>
<argument>-m</argument>
<argument>venv</argument>
<argument>venv</argument>
</arguments>
</configuration>
<id>create-venv</id>
<phase>validate</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
<execution>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<skip>${skipTests}</skip>
<executable>bash</executable>
<commandlineArgs>scripts/build.sh</commandlineArgs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>initialize</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>venv/pylib</outputDirectory>
<resources>
<resource>
<directory>src/main/python</directory>
<includes>
<include>**/*.py</include>
</includes>
</resource>
<resource>
<directory>src/test/python</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<environmentVariables>
<PYTHONPATH>${project.basedir}/src/main/python</PYTHONPATH>
</environmentVariables>
<executable>python3</executable>
<arguments>
<argument>-B</argument>
<argument>src/test/python/test_ranger_client.py</argument>
</arguments>
</configuration>
</execution>
</executions>
Expand Down
23 changes: 0 additions & 23 deletions intg/scripts/build.sh

This file was deleted.

14 changes: 7 additions & 7 deletions intg/src/test/python/test_ranger_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import unittest
from unittest.mock import patch
from ranger.model.ranger_service import RangerService
from ranger.client.ranger_client import API, HttpMethod, HTTPStatus, RangerClient
from apache_ranger.model.ranger_service import RangerService
from apache_ranger.client.ranger_client import API, HttpMethod, HTTPStatus, RangerClient


class MockResponse:
Expand All @@ -41,15 +41,15 @@ class TestRangerClient(unittest.TestCase):
USERNAME = "user"
PASSWORD = "password"

@patch('ranger.client.ranger_client.Session')
@patch('apache_ranger.client.ranger_client.Session')
def test_get_service_unavailable(self, mock_session):
mock_session.return_value.get.return_value = MockResponse(HTTPStatus.SERVICE_UNAVAILABLE)
result = RangerClient(TestRangerClient.URL, TestRangerClient.USERNAME, TestRangerClient.PASSWORD).find_services({})

self.assertTrue(result is None)


@patch('ranger.client.ranger_client.Session')
@patch('apache_ranger.client.ranger_client.Session')
def test_get_success(self, mock_session):
response = RangerService()
mock_session.return_value.get.return_value = MockResponse(HTTPStatus.OK, response=response, content='Success')
Expand All @@ -58,8 +58,8 @@ def test_get_success(self, mock_session):
self.assertTrue(response.__repr__() in result)


@patch('ranger.client.ranger_client.Session')
@patch('ranger.client.ranger_client.Response')
@patch('apache_ranger.client.ranger_client.Session')
@patch('apache_ranger.client.ranger_client.Response')
def test_get_unexpected_status_code(self, mock_response, mock_session):
content = 'Internal Server Error'
mock_response.text = content
Expand All @@ -73,7 +73,7 @@ def test_get_unexpected_status_code(self, mock_response, mock_session):
self.assertTrue(content in repr(e))


@patch('ranger.client.ranger_client.RangerClient.FIND_SERVICES')
@patch('apache_ranger.client.ranger_client.RangerClient.FIND_SERVICES')
def test_unexpected_http_method(self, mock_api):
mock_api.method.return_value = "PATCH"

Expand Down

0 comments on commit 1066351

Please sign in to comment.