Skip to content

Commit

Permalink
Adds test and removes LagoonVariable.add
Browse files Browse the repository at this point in the history
  • Loading branch information
bomoko committed Dec 19, 2023
1 parent b501723 commit 4fd1122
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 42 deletions.
4 changes: 0 additions & 4 deletions api/plugins/action/env_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,9 @@ def run(self, tmp=None, task_vars=None):
result['id'] = existing_var['id']
return result

# Delete before recreating.
# lagoonVariable.delete(existing_var['id'])

if state == 'absent':
return result

# result['data'] = lagoonVariable.add(type, type_id, name, value, scope)
result['data'] = lagoonVariable.addOrUpdateByName(lagoon_project_name, lagoon_environment_name, name, value, scope)
self._display.v("Variable add result: %s" % result['data'])

Expand Down
30 changes: 0 additions & 30 deletions api/plugins/module_utils/gqlVariable.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,36 +74,6 @@ def addOrUpdateByName(self, projectName:str, environmentName: str, name:str, val
)
return res['addOrUpdateEnvVariableByName']

def add(self, type: str, type_id: int, name: str, value: str, scope: str) -> dict:
res = self.client.execute_query(
"""
mutation addEnvVariable(
$type: EnvVariableType!
$type_id: Int!
$name: String!
$value: String!
$scope: EnvVariableScope!
) {
addEnvVariable(input: {
type: $type
typeId: $type_id
scope: $scope
name: $name
value: $value
}) {
id
}
}""",
{
"type": type,
"type_id": int(type_id),
"scope": scope,
"name": name,
"value": str(value),
}
)
return res['addEnvVariable']

def delete(self, id: int) -> bool:
res = self.client.execute_query(
"""
Expand Down
16 changes: 8 additions & 8 deletions api/tests/unit/plugins/module_utils/test_gql_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@

class GqlVariableTester(unittest.TestCase):

def test_add(self):
def test_variable_addOrUpdateByName(self):
client = GqlClient('foo', 'bar')
client.execute_query = MagicMock()

lagoonVariable = Variable(client)
lagoonVariable.add('PROJECT', 1, 'SOME_VAR', 'foo', 'RUNTIME')
lagoonVariable.addOrUpdateByName('projectname', "environmentname", 'SOME_VAR', 'foo', 'RUNTIME')
_, query_args = client.execute_query.call_args.args

assert isinstance(query_args['type'], str)
assert query_args['type'] == 'PROJECT'
assert isinstance(query_args['type_id'], int)
assert query_args['type_id'] == 1
assert isinstance(query_args['project'], str)
assert query_args['project'] == 'projectname'
assert isinstance(query_args['environment'], str)
assert query_args['environment'] == 'environmentname'
assert isinstance(query_args['scope'], str)
assert query_args['scope'] == 'RUNTIME'
assert isinstance(query_args['name'], str)
Expand All @@ -35,12 +35,12 @@ def test_add_value_cast_to_string(self):

lagoonVariable = Variable(client)

lagoonVariable.add('PROJECT', 1, 'SOME_VAR', True, 'RUNTIME')
lagoonVariable.addOrUpdateByName('projectname', "environmentname", 'SOME_VAR', True, 'RUNTIME')
_, query_args = client.execute_query.call_args.args
assert isinstance(query_args['value'], str)
assert query_args['value'] == 'True'

lagoonVariable.add('PROJECT', 1, 'SOME_VAR2', 50, 'RUNTIME')
lagoonVariable.addOrUpdateByName('projectname', "environmentname", 'SOME_VAR2', 50, 'RUNTIME')
_, query_args = client.execute_query.call_args.args
assert isinstance(query_args['value'], str)
assert query_args['value'] == '50'
Expand Down

0 comments on commit 4fd1122

Please sign in to comment.