Skip to content

Commit

Permalink
Merge pull request #15 from uw-it-aca/qa
Browse files Browse the repository at this point in the history
Qa
  • Loading branch information
abztrakt committed Mar 1, 2016
2 parents 08b8ddc + 7280c6a commit 34c48e4
Show file tree
Hide file tree
Showing 157 changed files with 853 additions and 516 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# compiled files, swap files, system files, etc.
*.egg-info/
*.pyc
*.swp
.DS_Store
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-e .
2 changes: 1 addition & 1 deletion requirements/ldap-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-r base-requirements.txt
# on ubuntu, python-ldap requires the libldap2-dev, libssl-dev, and libsasl2-dev packages
python-ldap
-r ../requirements.txt
2 changes: 1 addition & 1 deletion requirements/mysql-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
-r base-requirements.txt
mysql-python
-r ../requirements.txt
2 changes: 1 addition & 1 deletion requirements/oracle-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
-r base-requirements.txt
mysql-python
-r ../requirements.txt
9 changes: 0 additions & 9 deletions requirements/requirements.txt

This file was deleted.

11 changes: 10 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,14 @@
setup(name='SpaceScout-Server',
version='1.0',
description='REST Backend for SpaceScout',
install_requires=['Django>=1.4,<1.5','mock','oauth2','Pillow','pyproj','pytz','South','simplejson>=2.1','django-oauth-plus'],
install_requires=[
'Django>=1.4,<1.5',
'mock<=1.0.1',
'oauth2<=1.5.211',
'Pillow',
'pyproj',
'pytz',
'South',
'simplejson>=2.1',
'django-oauth-plus<=2.2.5'],
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,36 @@
from django.test import TestCase
from django.test.client import Client
from django.test.utils import override_settings
from django.utils.unittest import skipIf
from mock import patch
from spotseeker_server import models
import json
import time


# TODO: rather than skipping tests near midnight, mock datetime.now() to
# return a consistent time.
@override_settings(SPOTSEEKER_AUTH_MODULE='spotseeker_server.auth.all_ok')
@skipIf(datetime.now().hour + 3 > 23 or datetime.now().hour < 3, "Skip open_at tests due to the time of day")
class HoursRangeTest(TestCase):
""" Tests searches for spots that are open anywhere within a range of hours.
"""

def setUp(self):
self.now = datetime.now()
self.now = self.now - \
timedelta(seconds=self.now.second,
microseconds=self.now.microsecond)
""" Creates a spot that is open between 10:00:00 and
13:00:00 on Wednesday.
"""
self.now = datetime(16, 2, 3, 9, 0, 0)
spot_open = datetime.time(self.now + timedelta(hours=1))
spot_close = datetime.time(self.now + timedelta(hours=4))

self.spot1 = models.Spot.objects.create(name="Spot that opens at {0}:{1} and closes at {2}:{3}".format(
spot_open.hour, spot_open.minute, spot_close.hour, spot_close.minute))
self.spot1 = models.Spot.objects.create(
name="Spot that opens at {0}:{1} and closes at {2}:{3}".format(
spot_open.hour, spot_open.minute, spot_close.hour,
spot_close.minute))

day_lookup = ["su", "m", "t", "w", "th", "f", "sa"]
day_num = int(time.strftime("%w", time.localtime()))
self.today = day_lookup[day_num]
self.today = day_lookup[3]

models.SpotAvailableHours.objects.create(
spot=self.spot1, day=self.today, start_time=spot_open, end_time=spot_close)
spot=self.spot1, day=self.today, start_time=spot_open,
end_time=spot_close)

self.day_dict = {"su": "Sunday",
"m": "Monday",
Expand Down Expand Up @@ -77,7 +75,8 @@ def test_open_within_range(self):

client = Client()
response = client.get(
"/api/v1/spot", {'fuzzy_hours_start': start_query, 'fuzzy_hours_end': end_query})
"/api/v1/spot", {'fuzzy_hours_start': start_query,
'fuzzy_hours_end': end_query})
spots = json.loads(response.content)

self.assertEqual(response.status_code, 200)
Expand All @@ -102,7 +101,8 @@ def test_closes_within_range(self):

client = Client()
response = client.get(
"/api/v1/spot", {'fuzzy_hours_start': start_query, 'fuzzy_hours_end': end_query})
"/api/v1/spot", {'fuzzy_hours_start': start_query,
'fuzzy_hours_end': end_query})
spots = json.loads(response.content)

self.assertEqual(response.status_code, 200)
Expand All @@ -128,7 +128,8 @@ def test_open_and_close_span_range(self):

client = Client()
response = client.get(
"/api/v1/spot", {'fuzzy_hours_start': start_query, 'fuzzy_hours_end': end_query})
"/api/v1/spot", {'fuzzy_hours_start': start_query,
'fuzzy_hours_end': end_query})
spots = json.loads(response.content)

self.assertEqual(response.status_code, 200)
Expand All @@ -145,8 +146,9 @@ def test_open_after_range_but_end_in_range(self):
pass

def test_open_within_range_but_end_outside(self):
""" Tests search for a spot that opens inside of the requested range but
closes outside of the requested range the next day (it spans midnight.)
""" Tests search for a spot that opens inside of the
requested range but closes outside of the requested
range the next day (it spans midnight.)
This should return the spot.
"""
dummy_cache = cache.get_cache(
Expand All @@ -164,15 +166,16 @@ def test_open_within_range_but_end_outside(self):

client = Client()
response = client.get(
"/api/v1/spot", {'fuzzy_hours_start': start_query, 'fuzzy_hours_end': end_query})
"/api/v1/spot", {'fuzzy_hours_start': start_query,
'fuzzy_hours_end': end_query})
spots = json.loads(response.content)

self.assertEqual(response.status_code, 200)
self.assertTrue(self.spot1.json_data_structure() in spots)

def test_open_close_in_range(self):
""" Tests search for a spot that opens and closes within the requested
hours range.
""" Tests search for a spot that opens and closes within the
requested hours range.
This should return the spot.
"""
dummy_cache = cache.get_cache(
Expand All @@ -190,15 +193,16 @@ def test_open_close_in_range(self):

client = Client()
response = client.get(
"/api/v1/spot", {'fuzzy_hours_start': start_query, 'fuzzy_hours_end': end_query})
"/api/v1/spot", {'fuzzy_hours_start': start_query,
'fuzzy_hours_end': end_query})
spots = json.loads(response.content)

self.assertEqual(response.status_code, 200)
self.assertTrue(self.spot1.json_data_structure() in spots)

def test_start_within_range_and_end_within_range_next_day(self):
""" Tests search for a spot that opens within the requested range and
closes within the requested range the next day.
""" Tests search for a spot that opens within the requested range
and closes within the requested range the next day.
This should return the spot.
"""
dummy_cache = cache.get_cache(
Expand All @@ -207,8 +211,8 @@ def test_start_within_range_and_end_within_range_next_day(self):
pass

def test_start_end_before_range(self):
""" Tests search for a spot that opens and closes before the requested
range.
""" Tests search for a spot that opens and closes before the
requested range.
This should NOT return the spot.
"""
dummy_cache = cache.get_cache(
Expand All @@ -226,7 +230,8 @@ def test_start_end_before_range(self):

client = Client()
response = client.get(
"/api/v1/spot", {'fuzzy_hours_start': start_query, 'fuzzy_hours_end': end_query})
"/api/v1/spot", {'fuzzy_hours_start': start_query,
'fuzzy_hours_end': end_query})
spots = json.loads(response.content)

self.assertEqual(response.status_code, 200)
Expand All @@ -252,7 +257,8 @@ def test_start_end_after_range(self):

client = Client()
response = client.get(
"/api/v1/spot", {'fuzzy_hours_start': start_query, 'fuzzy_hours_end': end_query})
"/api/v1/spot", {'fuzzy_hours_start': start_query,
'fuzzy_hours_end': end_query})
spots = json.loads(response.content)

self.assertEqual(response.status_code, 200)
Expand Down Expand Up @@ -297,7 +303,8 @@ def test_invalid_start_only(self):
self.assertEqual(response.status_code, 400)

def test_closes_at_start(self):
""" Tests search for a spot that closes at exactly the time the search range begins.
""" Tests search for a spot that closes at exactly the time the
search range begins.
This should NOT return the spot.
"""
dummy_cache = cache.get_cache(
Expand All @@ -315,14 +322,16 @@ def test_closes_at_start(self):

client = Client()
response = client.get(
"/api/v1/spot", {'fuzzy_hours_start': start_query, 'fuzzy_hours_end': end_query})
"/api/v1/spot", {'fuzzy_hours_start': start_query,
'fuzzy_hours_end': end_query})
spots = json.loads(response.content)

self.assertEqual(response.status_code, 200)
self.assertFalse(self.spot1.json_data_structure() in spots)

def test_opens_at_end(self):
""" Tests search for a spot that opens at exactly the time the search range ends.
""" Tests search for a spot that opens at exactly the time
the search range ends.
This should NOT return the spot.
"""
dummy_cache = cache.get_cache(
Expand All @@ -340,7 +349,8 @@ def test_opens_at_end(self):

client = Client()
response = client.get(
"/api/v1/spot", {'fuzzy_hours_start': start_query, 'fuzzy_hours_end': end_query})
"/api/v1/spot", {'fuzzy_hours_start': start_query,
'fuzzy_hours_end': end_query})
spots = json.loads(response.content)

self.assertEqual(response.status_code, 200)
Expand Down
File renamed without changes.
File renamed without changes.
42 changes: 27 additions & 15 deletions test/hours/open_at.py → spotseeker_server/test/hours/open_at.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,49 @@
from django.test import TestCase
from django.test.utils import override_settings
from django.test.client import Client
from django.utils.unittest import skipIf
import simplejson as json
from datetime import datetime, timedelta
import time
from django.test.utils import override_settings
from mock import patch
from django.core import cache
from spotseeker_server import models
import mock


@override_settings(SPOTSEEKER_AUTH_MODULE='spotseeker_server.auth.all_ok')
class SpotHoursOpenAtTest(TestCase):
""" Tests search requests for spots that are open at a particular time.
"""

@skipIf(datetime.now().hour + 3 > 23 or datetime.now().hour < 3, "Skip open_at tests due to the time of day")
def test_open_at(self):
dummy_cache = cache.get_cache('django.core.cache.backends.dummy.DummyCache')
@mock.patch('spotseeker_server.views.search.SearchView.get_datetime')
def test_open_at(self, datetime_mock):
dummy_cache = cache.get_cache(
'django.core.cache.backends.dummy.DummyCache')
with patch.object(models, 'cache', dummy_cache):
# Create a spot that isn't open now but will be in an hour.
spot = models.Spot.objects.create(name="This spot is open later")
now = datetime.now()
#Setting now to be Wednesday 9:00:00
now = datetime(16, 2, 3, 9, 0, 0)
spot_open = datetime.time(now + timedelta(hours=1))
spot_close = datetime.time(now + timedelta(hours=3))

day_lookup = ["su", "m", "t", "w", "th", "f", "sa"]
day_num = int(time.strftime("%w", time.localtime()))
today = day_lookup[day_num]
today = day_lookup[3]

models.SpotAvailableHours.objects.create(spot=spot, day=today, start_time=spot_open, end_time=spot_close)
models.SpotAvailableHours.objects.create(spot=spot,
day=today,
start_time=spot_open,
end_time=spot_close)

# Mock the call to now() so that the time returned
# is always 9:00:00
datetime_mock.return_value = ('w',
datetime(16, 2, 3, 9, 0, 0).time())

# Verify the spot is closed now
c = Client()
response = c.get("/api/v1/spot", {'open_now': True})
client = Client()
response = client.get("/api/v1/spot", {'open_now': True})
spots = json.loads(response.content)

spot_returned = False
Expand All @@ -58,7 +67,8 @@ def test_open_at(self):
if s['id'] == spot.pk:
spot_returned = True

self.assertTrue(not spot_returned, "The spot that is open later is not in the spots open now")
self.assertTrue(not spot_returned,
"The spot that is open later is not in the spots open now")

# Test the spot that is open later
query_time = datetime.time(now + timedelta(hours=2))
Expand All @@ -73,7 +83,7 @@ def test_open_at(self):
query_day = day_dict[today]
query = "%s,%s" % (query_day, query_time)

response = c.get("/api/v1/spot", {'open_at': query})
response = client.get("/api/v1/spot", {'open_at': query})
spots = json.loads(response.content)

spot_returned = False
Expand All @@ -84,10 +94,11 @@ def test_open_at(self):

self.assertTrue(spot_returned, "Got the spot that is open later")

# Test that the spot is not returned if we search for open_at == spot_close
# Test that the spot is not returned if we search
# for open_at == spot_close
query = "%s,%s" % (query_day, spot_close)

response = c.get("/api/v1/spot", {'open_at': query})
response = client.get("/api/v1/spot", {'open_at': query})
spots = json.loads(response.content)

spot_returned = False
Expand All @@ -96,4 +107,5 @@ def test_open_at(self):
if s['id'] == spot.pk:
spot_returned = True

self.assertTrue(not spot_returned, "The spot that closes at search time is not returned.")
self.assertTrue(not spot_returned,
"The spot that closes at search time is not returned.")
Loading

0 comments on commit 34c48e4

Please sign in to comment.