Skip to content
This repository has been archived by the owner on Sep 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #657 from cdosborn/fix-old-tests
Browse files Browse the repository at this point in the history
Re-include old tests
  • Loading branch information
cdosborn authored Sep 6, 2018
2 parents f8fe0f5 + 9baadef commit 90211ef
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 364 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
([#649](https://github.com/cyverse/atmosphere/pull/649))
- Fixed v2 volume detach throwing 500 serialization error
([#655](https://github.com/cyverse/atmosphere/pull/655))
- Reincluded/fixed broken tests
([#657](https://github.com/cyverse/atmosphere/pull/657))

### Added
- Added AccessTokens model, API view, and serializers to enable new feature on
Expand Down
4 changes: 1 addition & 3 deletions core/models/instance_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ def transaction(cls, status_name, activity, instance, size,
try:
with transaction.atomic():
if not last_history:
# Required to prevent race conditions.
last_history = instance.get_last_history()\
.select_for_update(nowait=True)
last_history = instance.get_last_history()
if not last_history:
raise ValueError(
"A previous history is required "
Expand Down
46 changes: 13 additions & 33 deletions core/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ def first_transaction(self):

def new_transaction(self):
return InstanceStatusHistory.transaction(
self.status_name, self.instance, self.size, self.start_date)
self.status_name, "dummy-activity", self.instance, self.size,
start_time=self.start_date)

def _init_sizes(self, provider):
size_params = [
Expand Down Expand Up @@ -178,35 +179,15 @@ def set_machine(self, machine):
def to_core_instance(self):
return Instance.objects.get_or_create(
name=self.name, provider_alias=self.provider_alias,
provider_machine=self.machine, ip_address='1.2.3.4',
source=self.machine.instance_source, ip_address='1.2.3.4',
created_by=self.user, created_by_identity=self.identity,
token='unique-test-token-%s' % self.name,
password='password',
shell=False, start_date=self.start_date)[0]

def _init_provider_machines(self):
# Mock a machine and its dependencies..
app = Application.objects.get_or_create(
name='Ubuntu',
description='', created_by=self.user,
created_by_identity=self.identity,
uuid='1234-ubuntu-mock-APP')[0]
ubuntu = ProviderMachine.objects.get_or_create(
application=app, provider=self.provider,
created_by=self.user, created_by_identity=self.identity,
identifier='1234-ubuntu-mock-machine',
version="1.0")[0]

app = Application.objects.get_or_create(
name='CentOS',
description='', created_by=self.user,
created_by_identity=self.identity,
uuid='1234-centos-mock-APP')[0]
centos = ProviderMachine.objects.get_or_create(
application=app, provider=self.provider,
created_by=self.user, created_by_identity=self.identity,
identifier='1234-centos-mock-machine',
version='1.0')[0]
ubuntu = _new_provider_machine("ubuntu", "1.0", self.identity)
centos = _new_provider_machine("centos", "1.0", self.identity)
self.AVAILABLE_MACHINES = {
"ubuntu": ubuntu,
"centos": centos,
Expand Down Expand Up @@ -251,21 +232,19 @@ def to_core_machine(self):

class CoreMachineRequestHelper(object):

def __init__(self, new_application_name, start_date,
new_machine_version='1.0', new_machine_forked=True,
def __init__(self, new_application_name, start_date, new_machine_forked=True,
instance=None, provider='openstack', username='mock_user'):
self.AVAILABLE_PROVIDERS = _new_providers()
self.set_provider(provider)
identity_member = _new_mock_identity_member(
self.identity_member = _new_mock_identity_member(
username, self.provider)
self.identity = identity_member.identity
self.identity = self.identity_member.identity
self.user = self.identity.created_by
self.forked = new_machine_forked
if not instance:
instance = _new_core_instance(
"Mock Instance", uuid4(), start_date, self.identity, None)
self.new_application_name = new_application_name
self.new_machine_version = new_machine_version
self.instance = instance
self.start_date = start_date

Expand All @@ -279,14 +258,15 @@ def set_provider(self, provider):
def to_core_machine_request(self):
provider_machine = self.instance.provider_machine

status, _ = StatusType.objects.get_or_create(name='pending')
return MachineRequest.objects.get_or_create(
instance=self.instance, status='pending',
created_by=self.user, membership=self.identity_member,
instance=self.instance, status=status,
parent_machine=provider_machine,
new_machine_provider=provider_machine.provider,
new_application_name=self.new_application_name,
new_machine_version=self.new_machine_version,
new_machine_owner=self.user, new_machine_visibility='public',
new_machine_forked=self.forked, start_date=self.start_date)[0]
new_machine_owner=self.user, new_application_visibility='public',
new_version_forked=self.forked, start_date=self.start_date)[0]


class CoreApplicationHelper(object):
Expand Down
184 changes: 0 additions & 184 deletions core/tests/machine_request.py

This file was deleted.

Empty file removed core/tests/models/__init__.py
Empty file.
4 changes: 2 additions & 2 deletions core/tests/application.py → core/tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def test_simple_access(self):
self.app.access_list.add(self.allow_test_email)
expected_result = [
u'cdosborn', u'cyversedemo1', u'cyversedemo2',
u'cyversedemo3', u'lenards', u'steve']
u'cyversedemo3', u'lenards', u'sgregory', u'steve']
self.assertAccessList(expected_result)
self.app.access_list.clear()

Expand All @@ -135,7 +135,7 @@ def test_allow_deny_logic(self):
self.app.access_list.add(self.deny_specific_test_email)
expected_result = [
u'cdosborn', u'cyversedemo1', u'cyversedemo2',
u'cyversedemo3', u'lenards']
u'cyversedemo3', u'lenards', u'steve']
self.assertAccessList(expected_result)
self.app.access_list.clear()

Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion core/tests/instance.py → core/tests/test_instance.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.core.urlresolvers import reverse
from django.test import TestCase
import uuid

import unittest

Expand Down Expand Up @@ -62,7 +63,7 @@ def setUp(self):
tzinfo=pytz.utc)
self.terminate_time = datetime(2015, 1, 8, tzinfo=pytz.utc)
self.instance_helper = CoreInstanceHelper(
"test_instance", "1234-1234-1234-1234", self.start_time)
"test_instance", uuid.uuid4(), self.start_time)

def test_growing_history(self):
"""
Expand Down
Loading

0 comments on commit 90211ef

Please sign in to comment.