Commit af9a61a3 authored by Neil Spink's avatar Neil Spink

get solution to pass all tests in python3

parent 93f354a4
Pipeline #41150321 failed with stages
in 2 minutes and 13 seconds
#!/bin/bash
pip install -r ../source/requirements.txt
pip install -r ../source/requirements_unit_test.txt
\ No newline at end of file
pip3 install -r ../source/requirements.txt
pip3 install -r ../source/requirements_unit_test.txt
\ No newline at end of file
......@@ -11,7 +11,7 @@
"FunctionName": "grab-price",
"Description": "Reading the price off the online shop.",
"Handler": "grab_price.lambda_handler",
"Runtime": "python2.7",
"Runtime": "python3.6",
"Role": "arn:aws:iam::385753165070:role/price-grabber-role"
}
},
......@@ -25,7 +25,7 @@
"FunctionName": "grab-invoke",
"Description": "Invokes the price grabber using list from S3 bucket.",
"Handler": "grab_invoke.lambda_handler",
"Runtime": "python2.7",
"Runtime": "python3.6",
"Role": "arn:aws:iam::385753165070:role/price-grabber-role"
}
}
......
import urllib2
from urllib.request import urlopen
import lxml.html
import re
......@@ -12,8 +12,7 @@ class Crawler(object):
@staticmethod
def get_web_page(url):
req = urllib2.Request(url)
response = urllib2.urlopen(req)
response = urlopen(url)
return response.read()
......@@ -35,4 +34,4 @@ class Crawler(object):
if len(result) != 1:
raise Exception("Couldn't parse the price from value :" + value)
return result[0]
\ No newline at end of file
return result[0]
......@@ -9,7 +9,7 @@ def lambda_handler(event, context):
result = job.grab(event)
print result
print(result)
return result
......
......@@ -20,7 +20,7 @@ def lambda_handler(event, context):
result = json.dumps(data)
print result
print(result)
return result
......
......@@ -18,7 +18,7 @@ class Invoker(object):
stream = obj.get()['Body'].read().decode('utf-8')
else:
stream = file('./deployment/website-monitor-list.yml', 'r')
stream = open('./deployment/website-monitor-list.yml', 'r')
yml_data = yaml.load(stream)
......
import unittest
import crawler as bot
from . crawler import Crawler
class TestCrawlerMethods(unittest.TestCase):
def test_get_shirt_html(self):
try:
with open('../test-data/shirt.html', 'r') as myfile: #dev server
result = myfile.read().replace('\n', '')
with open('../test-data/shirt.html', 'r') as my_file: # dev server
result = my_file.read().replace('\n', '')
except IOError:
with open('./test-data/shirt.html', 'r') as myfile: #ci server
result = myfile.read().replace('\n', '')
with open('./test-data/shirt.html', 'r') as my_file: # ci server
result = my_file.read().replace('\n', '')
self.assertIsNotNone(result)
return result
def test_parse_price(self):
web = bot.Crawler()
web = Crawler()
price = web.parse_price('CHF 90.00')
self.assertEqual(price, '90.00')
def test_parse_price_failing(self):
web = bot.Crawler()
web = Crawler()
with self.assertRaises(Exception):
web.parse_price('abcdef')
def test_parse_html_way1(self):
web = bot.Crawler()
web = Crawler()
page = self.test_get_shirt_html()
data = web.parse_html(page, "//div[@class='h-text h-color-black title-typo h-p-top-m']/text()")
self.assertEqual(data, u'CHF\xa0105.00')
def test_parse_html_way2(self):
web = bot.Crawler()
web = Crawler()
page = self.test_get_shirt_html()
data = web.parse_html(page, "//div[contains(@class, 'h-product-price')]/div/text()")
self.assertEqual(data, u'CHF\xa0105.00')
def test_parse_html_failing(self):
web = bot.Crawler()
web = Crawler()
page = self.test_get_shirt_html()
with self.assertRaises(Exception):
......
import unittest
from invoker import Invoker
from . invoker import Invoker
import json
from mock import patch
......
......@@ -6,10 +6,10 @@ class TestWebsiteMonitorList(unittest.TestCase):
def test_sites_information_valid(self, yml_file='../deployment/website-monitor-list.yml'):
try:
stream = file(yml_file, 'r') # dev server
stream = open(yml_file, 'r') # dev server
except IOError:
stream = file('./deployment/website-monitor-list.yml', 'r') # ci server
stream = open('./deployment/website-monitor-list.yml', 'r') # ci server
ymldata = yaml.load(stream)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment