Skip to content

Commit

Permalink
Problem: No test for cyverse#350 - Duplicate user_allocation_source
Browse files Browse the repository at this point in the history
… Events

Solution: Added behave scenario to ensure that we don't create duplicate
events when checking the TAS API multiple times.
  • Loading branch information
julianpistorius committed Apr 30, 2017
1 parent 713de40 commit 7be31e1
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
42 changes: 42 additions & 0 deletions jetstream/features/monitor_jetstream_allocation_sources.feature
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,47 @@ Feature: Monitor Jetstream Allocation Sources
| TG-TRA160003 | 87914.060 |


Scenario: Correct events, with no duplicates when checking twice
When we get all projects
Then we should have the following events
| entity_id | name | payload | timestamp |
When we fill user allocation sources from TAS
Then we should have the following user allocation sources
| atmosphere_username | allocation_source |
| user108 | TG-BIO150062 |
| user109 | TG-BIO150062 |
| user109 | TG-TRA160003 |
| user111 | TG-TRA160003 |
# TODO: `allocation_source_created_or_renewed` & `allocation_source_compute_allowed_changed` should have `entity_id`
And we should have the following events
| entity_id | name | payload | timestamp |
| | allocation_source_created_or_renewed | {"allocation_source_name": "TG-BIO150062", "start_date": "2016-01-01T06:00:00Z", "end_date": "2017-06-30T05:00:00Z", "compute_allowed": 1000000} | 2017-02-15 05:00:00+0000 |
| | allocation_source_compute_allowed_changed | {"allocation_source_name": "TG-BIO150062", "start_date": "2016-01-01T06:00:00Z", "end_date": "2017-06-30T05:00:00Z", "compute_allowed": 1000000} | 2017-02-15 05:00:00+0000 |
| user108 | user_allocation_source_created | {"allocation_source_name": "TG-BIO150062"} | 2017-02-15 05:00:00+0000 |
| user109 | user_allocation_source_created | {"allocation_source_name": "TG-BIO150062"} | 2017-02-15 05:00:00+0000 |
| | allocation_source_created_or_renewed | {"allocation_source_name": "TG-TRA160003", "start_date": "2017-01-22T06:00:00Z", "end_date": "2018-01-21T06:00:00Z", "compute_allowed": 600000} | 2017-02-15 05:00:00+0000 |
| | allocation_source_compute_allowed_changed | {"allocation_source_name": "TG-TRA160003", "start_date": "2017-01-22T06:00:00Z", "end_date": "2018-01-21T06:00:00Z", "compute_allowed": 600000} | 2017-02-15 05:00:00+0000 |
| user109 | user_allocation_source_created | {"allocation_source_name": "TG-TRA160003"} | 2017-02-15 05:00:00+0000 |
| user111 | user_allocation_source_created | {"allocation_source_name": "TG-TRA160003"} | 2017-02-15 05:00:00+0000 |
Given a current time of '2017-02-16T06:00:00Z'
When we get all projects
And we fill user allocation sources from TAS
Then we should have the following user allocation sources
| atmosphere_username | allocation_source |
| user108 | TG-BIO150062 |
| user109 | TG-BIO150062 |
| user109 | TG-TRA160003 |
| user111 | TG-TRA160003 |
And we should have the following events
| entity_id | name | payload | timestamp |
| | allocation_source_created_or_renewed | {"allocation_source_name": "TG-BIO150062", "start_date": "2016-01-01T06:00:00Z", "end_date": "2017-06-30T05:00:00Z", "compute_allowed": 1000000} | 2017-02-15 05:00:00+0000 |
| | allocation_source_compute_allowed_changed | {"allocation_source_name": "TG-BIO150062", "start_date": "2016-01-01T06:00:00Z", "end_date": "2017-06-30T05:00:00Z", "compute_allowed": 1000000} | 2017-02-15 05:00:00+0000 |
| user108 | user_allocation_source_created | {"allocation_source_name": "TG-BIO150062"} | 2017-02-15 05:00:00+0000 |
| user109 | user_allocation_source_created | {"allocation_source_name": "TG-BIO150062"} | 2017-02-15 05:00:00+0000 |
| | allocation_source_created_or_renewed | {"allocation_source_name": "TG-TRA160003", "start_date": "2017-01-22T06:00:00Z", "end_date": "2018-01-21T06:00:00Z", "compute_allowed": 600000} | 2017-02-15 05:00:00+0000 |
| | allocation_source_compute_allowed_changed | {"allocation_source_name": "TG-TRA160003", "start_date": "2017-01-22T06:00:00Z", "end_date": "2018-01-21T06:00:00Z", "compute_allowed": 600000} | 2017-02-15 05:00:00+0000 |
| user109 | user_allocation_source_created | {"allocation_source_name": "TG-TRA160003"} | 2017-02-15 05:00:00+0000 |
| user111 | user_allocation_source_created | {"allocation_source_name": "TG-TRA160003"} | 2017-02-15 05:00:00+0000 |

@skip
Scenario: Generate reports
23 changes: 22 additions & 1 deletion jetstream/features/steps/tas_api_steps.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import copy
import datetime
import json
from decimal import Decimal

import mock
Expand Down Expand Up @@ -39,6 +41,7 @@ def _get_user_projects(context, url):
data = {'status': 'success', 'message': None, 'result': user_projects}
return data


def _make_mock_tacc_api_get(context):
def _mock_tacc_api_get(*args, **kwargs):
url = args[0]
Expand Down Expand Up @@ -205,7 +208,7 @@ def should_have_allocation_source_snapshots(context):
context.test.assertDictEqual(expected_allocation_source_snapshots, allocation_source_snapshots)


@then(u'we should have the following user allocation sources')
@step(u'we should have the following user allocation sources')
def should_have_user_allocation_sources(context):
expected_user_allocation_sources = [(row.cells[0], row.cells[1] or None,) for row in context.table]
from core.models import UserAllocationSource
Expand All @@ -218,3 +221,21 @@ def should_have_user_allocation_sources(context):
'allocation_source__name'
)]
context.test.assertListEqual(expected_user_allocation_sources, user_allocation_sources)


@step(u'we should have the following events')
@step(u'we should have the following "{event_name}" events')
def should_have_following_events(context, event_name=None):
expected_events = [dict(zip(row.headings, row.cells)) for row in context.table]
for expected_event in expected_events:
expected_event['payload'] = json.loads(expected_event['payload'])
from core.models import EventTable
query = EventTable.objects.all().order_by('id')
if event_name is not None:
query = query.filter(name=event_name)
events = [event for event in query.values('entity_id', 'name', 'payload', 'timestamp')]
for event in events:
event['timestamp'] = event['timestamp'].replace(microsecond=0)
event['timestamp'] = datetime.datetime.strftime(event['timestamp'], '%Y-%m-%d %H:%M:%S%z')
context.test.maxDiff = None
context.test.assertListEqual(expected_events, events)

0 comments on commit 7be31e1

Please sign in to comment.